Nutcracker, new eff...
 
Notifications
Clear all

Nutcracker, new effect: user_defined. Do you want to create your own animation code?

6 Posts
4 Users
0 Reactions
4,828 Views
smeighan
Posts: 2595
Topic starter
(@smeighan)
Famed Member
Joined: 15 years ago
[#19242]

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,$param1,$param2,$start_color,$end_color);

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. The modulo operator in php is %. So this code changes every 4th frame and sets all pixels to a single color.

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

Example #2

$rgb=0;
if($s%2==0) // for even numbered strands
{
if($p<=$frame) // if the current pixel number, $p, is less than our current frame
$rgb=hexdec("FF0000"); // then assign the color RED
}
else if($s%2==1) // for odd numbered strands
{
if($p>=($maxPixel-$frame)) // if the current pixel number is > than the bottom half of a strand
$rgb=hexdec("0000FF"); // set color BLUE
}

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=($maxPixel-$frame)) $rgb=hexdec(\"0000FF\"); }
submit Submit Form to create your effect
OBJECT_NAME user_defined

Example #3

$H=$S=$V=0;
if($s%2==0) // for odd numbered strands
{
if($p<=$frame)
{
$H=$p/$maxPixel; // set the HUE to be a ratio between 0 to 1.
$S=$V=1; // set saturation and brightness to be full on
}
}
else if($s%2==1) // for odd numbered strands
{
if($p>=($maxPixel-$frame))
{
$H=1- ($p/$maxPixel); // set the inverse color of above. Notice we subtract from 1 inverting number.
$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=($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

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

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

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

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

"; 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

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


5 Replies
Posts: 185
(@lefserev)
Estimable Member
Joined: 16 years ago

Just amazing. You never cease to amaze me with your dedicated work on the Nutcracker.


Reply
Posts: 844
(@tfischer)
Prominent Member
Joined: 17 years ago

Holy cow! Now I guess we can't complain that there aren't enough effects anymore! 😉

Great work, as always!


Reply
Matt_Edwards
Posts: 2664
(@matt-edwards)
Famed Member
Joined: 18 years ago

excelent stuff - any news on the grid?


Reply
smeighan
Posts: 2595
Topic starter
(@smeighan)
Famed Member
Joined: 15 years ago

Grid is next up i think.,

I wrote out the pseudo code for it last week.

I fixed these bugs this last week
1) Sticky fields should now work (things like sparkles that wouldnt remember value).
2) Fixed lms file
3) Re-wrote some major chunks of Nutcracker so it will work in both Windows and Linux.
4) Created code to install the Nutcracker onto Windows 7 and Windows XP
5) Create an update script that will use a manifest of all files, check the checksums and only download changes files to your windows box
6) released user_defined effect. I wrote this about a week ago, it needed some clean up. now done
7) Corrected a bug in the text effect. It now works on both windows and linux
8) removed any reference to imagick. Now gnuplot is solely being used to create animated gif's
9) The entire install of nutcracker database, users, database tables and all code takes about 45 seconds. Updates after that are < 5 seconds.
10) did some research on where i will put nutcracker as an open source project.
11) Created new option in the input form to allow a textarea box so people can paste program code there.

so, i have not been idle. Just keep plugging away. I lost two days trying to get imagick and WAMP or XAMP to work together. I gave up and took a different path with gnuplot
now the sole graphics engine.

stay tuned for more.


Reply
Page 1 / 2
Share: