Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env gmic
- # File : glenz3d.gmic
- # Author : David Tschumperle
- # Entrypoint when run from CLI:
- go =>[^] "3D Glenz" e[] "" animate 30
- # Main function
- go :
- v 0
- # Init canvas.
- W,H=800,600
- $W,$H,1,3,"y<h/2?lerp([ 100,100,255 ],[ 30,0,0 ],2*y/h):[ 0,0,0 ]" => background
- # Generate 3D base glenz object.
- l[] {
- ({'CImg3d'},14,24:y)
- 1,14,1,3,"y<8?[ y&1,(y&2)>>1,(y&4)>>2 ] - 0.5:(V = [ 0,0,0 ]; V[(y - 8)>>1] = 0.75*(y&1?1:-1); V)"
- 0 eval "
- add(p0,p1,p2,p3,p4) = da_push([ 3,p0,p1,p4 ],[ 3,p1,p2,p4 ],[ 3,p2,p3,p4 ],[ 3,p3,p0,p4 ]);
- add(0,2,6,4,8); add(3,1,5,7,9); add(0,4,5,1,10); add(3,7,6,2,11); add(0,1,3,2,12); add(5,4,6,7,13)"
- da_freeze. 1,100%,1,3,200 1,100%,1,1,0.5 permute cyzx y a y
- } => glenz3d
- # Create chromatic variations of the base glenz.
- nb_cols=10
- repeat $nb_cols {
- ({lerp(0,360,$>/$nb_cols)}^1^1) hsv2rgb. col={^} rm.
- +l[glenz3d] { s3d 1,100%,1,3,y&1?[$col]:[255,255,255] permute. cyzx y. j... . rm. a y } => glenz3d_$>
- }
- rm[glenz3d]
- # Generate 3D checkerboard.
- l[] {
- plane3d {$W*[4,2]},101,100 -3d {2*$W},$W,0
- s3d 1,100%,1,3,"(y&1)?[ 100,0,50 ]:[ 130,20,70 ]" permute. cyzx y. j... . rm. a y
- } => checkerboard3d
- # Init glenz attributes.
- 1,128,1,7,"[ u,u,v($nb_cols - 1),abs(3*g),g,g,g ]" => glenz_attr
- # Do animation.
- nbf=180
- repeat $nbf { f=$> t0:=$f/$nbf
- e[] "\r > Frame "{$f+1}/$nbf
- [background] => canvas
- # Draw checkeboard.
- ++3d[checkerboard3d] 0,{lerp(0,36*$W%,$t0)%(4*$W%)},0 r3d. 1,0,0,-80 j3d.. .,50%,{-2,h/2},0,1,2,0,0,250 rm.
- # Draw 3D glenz objects.
- repeat {glenz_attr,h} {
- t,x,c,amp0,rx,ry,rz={glenz_attr,I[$>]}
- t:=($t+$t0)%1
- y:="const y0 = 70*$H%; const amp = lerp($amp0,0.3,$t)*$W; y0 - amp*abs(sin(20*$t))^0.5"
- z:=lerp(100000,-600,$t^0.1)
- [glenz3d_$c] o3d. {lerp(0,0.75,$t)}
- r3d. 1,0,0,{600*$rx*$t} r3d. 0,1,0,{600*$ry*$t} r3d. 0,0,1,{600*$rz*$t}
- -3d. 0,0.5,0 *3d. {$W/6} +3d. {3*lerp(-$W,$W,$x)},$y,$z
- }
- +3d[-{glenz_attr,h}--1]
- j3d.. .,50%,43%,0,1,3,1,1 rm.
- }
- k[-$nbf--1]
- # End of file.
Add Comment
Please, Sign In to add comment