Join us in Phaze Demesnes or follow us:

Home   Show All
Category: Contributor: Creator
Particles Square_Particle_Garden  

Square_Particle_Garden

Square_Particle_Garden

Category: Particles
By : Optikal
Created: 2011-06-13 Edited: 2011-06-13
Worlds: Second Life + OpenSim

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_1.lsl
1 // 3-2-2012 - removed non breaking spaces - FKB
2
3 //// "Fire" PARTICLE TEMPLATE v1 - by Jopsy Pendragon - 4/8/2008
4 //// You are free to use this script as you please, so long as you include this line:
5 //** The original 'free' version of this script came from THE PARTICLE LABORATORY. **//
6
7 // SETUP: Drop one optional particle texture and this script into a prim.
8 // Particles should start automatically. (Reset) the script if you insert a
9 // particle texture later on. Add one or more CONTROLLER TEMPLATES to any
10 // prims in the linked object to control when particles turn ON and OFF.
11
12 // Customize the particle_parameter values below to create your unique
13 // particle effect and click SAVE. Values are explained along with their
14 // min/max and default values further down in this script.
15
16 // converted for pattern spread by Joris Tolsen
17 // -----------------------------------
18 // parameters ------------------------
19 // -- square mode --
20 float row_space = 0.5;
21 float plant_space = 0.5; // used by circle and random too
22 float plant_offset = 0.0;
23 integer rows = 8;
24 integer plants = 8;
25 // -- random mode --
26 integer rand_plants = 30;
27 float rand_width = 15.0;
28 float rand_depth = 12.0;
29 // -------------------
30 float scale = 0.5;
31 integer Handle;
32 integer Channel = 1;
33 integer active = 1;
34 integer pattern = 0; // 0 = square, 1 = random, 2 = circle
35 list plant_list = [];
36 // ----------------------------------
37 list particle_parameters=[]; // stores your custom particle effect, defined below.
38 list target_parameters=[]; // remembers targets found using TARGET TEMPLATE scripts.
39 maak_part(float distance,float angle,string texture){
40 particle_parameters = [ // start of particle settings
41 // Texture Parameters:
43 PSYS_PART_START_SCALE, <scale ,scale, FALSE>,
44 PSYS_PART_END_SCALE, <scale ,scale, FALSE>,
45 PSYS_PART_START_COLOR, < 1,1,1>,
46 PSYS_PART_END_COLOR, < 1,1,1>,
49 // Production Parameters:
54 // Placement Parameters:
55 PSYS_SRC_PATTERN, (integer)4, // 1=DROP, 2=EXPLODE, 4=ANGLE, 8=ANGLE_CONE,
56 // Placement Parameters (for any non-DROP pattern):
59 PSYS_SRC_BURST_RADIUS, distance,
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 PSYS_PART_FLAGS, (integer)( 0 // Texture Options:
72 // After-effect & Influence Options:
78 )
79 //end of particle settings
80 ];
81 llParticleSystem( particle_parameters );
82 }
83 // ---------------------------------
84 // calculate where the plants go
85 // ---------------------------------
86 planten(){
87 if (pattern==0){
88 planten_square();
89 }
90 else if (pattern==1){
91 planten_list();
92 }
93 }
94 planten_square(){
95 integer plants_row=0; // will be set by script !!!
96 integer plants_row_odd=0; // will be set by script !!
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 if (plants - plants_row - plants_row > 0){
109 plants_row_odd=1;
110 }
111 if (rows > 1){
112 fl = rows*row_space-row_space;
113 begin_pos.x-=fl/2.0;
114 }
115 if (plants_row > 1){
116 rl=plants_row*plant_space-plant_space;
117 }
118 if (!plants_row_odd){
119 begin_pos.y+=plant_space/2.0; // even number of rows .. take offset
120 }
121 begin_pos.x+=plant_offset;
122 for(rc=0; rc< rows ; rc++){
123 float rx=begin_pos.x+rc*row_space;
124 for (pc=0; pc<plants_row+plants_row_odd;pc++){
125 float py=begin_pos.y+pc*plant_space;
126 float dst;
127 float ang;
128 float ro=rx-thrower_pos.x;
129 float po=py-thrower_pos.y;
130 dst = llSqrt(ro*ro+po*po);
131 ang = llAtan2(po,ro);
132 maak_part(dst,ang,llGetInventoryName(INVENTORY_TEXTURE,textcnt));
133 if (++textcnt >= number) textcnt=0;
134 llSleep(0.05);
135 }
136 }
138 }
139 planten_list(){
140 integer planten = llGetListLength(plant_list); // will be set by script !!!
141
142 vector thrower_pos;
143 vector begin_pos;
144 integer pc; // plant counter
145 thrower_pos=llGetPos();
146 begin_pos=thrower_pos;
147 begin_pos.x+=plant_offset;
148 for (pc=0; pc< planten ; pc++){
149 vector pp;
150 pp=llList2Vector(plant_list,pc);
151 float px=begin_pos.x+pp.x;
152 float py=begin_pos.y+pp.y;
153 float dst;
154 float ang;
155 float ro=px-thrower_pos.x;
156 float po=py-thrower_pos.y;
157 dst = llSqrt(ro*ro+po*po);
158 ang = llAtan2(po,ro);
160 llSleep(0.05);
161 }
163 }
164 maak_list(){
165 plant_list=[];
166 integer pc; // plant counter
168 float hpd=plant_space/2.0;
169 float dpt=(rand_depth-plant_space)/2.0;
170 for (pc=0; pc<rand_plants;pc++) {
171 integer fout=0;
172 vector pp;
173 do{
174 fout=0;
175 pp=<llFrand(rand_width)-(rand_width/2),llFrand(dpt)+hpd,llFrand(number)>;
176 // check distance
178 if (len > 0){
179 integer tel;
180 for (tel=0;!fout && tel < len ;tel++){
181 vector lp=llList2Vector(plant_list,tel);
182 if (llVecDist(lp,pp)<plant_space){
183 fout=1;
184 }
185 }
186 }
187 }
188 while (fout);
189 plant_list += [pp];
190 }
191 }
192 // -------------------------------------
193 // check if and which command is in str
194 // -------------------------------------
195 string checkMatch( string str, list prefixes ){
196 integer numElements = llGetListLength( prefixes );
198 integer lastChar;
199 string curPrefix;
200 string curStr = llToLower( str );
201 for( i=0; i<numElements; i++ ){
202 curPrefix = llList2String(prefixes, i);
203 lastChar = llStringLength( curPrefix );
204 lastChar -= 1;
205 if ( llGetSubString(curStr, 0, lastChar) == curPrefix )
206 return curPrefix;
207 }
208 return "";
209 }
210 help(){
211 llOwnerSay("command format /"+(string)Channel+" command value");
212 llOwnerSay("commands recognized :");
213 llOwnerSay("uit off stop : switch the particles off");
214 llOwnerSay("aan on start : switch the particles on");
215 llOwnerSay("regels rows : number of rows to plant");
216 llOwnerSay("plants planten : number of plants per row/random patern");
217 llOwnerSay("offset plaats : shift the rows away from the center");
218 llOwnerSay("plantspace : space between plants");
219 llOwnerSay("rowspace : space between rows");
220 llOwnerSay("show toon : make spreader visible");
221 llOwnerSay("hide verstop : hide the spreader");
222 llOwnerSay("square : square plants in rows");
223 llOwnerSay("random : generate random pattern");
224 llOwnerSay("width : width of the random pattern");
225 llOwnerSay("depth : dept of the random pattern");
226 llOwnerSay("scale : scale factor of the particle");
227 }
228 init(){
229 llSetTimerEvent(12.5);
230 planten();
231 Handle = llListen(Channel, "", llGetOwner(), "");
232 active=1;
233 if (pattern == 1) maak_list();
234 }
235
236 default{
237
239 llOwnerSay("Commands == /"+(string)Channel+" help ");
240 init();
241 }
242
243 on_rez(integer count){
245 }
246
247 timer(){
248 planten();
249 }
250
252 if (active){
253 llSetTimerEvent(0.0);
254 active=0;
255 }
256 else{
257 init();
258 }
259 }
260
261 listen(integer channel,string name,key id,string message) {
262 string match;
263 integer divide=llSubStringIndex(message," ");
264 string gSubCommand = llToLower(llGetSubString(message, divide + 1, 40)); // grab the rest of the input string.
265 match = checkMatch( message, ["offset", "plaats"] );
266 if( match != "" ) {
267 plant_offset=(float)gSubCommand;
268 } else {
269 match = checkMatch( message, ["uit", "off", "stop"] );
270 if( match != "" ) {
271 llSetTimerEvent(0.0);
272 active=0;
273 } else {
274 match = checkMatch( message, ["aan", "on", "start"] );
275 if( match != "" ) {
276 init();
277 } else {
278 match = checkMatch( message, ["plantspace", "plantafstand"] );
279 if( match != "" ) {
280 plant_space=(float)gSubCommand;
281 } else {
282 match = checkMatch( message, ["rowspace", "rijafstand"] );
283 if( match != "" ) {
284 row_space=(integer)gSubCommand;
285 } else {
286 match = checkMatch( message, ["rows", "regels"] );
287 if( match != "" ) {
288 integer rw=0;
289 rw=(integer)gSubCommand;
290 if (rw > 0) rows = rw;
291 } else {
292 match = checkMatch( message, ["plants", "planten"] );
293 if( match != "" ) {
294 integer pl=0;
295 pl=(integer)gSubCommand;
296 if (pl > 0) {
297 if (pattern == 1) {
298 rand_plants=pl;
299 maak_list();
300 } else {
301 plants=pl;
302 }
303 }
304 } else {
305 match = checkMatch( message, ["show", "toon"] );
306 if( match != "" ) {
308 } else {
309 match = checkMatch( message, ["hide", "verstop"] );
310 if( match != "" ) {
312 } else {
313 match = checkMatch( message, ["width"] );
314 if( match != "" ) {
315 rand_width=(float)gSubCommand;
316 } else {
317 match = checkMatch( message, ["depth"] );
318 if( match != "" ) {
319 rand_depth=(float)gSubCommand;
320 } else {
321 match = checkMatch( message, ["square"] );
322 if( match != "" ) {
323 pattern=0;
324 } else {
325 match = checkMatch( message, ["random"] );
326 if( match != "" ) {
327 pattern=1;
328 maak_list();
329 } else {
330 match = checkMatch( message, ["scale"] );
331 if( match != "" ) {
332 scale = (float)gSubCommand;
333 } else {
334 help();
335 }}}}}}}}}}}}}}
336 }
337 }