Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Discussion: Particle Garden - Grows slowly, random textures

Zara Vale
Registered User
Join date: 17 Oct 2006
Posts: 10
01-19-2007 17:55
Hello everyone,

This is my first post in here so I hope I'm doing it right. Took me forever to learn how to put the code thing in. Anyway on behalf of Tina Vale and myself I would like to present the particle garden script that I use in my classes.

What does it do?
- It shows a particle picture of what ever texture that is in the object randomly.
- The flowers grow slowly
- It is visible from all angles like all particles

How do you use it?
- Rez an Object
- Change the ROTATION X=90, Y=0, Z=0 (Under the OBJECT tab for the object)
- You put this script into an object (Click on New Script in the object's contents and copy the code below to this object and save)
- Put any other flowers, gnomes, tree textures you want inside it.
- Click to start / stop

CODE

float MAX_RADIUS = 2.5;
float RADIUS_INTERVAL = 0.5;

// Modified values
integer IS_ON = FALSE;
float RADIUS = 2;
string TEXTURE = "f42bcc2b-20c8-9df7-cf1c-69566e377fd8";

garden() {
llParticleSystem([
PSYS_PART_FLAGS, 0 | PSYS_PART_EMISSIVE_MASK |
PSYS_PART_INTERP_COLOR_MASK | PSYS_PART_INTERP_SCALE_MASK,
PSYS_SRC_PATTERN,PSYS_SRC_PATTERN_ANGLE_CONE,

// Texture / Size / Alpha / Color
PSYS_SRC_TEXTURE, TEXTURE,
PSYS_PART_START_SCALE,<0.2000, 0.2000, 0.0000>,
PSYS_PART_END_SCALE,<0.5000, 0.5000, 0.0000>,
PSYS_PART_START_ALPHA,0.000000,
PSYS_PART_END_ALPHA,1.000000,
PSYS_PART_START_COLOR, <1.0,1.0,1.0>,
PSYS_PART_END_COLOR, <1.0,1.0,1.0>,

// Flow
PSYS_PART_MAX_AGE,1000.0000,
PSYS_SRC_BURST_RATE,1.000000,
PSYS_SRC_BURST_PART_COUNT,1,
PSYS_SRC_MAX_AGE,0.000000,

// Rez position
PSYS_SRC_BURST_RADIUS,RADIUS,
PSYS_SRC_INNERANGLE,1.550000,
PSYS_SRC_OUTERANGLE,1.550000,
PSYS_SRC_OMEGA,<0.00000, 0.00000, 4>,
PSYS_SRC_BURST_SPEED_MIN,0.000000,
PSYS_SRC_BURST_SPEED_MAX,0.000000
]);
}

stop() {
llParticleSystem([]);
}

default {
state_entry() {
if(IS_ON) {
llSetTimerEvent(RADIUS_INTERVAL);
garden();
} else {
stop();
}
}

touch_start(integer num_detected) {
if(IS_ON) {
llSetTimerEvent(0.0);
stop();
llWhisper(0, "Garden has stopped");
} else {
llSetTimerEvent(RADIUS_INTERVAL);
garden();
llWhisper(0, "Garden has started");
}
IS_ON = !IS_ON;
}

timer() {
integer max_inventory = llGetInventoryNumber(INVENTORY_TEXTURE);
if(max_inventory > 0) {
TEXTURE = llGetInventoryName(INVENTORY_TEXTURE, (integer)llFrand(max_inventory));
}
RADIUS = llFrand(MAX_RADIUS);
garden();
}
}


Oh I do give a 3 part class on this. And the classes are FREE! Come on down to http://slurl.com/secondlife/Eson/32/162/351/. I'll try to repeat it once a week. Although my plan is to create a new class every week.

Hope I didn't talk to much. And remember me when you make your millions.... lol
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Original Thread
01-21-2007 16:52
/15/c3/161580/1.html
_____________________
i've got nothing. ;)
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
01-22-2007 01:39
minor point, Since IS_ON is FALSE at script reset the code in state_entry is redundant.

Personally I'd invert the touch logic, toggle at the start and process after but thats just me.

I also hate the K&R style but agains thats a personal thing.
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
01-22-2007 10:47
Worth a read if you've not already is the original Field of Dreams by Jimmy Thomson of Bedazzle fame: /8/a0/26220/1.html
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
01-22-2007 13:04
This is just screaming to be made into two states. :)
Zara Vale
Registered User
Join date: 17 Oct 2006
Posts: 10
Thanks for your comment, Newgate
01-23-2007 02:48
Wow such great comments!

Yeah you are right the IS_ON, well it isn't really redundant, been teaching the class for a while, students generally like to have something at the start that they can change by themselves, well that's just my experience. And you need something to turn it on when it starts :)

Isn't it set to touch on start by default?

As for the style, yeah I'd have to say my script tutor did that, she likes to have things more compact. Guess that's up to personal tatse, feel free to change :)

From: Newgate Ludd
minor point, Since IS_ON is FALSE at script reset the code in state_entry is redundant.

Personally I'd invert the touch logic, toggle at the start and process after but thats just me.

I also hate the K&R style but agains thats a personal thing.
Zara Vale
Registered User
Join date: 17 Oct 2006
Posts: 10
Thanks Argent
01-23-2007 02:51
Hi there,

Yes you are right! I could use two states, thanks Argent. I'll try that and repost it.

From: Argent Stonecutter
This is just screaming to be made into two states. :)
Zara Vale
Registered User
Join date: 17 Oct 2006
Posts: 10
Thanks Pale
01-23-2007 02:53
Wow that post is great, wish I had read that when I was making this.

From: Pale Spectre
Worth a read if you've not already is the original Field of Dreams by Jimmy Thomson of Bedazzle fame: /8/a0/26220/1.html
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
01-23-2007 03:03
From: Zara Vale
Wow such great comments!

Yeah you are right the IS_ON, well it isn't really redundant, been teaching the class for a while, students generally like to have something at the start that they can change by themselves, well that's just my experience. And you need something to turn it on when it starts :)

Isn't it set to touch on start by default?

As for the style, yeah I'd have to say my script tutor did that, she likes to have things more compact. Guess that's up to personal tatse, feel free to change :)


As written IS_ON is true so garden will always be called as a part of state_entry.
You could just as easily just call garden() no point in the extra logic :)

if you use my inverted logic in the touch event then, apart from the whispers, its functionally identical to state_entry code. I'd be inclinded to make it a function.

stop is a single line so the overhead of calling a function isnt really worth it.

CODE


OnOff()
{
if(IS_ON)
{
llSetTimerEvent(RADIUS_INTERVAL);
garden();
}
else
{
llSetTimerEvent(0.0);
llParticleSystem([]); // Was the stop function
}
}


default
{
state_entry()
{
OnOff();
}

touch_start(integer num_detected)
{
IS_ON = !IS_ON;
OnOff();
}

timer()
{
integer max_inventory = llGetInventoryNumber(INVENTORY_TEXTURE);
if(max_inventory > 0)
{
TEXTURE = llGetInventoryName(INVENTORY_TEXTURE, (integer)llFrand(max_inventory));
}
RADIUS = llFrand(MAX_RADIUS);
garden();
}
}



Argent's comment is valid although for such a simple example not really worth the overhead, but would be an easy introduction into state logic.