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
Gardening Square Particle garden  

Square Particle garden

Drop one optional particle texture and this script into a prim.
Particles should start automatically. (Reset) the script if you insert a particle texture later on. Add one or more CONTROLLER TEMPLATES to any prims in the linked object to control when particles turn ON and OFF.

Category: Gardening
By : Optikal
Created: 2014-01-17 Edited: 2014-01-17
Worlds: Second Life

the Zip file

Download all files for Square Particle garden
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Square Particle Garden.lsl
1 // :LICENSE: Licensed as Creative Commons By Attribution and Non-Commercial. http://creativecommons.org/licenses/by-nc/3.0/
2
3 // Square Particle Garden v1.0 by Optikal
4 // Licensed as Creative Commons By Attribution and Non-Commercial.
5 // http://creativecommons.org/licenses/by-nc/3.0/
6 // Drop one optional particle texture and this script into a prim.
7 // Particles should start automatically. (Reset) the script if you insert a particle texture later on. Add one or more CONTROLLER TEMPLATES to any prims in the linked object to control when particles turn ON and OFF.
8
9 // Square Mode Parameters:
10 float row_space = 0.5;
11 float plant_space = 0.5; // used by circle and random too
12 float plant_offset = 0.0;
13 integer rows = 8;
14 integer plants = 8;
15
16 // Random Mode Parameters:
17 integer rand_plants = 30;
18 float rand_width = 15.0;
19 float rand_depth = 12.0;
20
21 float scale = 0.5;
22 integer Handle;
23 integer Channel = 1;
24 integer active = 1;
25
26 // 0 = square, 1 = random, 2 = circle
27 integer pattern = 0;
28
29 list plant_list = [];
30 list particle_parameters = [];
31 list target_parameters = [];
32
33 maak_part(float distance, float angle, string texture)
34 {
35 particle_parameters = [
36 // Texture Parameters:
37 PSYS_SRC_TEXTURE, texture,
38 PSYS_PART_START_SCALE,<scale ,scale, FALSE>,
39 PSYS_PART_END_SCALE, <scale ,scale, FALSE>,
40 PSYS_PART_START_COLOR, <1,1,1>,
41 PSYS_PART_END_COLOR, <1,1,1>,
44
45 // Production Parameters:
50
51 // Placement Parameters:
52 // 1=DROP, 2=EXPLODE, 4=ANGLE, 8=ANGLE_CONE,
54
55 // Placement Parameters (for any non-DROP pattern):
58 PSYS_SRC_BURST_RADIUS, distance,
59
60 // Placement Parameters (only for ANGLE & CONE patterns):
62 PSYS_SRC_ANGLE_END, angle,
63 // PSYS_SRC_OMEGA, <0,0,0>,
64 // After-Effect & Influence Parameters:
65 // PSYS_SRC_ACCEL, <0.0,0.0,0.01>,
66 // PSYS_SRC_TARGET_KEY, llGetLinkKey(llGetLinkNum() + 1),
67
68 // Texture Options:
74 // After-effect & Influence Options:
80 )];
81 llParticleSystem(particle_parameters);
82 }
83
84 // Calculate where the plants go
85 planten()
86 {
87 if(pattern==0) {planten_square();}
88 else if(pattern==1) {planten_list();}
89 }
90
91 planten_square()
92 {
93 // Will be set by script
94 integer plants_row = 0;
95 // Will be set by script
96 integer plants_row_odd = 0;
98 integer textcnt=0;
99 vector begin_pos;
100 vector thrower_pos;
101 integer rc; // row counter
102 integer pc; // plant counter
103 float rl=0.0; // row length
104 float fl=0.0; // field length
105 begin_pos=llGetPos();
106 thrower_pos=llGetPos();
107 plants_row=plants/2;
108
109 if(plants - plants_row - plants_row > 0) {plants_row_odd=1;}
110
111 if(rows > 1)
112 {
113 fl = rows*row_space-row_space;
114 begin_pos.x-=fl/2.0;
115 }
116
117 if(plants_row > 1) {rl=plants_row*plant_space-plant_space;}
118
119 // Even number of rows, take offset
120 if(!plants_row_odd){begin_pos.y+=plant_space/2.0;}
121
122 begin_pos.x+=plant_offset;
123
124 for(rc=0; rc< rows ; rc++)
125 {
126 float rx=begin_pos.x+rc*row_space;
127
128 for (pc=0; pc<plants_row+plants_row_odd;pc++)
129 {
130 float py=begin_pos.y+pc*plant_space;
131 float dst;
132 float ang;
133 float ro=rx-thrower_pos.x;
134 float po=py-thrower_pos.y;
135 dst = llSqrt(ro*ro+po*po);
136 ang = llAtan2(po,ro);
137 maak_part(dst,ang,llGetInventoryName(INVENTORY_TEXTURE,textcnt));
138 if(++textcnt >= number) textcnt=0;
139 llSleep(0.05);
140 }
141 }
143 }
144
145 planten_list()
146 {
147 // Will be set by script
148 integer planten = llGetListLength(plant_list);
149 vector thrower_pos;
150 vector begin_pos;
151 integer pc; // Plant counter
152 thrower_pos=llGetPos();
153 begin_pos=thrower_pos;
154 begin_pos.x+=plant_offset;
155
156 for (pc=0; pc< planten ; pc++)
157 {
158 vector pp;
159 pp=llList2Vector(plant_list,pc);
160 float px=begin_pos.x+pp.x;
161 float py=begin_pos.y+pp.y;
162 float dst;
163 float ang;
164 float ro=px-thrower_pos.x;
165 float po=py-thrower_pos.y;
166 dst = llSqrt(ro*ro+po*po);
167 ang = llAtan2(po,ro);
168 maak_part(dst,ang,llGetInventoryName(INVENTORY_TEXTURE,(integer)llFloor(pp.z)));
169 llSleep(0.05);
170 }
172 }
173
174 maak_list()
175 {
176 plant_list=[];
177 integer pc; // Plant counter
179 float hpd=plant_space/2.0;
180 float dpt=(rand_depth-plant_space)/2.0;
181
182 for (pc=0; pc<rand_plants;pc++)
183 {
184 integer fout=0;
185 vector pp;
186
187 do
188 {
189 fout = 0;
190 pp = <llFrand(rand_width)-(rand_width/2),llFrand(dpt)+hpd,llFrand(number)>;
191
192 // Check distance
193 integer len = llGetListLength(plant_list);
194
195 if(len > 0)
196 {
197 integer tel;
198
199 for (tel=0;!fout && tel < len ;tel++)
200 {
201 vector lp=llList2Vector(plant_list,tel);
202
203 if(llVecDist(lp,pp)<plant_space)
204 {
205 fout=1;
206 }
207 }
208 }
209 }
210 while(fout);
211 plant_list += [pp];
212 }
213 }
214
215 // Check if and which command is in str
216 string checkMatch(string str, list prefixes)
217 {
218 integer numElements = llGetListLength(prefixes);
219 integer i;
220 integer lastChar;
221 string curPrefix;
222 string curStr = llToLower(str);
223
224 for (i=0; i<numElements; i++ )
225 {
226 curPrefix = llList2String(prefixes, i);
227 lastChar = llStringLength( curPrefix );
228 lastChar -= 1;
229
230 if(llGetSubString(curStr, 0, lastChar) == curPrefix)
231 return curPrefix;
232 }
233 return "";
234 }
235
236 help()
237 {
238 llOwnerSay("command format /"+(string)Channel+" command value");
239 llOwnerSay("commands recognized :");
240 llOwnerSay("uit off stop : switch the particles off");
241 llOwnerSay("aan on start : switch the particles on");
242 llOwnerSay("regels rows : number of rows to plant");
243 llOwnerSay("plants planten : number of plants per row/random patern");
244 llOwnerSay("offset plaats : shift the rows away from the center");
245 llOwnerSay("plantspace : space between plants");
246 llOwnerSay("rowspace : space between rows");
247 llOwnerSay("show toon : make spreader visible");
248 llOwnerSay("hide verstop : hide the spreader");
249 llOwnerSay("square : square plants in rows");
250 llOwnerSay("random : generate random pattern");
251 llOwnerSay("width : width of the random pattern");
252 llOwnerSay("depth : dept of the random pattern");
253 llOwnerSay("scale : scale factor of the particle");
254 }
255
256 init()
257 {
258 llSetTimerEvent(12.5);
259 planten();
260 Handle = llListen(Channel, "", llGetOwner(), "");
261 active=1;
262 if(pattern == 1) maak_list();
263 }
264
265 default
266 {
268 {
269 llOwnerSay("Commands == /" + (string)Channel + " help ");
270 init();
271 }
272
273 on_rez(integer count) {llResetScript();}
274
275 timer() {planten();}
276
277 touch_start(integer count)
278 {
279 if(active)
280 {
281 llSetTimerEvent(0.0);
282 active=0;
283 }
284
285 else {init();}
286 }
287
288 listen(integer channel,string name,key id,string message)
289 {
290 string match;
291 integer divide=llSubStringIndex(message," ");
292
293 // Grab the rest of the input string
294 string gSubCommand = llToLower(llGetSubString(message, divide + 1, 40));
295 match = checkMatch(message, ["offset", "plaats"]);
296
297 if(match != "") {plant_offset=(float)gSubCommand;}
298
299 else
300 {
301 match = checkMatch( message, ["uit", "off", "stop"]);
302
303 if(match != "")
304 {
305 llSetTimerEvent(0.0);
306 active=0;
307 }
308
309 else
310 {
311 match = checkMatch(message, ["aan", "on", "start"]);
312
313 if(match != "") {init();}
314
315 else
316 {
317 match = checkMatch(message, ["plantspace", "plantafstand"]);
318
319 if(match != "") {plant_space=(float)gSubCommand;}
320
321 else
322 {
323 match = checkMatch( message, ["rowspace", "rijafstand"]);
324
325 if(match != "") {row_space=(integer)gSubCommand;}
326
327 else
328 {
329 match = checkMatch( message, ["rows", "regels"]);
330
331 if(match != "")
332 {
333 integer rw = 0;
334 rw = (integer)gSubCommand;
335
336 if(rw > 0)
337 rows = rw;
338 }
339
340 else
341 {
342 match = checkMatch( message, ["plants", "planten"]);
343
344 if(match != "")
345 {
346 integer pl=0;
347 pl=(integer)gSubCommand;
348
349 if(pl > 0)
350 {
351 if(pattern == 1)
352 {
353 rand_plants=pl;
354 maak_list();
355 }
356
357 else {plants=pl;}
358 }
359 }
360
361 else
362 {
363 match = checkMatch(message, ["show", "toon"]);
364
365 if(match != "") {llSetAlpha(1.0,ALL_SIDES);}
366
367 else
368 {
369 match = checkMatch(message, ["hide", "verstop"]);
370
371 if(match != "") {llSetAlpha(0.0,ALL_SIDES);}
372
373 else
374 {
375 match = checkMatch(message, ["width"]);
376
377 if(match != "" ) {rand_width = (float)gSubCommand;}
378
379 else
380 {
381 match = checkMatch(message, ["depth"]);
382
383 if(match != "") {rand_depth=(float)gSubCommand;}
384
385 else
386 {
387 match = checkMatch(message, ["square"]);
388
389 if(match != "") {pattern=0;}
390
391 else
392 {
393 match = checkMatch(message, ["random"]);
394
395 if(match != "")
396 {
397 pattern = 1;
398 maak_list();
399 }
400
401 else
402 {
403 match = checkMatch(message, ["scale"]);
404
405 if(match != "") {scale = (float)gSubCommand;}
406
407 else {help();}
408 }
409 }
410 }
411 }
412 }
413 }
414 }
415 }
416 }
417 }
418 }
419 }
420 }
421 }
422 }

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