Jump to content
Light-O-Rama Forums

Nutcracker, new effect: user_defined.


smeighan

Recommended Posts

Would you like to write your animations? The new effect, user_defined allows you to do this.

The audience for this effect will be anyone who has some programming knowledge. You are going to provide a code snippet in the PHP language.

When you select user_defined, the Nutcracker will call a routine called user_defined.

here is the wrapper for the call
$maxFrame=80;
for($frame=1;$frame<=$maxFrame;$frame++)
for($s=1;$s<=$maxStrand;$s++)
for($p=1;$p<=$maxPixel;$p++)
$rgb=user_defined($frame,$s,$p,$maxFrame,$maxStrand,$maxPixel,$user1);


So your job is to create code that will return a rgb value for every frame, strand and pixel.



Lets have some examples:
Example #1

if($frame%4==0) $rgb=hexdec("#FFFFFF"); // WHITE
if($frame%4==1) $rgb=hexdec("#FF0000"); // RED
if($frame%4==2) $rgb=hexdec("#00FF00"); // GREEN
if($frame%4==3) $rgb=hexdec("#0000FF"); // BLUE


hexdec(string) converts hexadecimal string into a decimal.

array_to_save
username f
user_target ZZ_ZZ
effect_class user_defined
effect_name USER1
window_degrees 180
start_color #FFFFFF
end_color #FFFFFF
frame_delay 200
sparkles 0
param1 1
param2 2
seq_duration 2
php_program if($frame%4==0) $rgb=hexdec("#FFFFFF"); if($frame%4==1) $rgb=hexdec("#FF0000"); if($frame%4==2) $rgb=hexdec("#00FF00"); if($frame%4==3) $rgb=hexdec("#0000FF");
submit Submit Form to create your effect
OBJECT_NAME user_defined

ZZ_ZZ+USER1.gif






Example #2

$rgb=0;
if($s%2==0)
{
if($p<=$frame)
$rgb=hexdec("FF0000");
}
else if($s%2==1)
{
if($p>=($maxPixel-$frame))
$rgb=hexdec("0000FF");
}


array_to_save
username f
user_target ZZ_ZZ
effect_class user_defined
effect_name USER2
window_degrees 180
start_color #FFFFFF
end_color #FFFFFF
frame_delay 100
sparkles 0
param1 1
param2 2
seq_duration 2
php_program $rgb=0; if($s%2==0) { if($p<=$frame) $rgb=hexdec("FF0000"); } else if($s%2==1) { if($p>=($maxPixel-$frame)) $rgb=hexdec("0000FF"); }
submit Submit Form to create your effect
OBJECT_NAME user_defined
ZZ_ZZ+USER2.gif




Example #3

$H=$S=$V=0;
if($s%2==0)
{
if($p<=$frame)
{
$H=$p/$maxPixel;
$S=$V=1;
}
}
else if($s%2==1)
{
if($p>=($maxPixel-$frame))
{
$H=1- ($p/$maxPixel);
$S=$V=1;
}
}
$rgb=HSV_TO_RGB ($H, $S, $V);

Now we get to using a function that will use HUE, SATURATION and VALUE. H is a value between 0 to 1.0. This varies the hue through the color specturm.
$S, saturation, is a 1 if we are fully saturated. S=0 means we have a WHITE. $V is the brightness value. $V=1 full brightness, $V=0 = black.

H,S,V is much better for creating animations because of the ease of sliding through the colors. I wrote a function, HSV_TO_RGB to change HSV into an rgb value.

array_to_save
username f
user_target ZZ_ZZ
effect_class user_defined
effect_name USER3
window_degrees 180
start_color #FFFFFF
end_color #FFFFFF
frame_delay 100
sparkles 0
param1 1
param2 2
seq_duration 2
php_program $H=$S=$V=0; if($s%2==0) { if($p<=$frame) { $H=$p/$maxPixel; $S=$V=1; } } else if($s%2==1) { if($p>=($maxPixel-$frame)) { $H=1- ($p/$maxPixel); $S=$V=1; } } $rgb=HSV_TO_RGB ($H, $S, $V);
submit Submit Form to create your effect
OBJECT_NAME user_defined

ZZ_ZZ+USER3.gif




Example #4

$s_ratio=$s/$maxStrand; $p_ration=$p/$maxPixel;
$H1=sin($s_ratio) * cos($p_ratio);
$H = $H1 * $frame;
if($H>1) $H=$H- intval($H);
$S=$V=1;
$rgb=HSV_TO_RGB ($H, $S, $V);

We can use math functions (sin, cos .etc). We need to make sure $H is never greater than 1.

array_to_save
username f
user_target ZZ_ZZ
effect_class user_defined
effect_name USER4
window_degrees 180
start_color #FFFFFF
end_color #FFFFFF
frame_delay 200
sparkles 0
param1 4
param2 2
seq_duration 2
php_program $s_ratio=$s/$maxStrand; $p_ration=$p/$maxPixel; $H1=sin($s_ratio) * cos($p_ratio); $H = $H1 * $frame; if($H>1) $H=$H- intval($H); $S=$V=1; $rgb=HSV_TO_RGB ($H, $S, $V);
submit Submit Form to create your effect
OBJECT_NAME user_defined

ZZ_ZZ+USER4.gif




Example #5

$s_ratio=$frame*$s/$maxStrand; $p_ration=$frame*$p/$maxPixel;
$H1=sin($s_ratio) * sin($s_ratio) + cos($p_ratio)* cos($p_ratio);
$H = $H1 * $p/$maxPixel;
if($H>1) $H=$H- intval($H);
$S=$V=1;
$rgb=HSV_TO_RGB ($H, $S, $V);

array_to_save
username f
user_target ZZ_ZZ
effect_class user_defined
effect_name USER5
window_degrees 180
start_color #FFFFFF
end_color #FFFFFF
frame_delay 200
sparkles 0
param1 4
param2 2
seq_duration 2
php_program $s_ratio=$frame*$s/$maxStrand; $p_ration=$frame*$p/$maxPixel; $H1=sin($s_ratio) * sin($s_ratio) + cos($p_ratio)* cos($p_ratio); $H = $H1 * $p/$maxPixel; if($H>1) $H=$H- intval($H); $S=$V=1; $rgb=HSV_TO_RGB ($H, $S, $V);
submit Submit Form to create your effect
OBJECT_NAME user_defined

ZZ_ZZ+USER5.gif



Example #6


$rgb=hexdec("#FFFFFF");
$H=$S=$V=0;
$p_half = $maxPixel/2; // find half way point going down tree
$p2=$p*2; // double speed of pixel movement
if($p2<$p_half) $p_working = $p2;
else $p_working = ($p*2-$p_half);
if($s%2==1)
{
$H=$p_working/$maxPixel;
$H = $H*$frame/$maxFrame;
$S=$V=1;
}
else
{
$H=1-$p_working/$maxPixel;
$H = $H*$frame/$maxFrame;
$S=$V=1;
}
$rgb=HSV_TO_RGB ($H, $S, $V);
return $rgb;

array_to_save
username f
user_target ZZ_ZZ
effect_class user_defined
effect_name USER6
window_degrees 180
start_color #FFFFFF
end_color #FFFFFF
frame_delay 200
sparkles 0
param1 4
param2 2
seq_duration 2
php_program $rgb=hexdec("#FFFFFF"); $H=$S=$V=0; $p_half = $maxPixel/2; // find half way point going down tree $p2=$p*2; // double speed of pixel movement if($p2<$p_half) $p_working = $p2; else $p_working = ($p*2-$p_half); if($s%2==1) { $H=$p_working/$maxPixel; $H = $H*$frame/$maxFrame; $S=$V=1; } else { $H=1-$p_working/$maxPixel; $H = $H*$frame/$maxFrame; $S=$V=1; } $rgb=HSV_TO_RGB ($H, $S, $V); return $rgb;
submit Submit Form to create your effect
OBJECT_NAME user_defined

ZZ_ZZ+USER6.gif




Example #7

# function user_defined($frame,$s,$p,$maxFrame,$maxStrand,$maxPixel,$param1,$param2,$start_color,$end_color)
$rgb=hexdec("#FFFFFF");
$H=$S=$V=1;
$slice=$param1; // use first parameter passed in from user
$slice_size=$maxPixel/$slice;
$H0 = (($frame% $slice) * $slice_size);
$H=($p+$H0)/$maxPixel;
if($H>1) $H = $H-intval($H);

$rgb=HSV_TO_RGB ($H, $S, $V);
//echo "

f,s,p=$frame,$s,$p. slice_size=$slice_size. H0=$H0, H=$H
";
//echo "
 maxP=$maxPixel. H,S,V=$H,$S,$V, rgb=$rgb
";

return $rgb;

Here you see we are using the passed in parameter from the user form, $param1. You have 4 variables you can use:
$param1, $param2, $start_color, $end_color.

Also, see how to debug your code by outputting a echo "
stuff to see
n"; These debug statements are currently commented out.

array_to_save
username f
user_target ZZ_ZZ
effect_class user_defined
effect_name USER7
window_degrees 180
start_color #FFFFFF
end_color #FFFFFF
frame_delay 200
sparkles 0
param1 3
param2 2
seq_duration 2
php_program 1) $H = $H-intval($H); $rgb=HSV_TO_RGB ($H, $S, $V); //echo "
f,s,p=$frame,$s,$p. slice_size=$slice_size. H0=$H0, H=$H
"; //echo "
maxP=$maxPixel. H,S,V=$H,$S,$V, rgb=$rgb
"; return $rgb; ># function user_defined($frame,$s,$p,$maxFrame,$maxStrand,$maxPixel,$param1,$param2,$start_color,$end_color) $rgb=hexdec("#FFFFFF"); $H=$S=$V=1; $slice=$param1; // use first parameter passed in from user $slice_size=$maxPixel/$slice; $H0 = (($frame% $slice) * $slice_size); $H=($p+$H0)/$maxPixel; if($H>1) $H = $H-intval($H); $rgb=HSV_TO_RGB ($H, $S, $V); //echo "
f,s,p=$frame,$s,$p. slice_size=$slice_size. H0=$H0, H=$H
"; //echo "
maxP=$maxPixel. H,S,V=$H,$S,$V, rgb=$rgb
"; return $rgb;
submit Submit Form to create your effect
OBJECT_NAME user_defined

ZZ_ZZ+USER7.gif


Well, have fun creating your own animation effects. If you find a cool one, please post it. I will add it into the effects library.

thanks

sean
Link to comment
Share on other sites

you programmers blow me away!!!!

Darn it...should have listened to those guys would said computers were the next big thing!!!

But NOOOOOOOO...I took accounting!!!

To this day I have NEVER held a job where I used my accounting degree... :shock:

Link to comment
Share on other sites

jimswinder wrote:

you programmers blow me away!!!!

Darn it...should have listened to those guys would said computers were the next big thing!!!

But NOOOOOOOO...I took accounting!!!

To this day I have NEVER held a job where I used my accounting degree...  :shock:


Hi Jim;

Here is another simple one , just for you.

This program:
$H = rand(1,100)/100;
$S=rand(1,100)/100;
$V=rand(1,100)/100;
if($p%5==0) { $H=$p/$maxPixel; $S=$V=1; }
$rgb=HSV_TO_RGB ($H, $S, $V);

makes this tree:

ZZ_ZZ+USER8.gif
Link to comment
Share on other sites

smeighan wrote:

jimswinder wrote:
you programmers blow me away!!!!

Darn it...should have listened to those guys would said computers were the next big thing!!!

But NOOOOOOOO...I took accounting!!!

To this day I have NEVER held a job where I used my accounting degree... :shock:


Hi Jim;

Here is another simple one , just for you.

This program:
$H = rand(1,100)/100;
$S=rand(1,100)/100;
$V=rand(1,100)/100;
if($p%5==0) { $H=$p/$maxPixel; $S=$V=1; }
$rgb=HSV_TO_RGB ($H, $S, $V);


lol...

Yeah...REALLY simple!!

I do recognize the $ sign and the numbers 1 and 100!!! :D
Link to comment
Share on other sites

Jeff Millard wrote:

jimswinder wrote:
smeighan wrote:
This program:
$H = rand(1,100)/100;
$S=rand(1,100)/100;
$V=rand(1,100)/100;
if($p%5==0) { $H=$p/$maxPixel; $S=$V=1; }
$rgb=HSV_TO_RGB ($H, $S, $V);
lol...
Yeah...REALLY simple!!
I do recognize the $ sign and the numbers 1 and 100!!! :P
Ooh ooh! I recognize a percent sign! Does that make Jim and I honorary programmers???
no...Honorary Accountants... :D
Link to comment
Share on other sites

Champion Sound Entertainment wrote:

What kind of lights do you need to create trees like these?

I use some RGB seeds...

best time to plant them is on Earth Day...

April 22nd...

:)
Link to comment
Share on other sites

Guest wbottomley

jimswinder wrote:

Champion Sound Entertainment wrote:
What kind of lights do you need to create trees like these?

I use some RGB seeds...

best time to plant them is on Earth Day...

April 22nd...

:)


+1 For Jim today. :)
Link to comment
Share on other sites

jimswinder wrote:

Champion Sound Entertainment wrote:
What kind of lights do you need to create trees like these?

I use some RGB seeds...

best time to plant them is on Earth Day...

April 22nd...

:)

But consider the source. This may only get you horizontal rgb trees.
Link to comment
Share on other sites

Champion Sound Entertainment wrote:

What kind of lights do you need to create trees like these?


You need strings that have each RGB pixel addressable.

The LOR CCR would be one choice.

I am going to be using these
http://www.diylightanimation.com/wiki/index.php?title=Equipment#Smart_Strings

I will be building 8 strings of 100 pixels each. Here is where i will buy the 100 pixel string
http://www.aliexpress.com/fm-store/701799/209889132-495658159/100-node-LED-pixel-string-DC12V-input-new-model-IP68.html


495658159-100-node-LED-pixel-string-DC12V-input-new-model-IP68-wholesalers.html

There is also the ELOR controller from http://www.sandevices.com/ that allows you to connect things together.

There are probably more choices for LOR. Others smarter than me could answer this.

thanks
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...