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
Color Color_fade_script  

Color_fade_script

Color fade script.lsl

Category: Color
By : Jesrad Seraph
Created: 2010-01-10 Edited: 2010-01-10
Worlds: Second Life

the Zip file

Download all files for Color_fade_script
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Color_fade_script_1.lsl
1
2 // linkset color variation over time
3 // can be random or sequential in hue
4 // random is NOT advised as it strains the Sim's resources
5
6 // Author: Jesrad Seraph
7 // use, modify and redistribute freely
8
9
10 // commands:
11 // /23 toggle => toggles between sequential and random color change
12 // /23 reset => sets color back to pure red, useful to sync multiple items
13 // /23 start => starts the color change effect
14 // /23 stop => freezes the color change effect
15 // /23 clear => stops the effect and sets color to white
16 // /23 blue => stops the effect and sets color to pure blue
17 // /23 green => stops the effect and sets color to pure green
18 // /23 red => stops the effect and sets color to pure red
19 // /23 saturate => augments the saturation up 10%
20 // /23 desaturate => decreases saturation by 10%
21 // /23 faster => makes the effect twice as fast (WARNING may cause lag on the whole Sim at high speeds)
22 // /23 slower => makes the effect half as fast
23 // /23 alpha => makes the object 10% more transparent
24 // /23 dealpha => makes the object 10% less transparent
25 // /23 transparent => makes the object fully transparent
26 // /23 opaque => makes the object fully opaque
27 // /23 change => manually triggers the color change
28 // saturation control only affects the sequential fade effect
29
30 key owner;
31
32 integer ISSEQUENTIAL = 1;
33
34 integer listen_handle;
35
36 float colordelay = 2.0;
37 // this is the default color update frequency
38
39 float unsaturation = 0.0;
40 float opacity = 1.0;
41
42 vector currentcolor = <1.0, 0.0, 0.0>;
43 // switch to pure red on reset
44
45 integer currentangle = 0;
46 integer currentdir = 0;
47 // 0 for red to green
48 // 1 for green to blue
49 // 2 for blue to red
50
51 integer angle_increment = 3;
52 // determines the number of steps around the hue wheel.
53 // the lower the more steps, doesn't go over 90
54 // Always use a factor of 90 for better results
55 // 3 or 5 are good values
56
57
58
59 colorupdate()
60 {
61 // change current color
62 if(ISSEQUENTIAL < 0)
63 {
64 // set a random color:
65 currentcolor = <llFrand(1),llFrand(1),llFrand(1)>;
66 }
67 else
68 {
69 // rotate the color vector along X Y Z to vary between red, green and blue
70 if(currentangle >= 90)
71 {
72 currentdir += 1;
73 currentangle = 0;
74 if((currentdir >= 3) || (currentdir < 0))
75 currentdir = 0;
76 }
77 currentangle += angle_increment;
78 }
79 }
80
81 colorchange()
82 {
83 float float_angle = ((float)currentangle) * DEG_TO_RAD;
84 float sinelement = llSin(float_angle) * (1.0 - unsaturation) + unsaturation;
85 float coselement = llCos(float_angle) * (1.0 - unsaturation) + unsaturation;
86
87 if(ISSEQUENTIAL > 0)
88 {
89 if(currentdir == 0)
90 {
91 currentcolor = <coselement, sinelement, unsaturation>;
92 }
93 else if(currentdir == 1)
94 {
95 currentcolor = <unsaturation, coselement, sinelement>;
96 }
97 else if(currentdir == 2)
98 {
99 currentcolor = <sinelement, unsaturation, coselement>;
100 }
101 }
102
103 llSetColor(currentcolor,ALL_SIDES);
104 llMessageLinked(LINK_SET,105,(string)currentcolor, NULL_KEY);
105 }
106
107 default
108 {
110 {
111 llListenRemove(listen_handle);
112 owner=llGetOwner();
113 listen_handle = llListen(23,"",owner,"");
114 }
115
116 timer()
117 {
118 colorupdate();
119 colorchange();
120 }
121
122 listen(integer channel, string name, key id, string message)
123 {
124 if(message == "toggle")
125 {
126 ISSEQUENTIAL *= -1;
127 }
128 else if(message == "reset")
129 {
130 currentcolor = <1.0, 0.0, 0.0>;
131 unsaturation = 0.0;
132 currentangle = 0;
133 currentdir = 0;
134 ISSEQUENTIAL = 1;
135 colordelay = 2.0;
136 llSetColor(currentcolor,ALL_SIDES);
137 llMessageLinked(LINK_SET,105,(string)currentcolor, NULL_KEY);
138 llSetTimerEvent(colordelay);
139 }
140 else if(message == "start")
141 {
142 llSetTimerEvent(colordelay);
143 }
144 else if(message == "stop")
145 {
147 }
148 else if(message == "clear")
149 {
151 currentcolor = <1.0, 1.0, 1.0>;
152 llSetColor(currentcolor,ALL_SIDES);
153 llMessageLinked(LINK_SET,105,(string)currentcolor, NULL_KEY);
154 }
155 else if(message == "blue")
156 {
158 unsaturation = 0.0;
159 currentangle = 0;
160 currentdir = 2;
161 colorchange();
162 }
163 else if(message == "green")
164 {
166 unsaturation = 0.0;
167 currentangle = 0;
168 currentdir = 1;
169 colorchange();
170 }
171 else if(message == "red")
172 {
174 unsaturation = 0.0;
175 currentangle = 0;
176 currentdir = 0;
177 colorchange();
178 }
179 else if(message == "black")
180 {
182 currentcolor = <0.0, 0.0, 0.0>;
183 llSetColor(currentcolor,ALL_SIDES);
184 llMessageLinked(LINK_SET,105,(string)currentcolor, NULL_KEY);
185 }
186 else if(message == "faster")
187 {
188 colordelay /= 2.0;
189 if(colordelay < 0.25)
190 colordelay = 0.25;
191 llSetTimerEvent(colordelay);
192 }
193 else if(message == "slower")
194 {
195 colordelay *= 2.0;
196 llSetTimerEvent(colordelay);
197 }
198 else if(message == "saturate")
199 {
200 unsaturation -= 0.1;
201 if(unsaturation < 0.0)
202 unsaturation = 0.0;
203 colorchange();
204 }
205 else if(message == "desaturate")
206 {
207 unsaturation += 0.1;
208 if(unsaturation > 1.0)
209 unsaturation = 1.0;
210 colorchange();
211 }
212 else if(message == "alpha")
213 {
214 opacity -= 0.1;
215 if(opacity < 0.0)
216 opacity = 0.0;
217 llSetAlpha(opacity, ALL_SIDES);
219 }
220 else if(message == "dealpha")
221 {
222 opacity += 0.1;
223 if(opacity > 1.0)
224 opacity = 1.0;
225 llSetAlpha(opacity, ALL_SIDES);
227 }
228 else if(message == "transparent")
229 {
230 opacity = 0.0;
231 llSetAlpha(opacity, ALL_SIDES);
233 }
234 else if(message == "opaque")
235 {
236 opacity = 1.0;
237 llSetAlpha(opacity, ALL_SIDES);
239 }
240 else if(message == "change")
241 {
242 colorupdate();
243 colorchange();
244 }
245 }
246 }// END //

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