Join us in Outworldz at www.outworldz.com:9000 or follow us:

Search dozens of selected web sites for OpenSim and LSL script

New! Script Meta-Search will search thousands of scripts here and at other sites for LSL or Opensim scripts.
Loading

Want to add a script or a project? Upload it and a half million people will see it and your name here this year.

Home   Show All
Category: Contributor: Creator
Presentations SL_Pie_Chart_Maker  

SL_Pie_Chart_Maker

There's nothing like a pie chart for displaying survey results. Set this up in three steps - Rez the base, get its email address, send it formatted results. Bang! A fine little 3D chart builds before your eyes.

The system uses three scripts:

* Pie Chart Maker = the controller - receives email and sends the subject line to Title maker. Then it rezzes segment objects, calculates segment shapes and sends settings to Pie Segment
* Title Maker = a label - simply displays the title of the incoming email.
* Pie Segment = the colored wedges - rezzed by Pie Chart Maker and changes cut shapes and colors.

Category: Presentations
By : Angrybeth Shortbread
Created: 2010-01-10 Edited: 2010-01-10
Worlds: Second Life

the Zip file

Download all files for SL_Pie_Chart_Maker
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. SL_Pie_Chart_Maker_1.lsl
1 //Pie Chart Maker
2 //by Angrybeth Shortbread, 2006
3 //Concept by Jeremy Kemp / www.simteach.com
4 //Distrubute Freely and adapt....
5
6 //This script works by creating a list of the value of each segment , based on the string provided by an email...
7 //The email needs to be in the format
8 //Subject - What the Title of the Pie Chart is
9 //Message - Percentage Value,Colour,Description
10 //the message body would look like - 45,red,Labour,30,blue,Conservative,25,yellow,Liberal
11
12 //Colour names can be customised in the piesegment script, if you want to add additional hues.
13
14 //It then rezzes a number of segment blocks.
15 //Each Segment block is given is own private chat channel via the start_param function of llRez
16 //Once all Segment blocks are in place
17 //They are inturn told the data nessecary to visualise the information.
18
19
20 integer numofsegments;
21
22 integer chatchannel = 300000; // The starting number of private chat channels that are added to incrementely
23
24 integer chatchannelrez; // and assigned to this
25
26 vector mypos;
27
28 float segmentheight;
29
30 list segments;
31
32 list segmentsize;
33
34 list segmentdesc;
35
36 list segmentcolour;
37
38 list backup; // this is a list that copies the data and truncates it for striding reasons
39
40
41 default
42 {
43
44 on_rez(integer param)
45 {
47 }
48
50 {
51
52 llSetTimerEvent(2.5); // A timer is needed so emails sent to the object are read.
53
54 mypos = llGetPos();
55
56 segmentheight = 0.3; // the gap between each segment - to give an exploded pie chart - make this zero - if you want it to be flat.
57
58
59 }
60
61 touch_start(integer param) // This only allows the owner to get the email address of the piechartmaker
62 {
63 key who = llDetectedKey(0);
64 if(who == llGetOwner() )
65 {
66 string myname = llGetKey();
67 llSay(0, (string)myname + "@lsl.secondlife.com");
68 }
69
70 // *** addition could be on touch - to send an email to the server outside Second life that is providing the data
71 }
72
73 timer()
74 {
75 llGetNextEmail("", ""); // Every 2.5 seconds - the object sees if there's been an email sent - if so then it triggers the email event
76 }
77
78 //This version uses email - but the following below could be used in a listen event instead...
79
80 email(string time, string address, string subj, string message, integer num_left) {
81 {
82 llOwnerSay("Recieving data...."); // - Tells the owner I've got data from an email
83
84 // llSay(0, message); - Debug to display the email message body recieved
85
86 segments = llParseString2List(message, [","], []); // takes the messagebody of the email and converts it into a list of strings.
87 llSleep(0.2); // probably not needed
88 segmentsize = llList2ListStrided(segments, 0, -1, 3); // this is making a new list - that only contains the percentage value
89
90 integer lengthy = llGetListLength(segments);
91 backup = llList2List(segments, 1, lengthy); // as lists are annoying to stride - this is making a backup - where it is removing the first bit from the list to make it easier to stride
92 segmentcolour = llList2ListStrided(backup, 0 ,-1, 3); // this is making a list - that only contains the colour information for the pie segment
93
94 lengthy = llGetListLength(backup);
95 backup = llList2List(backup, 1, lengthy); // and one more time
96 segmentdesc = llList2ListStrided(backup, 0 ,-1 ,3); // this is making a list - that only contain the description
97
98 // llSay(0, llDumpList2String(segmentsize, " + "));
99 // llSay(0, llDumpList2String(segmentdesc, " + ")); // a bunch of chat debugs to see if its sliced up the original email message properly
100 // llSay(0, llDumpList2String(segmentcolour, " + "));
101
102 llMessageLinked(LINK_SET, 0, subj, NULL_KEY); // this sends the subject line of the email to a linked prim so it can display it as the title of the pie chart.
103
104 state create; // its prepare all the lists it needs to create the chart
105
106
107 }
108 }
109
110 }
111
112 state create
113 {
115 {
116
117 llSay(0, "creating pie chart..."); // a public message to get attention.. ohhhhh!
118
119 llSay(400000, "delete"); // if there are already segments from a previous pie chart - this sends a command to delete them.
120
121 llSleep(1.0); // Just have a sleep - to make sure all the segments got the instruction to delete..
122
123 numofsegments = llGetListLength(segmentsize); // this works out how many pie segments to make
124
125 integer i;
126
127 for (i = 0; i < numofsegments; ++i) // the For loop - keeps rezzing piesegment (from the piemaker content's ) until the number needed is met
128 {
129
130 chatchannelrez = chatchannel + i; // each segment will have a unique private chat channel associated with it
131
132 llRezObject("piesegment",mypos + <0,0,segmentheight>, ZERO_VECTOR, ZERO_ROTATION, chatchannelrez); // this rezzes the piesegment - above the piemaker and sets the chatchannel as the new segements starting param.
133
134 segmentheight = segmentheight + 0.3; // to make the pie segments keep on going up ...
135
136 llSleep(0.2);
137
138
139 }
140
141 //Once the For loop is done - of to the next event
142
143 state piedata;
144
145 }
146
147 }
148
149 state piedata
150 {
151
153 {
154
155 float slicedend = 0.0;
156 float previoussliceend = 0.0;
157 string slicestart = "";
158 string sliceend = "";
159 string slicedesc = "";
160 string slicecolour;
161
162 // llSay(0, "now sending data to segments...");
163
164 numofsegments = llGetListLength(segmentsize);
165
166 // The first pie segment - needs to be handled outside the for loop ( well just to make life easier for myself )
167
168 llSay(chatchannel, "0" + "," + llList2String(segmentsize, 0) + "," + llList2String(segmentcolour, 0) + "," + llList2String(segmentdesc, 0) );
169
170 string first = (llList2String(segmentsize, 0));
171
172 previoussliceend = (float)(first); // this is important as it helps sort out the value of were the data for the next path cut begins
173
174 integer i;
175
176 for (i = 1; i < numofsegments; ++i) // another For Loop to cycle thru sending data to each segment in turn.
177 {
178
179 chatchannelrez = chatchannel + i;
180
181 slicestart = (llList2String(segmentsize, i - 1 ));
182 sliceend = (llList2String(segmentsize, i ));
183 slicedesc = (llList2String(segmentdesc, i ));
184 slicecolour = (llList2String(segmentcolour, i ));
185
186 float slicedstart = previoussliceend; // were the next part cut begins
187 slicedend = (float)(sliceend) + previoussliceend; // and ends
188
189
190
191 previoussliceend = slicedend; // then retain that info for the nexts segments part start
192
193 llSleep(0.2); // have a kip between each chat message
194
195 llSay(chatchannelrez, (string)(slicedstart) + "," +(string)(slicedend) + "," + (string)(slicecolour) + "," + (string)(slicedesc));
196
197 }
198
199 state default; // its done all the work so its back to the start again - to wait for a new email.
200 }
201
203 {
204 llSay(0, "Compiled Pie Chart"); // on state exit - just tell everyone that you've done the job...yay!!
205
206 }
207
208 }

Back to the Best Free Tools in Second Life and OpenSim.