Skip to content

Commit

Permalink
Filter 'Spline Spirograph' : Add option for rendering animations.
Browse files Browse the repository at this point in the history
  • Loading branch information
dtschump committed Apr 15, 2024
1 parent cce5bdd commit 0cef7b1
Showing 1 changed file with 30 additions and 23 deletions.
53 changes: 30 additions & 23 deletions src/gmic_stdlib.gmic
Expand Up @@ -58931,7 +58931,7 @@ fx_sine_curve_preview :
fx_sine_curve $*
k[0]

#@gui Spline Spirograph : fx_spline_spirograph, fx_spline_spirograph
#@gui Spline Spirograph : fx_spline_spirograph, fx_spline_spirograph_preview
#@gui : Seed = int(0,0,65535)
#@gui : Randomize Seed = button()
#@gui : sep = separator()
Expand All @@ -58951,44 +58951,51 @@ fx_sine_curve_preview :
#@gui : Normalization Strength (%) = float(50,0,100)
#@gui : Normalization Radius (%) = float(50,0,100)
#@gui : sep = separator()
#@gui : Number of Output Frames = _int(1,1,512)
#@gui : sep = separator()
#@gui : note = note("<small>Author: <i>David Tschumperlé</i>.      Latest Update: <i>2024/04/10</i>.</small>")
fx_spline_spirograph :
seed,randomize_seed,complexity,sampling,radius,vertices,twist,offset,\
colors,is_alpha,randomize_parameters,normalization_strength,normalization_radius=${1-13}
colors,is_alpha,randomize_parameters,normalization_strength,normalization_radius,nb_frames=${1-14}
if $randomize_seed seed:=v(65535) fi
if $randomize_parameters
complexity,sampling,radius,vertices,twist,offset,colors:=u(100),u(200),u(100),v(2,16),u(100),u(-180,180),v(46)
fi
foreach {
nm={n}
if $is_alpha to_a else remove_opacity fi
f 0 => canvas
palette $colors r. 360,1,1,3,3 to_colormode. {0,s} => palette
palette $colors r. 360,1,1,3,3 to_colormode. {0,s}

# Parameterization of a random spline curve.
rs[canvas] 100,100,-1,2 ${}
rs[0] 100,100,-1,2 ${}
srand $seed noise_poissondisk. {max(5,lerp(100,0,$complexity%^0.3))}
0 eval.. "i?da_push([u,x*w#$canvas%,y*h#$canvas%])" da_freeze. rm..
0 eval.. "i?da_push([u,x*w#0%,y*h#0%])" da_freeze. rm..
sort. +,y channels. 1,2
r. 1,{max(1,h*max(w#0,h#0)*($sampling%)^2)},1,2,5 => coords

# Draw spirograph along spline.
eval[coords] ":
const R = $radius%*max(w#$canvas,h#$canvas);
const N = $vertices;
C = round(I);
pP = [ 0,0 ];
repeat (N + (N>2),k,
ang = ($offset + lerp(0,360,k/N) + 360*lerp(0,64,$twist%^2)*y/h)%360;
P = round(C + R*cexp([0,ang°]));
k>0?polygon(#$canvas,2,pP,P,-1,I(#$palette,ang,0,0,1));
pP = P;
)"
k[canvas]
n 0,255 normalize_local {10*$normalization_strength%},{max(1,($normalization_radius%)^3*10*max(w,h)%)}
r. 1,{max(1,h*max(w#0,h#0)*($sampling%)^2)},1,2,5

repeat 0$_is_preview?1:$nb_frames {
+f[0] 0
eval[2] ": # Draw spirograph along spline.
const R = $radius%*max(w#0,h#0);
const N = $vertices;
const off = $offset + lerp(0,360,($>)/$nb_frames);
C = round(I);
pP = [ 0,0 ];
repeat (N + (N>2),k,
ang = (off + lerp(0,360,k/N) + 360*lerp(0,64,$twist%^2)*y/h)%360;
P = round(C + R*cexp([0,ang°]));
k>0?polygon(#-1,2,pP,P,-1,I(#1,ang,0,0,1));
pP = P;
)"
}
k[3--1]
n 0,255 normalize_local {0.1*$normalization_strength},{max(1,($normalization_radius%)^3*10*max(w,h)%)}
}
u \{$seed\}\{0\}\{$complexity\}\{$sampling\}\{$radius\}\{$vertices\}\{$twist\}\{$offset\}\
\{$colors\}\{$is_alpha\}\{0\}\{$normalization_strength\}\{$normalization_radius\}
\{$colors\}\{$is_alpha\}\{0\}\{$normalization_strength\}\{$normalization_radius\}\{$nb_frames\}

fx_spline_spirograph_preview :
_is_preview=1 fx_spline_spirograph $*

#@gui Superformula : fx_superformula, fx_superformula(1)
#@gui : Resolution = int(4096,2,8192)
Expand Down

0 comments on commit 0cef7b1

Please sign in to comment.