Advertisement
Guest User

Fractal 3d Solenoid in G'MIC

a guest
Feb 9th, 2017
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.58 KB | None | 0 0
  1. # Create a random fractal solenoid, as shown in http://paulbourke.net/fractals/solenoid/
  2. # using the G'MIC script language.
  3. solenoid3d :
  4.   -torus3d 100,10,64,32 -col3d. ${-RGB} -nm. 0,0,0,1,0,0,0,1,0,0,0,1,100,10 # Create initial torus
  5.   -repeat 5 # Number of scales
  6.     subd={round(1.25^-($>+1)*[64,32])} # Torus resolution for this scale (decreasing).
  7.     col=${-RGB} # Same random color for a single scale
  8.     N={round(u(4,8))} # Random number of subdivision for this scale
  9.     -repeat $! -l[$<] # For each existing torus, let's add children !
  10.       nm={n}
  11.       -if {narg($nm)>1}
  12.         X={([$nm])[0,3]}  # Current center
  13.         R={([$nm])[3,9]}  # Current rotation matrix
  14.         r={([$nm])[12,2]} # Current radii
  15.         nr={[$r]/2.5}     # New radii (decreasing).
  16.         -repeat $N # Start the loop to add children
  17.           ang={$>*360/$N}
  18.           nX={rad=$ang*pi/180;[$X]+([$r])[0]*[$R]*[cos(rad),sin(rad),0]}  # New center
  19.           nR={mul([$R],mul(rot(0,0,1,$ang),rot(1,0,0,90),3),3)}           # New rotation matrix
  20.           -torus3d $nr,$subd nbp={i[6]} # Add new torus
  21.           -sh. 8,{8+3*$nbp-1},0,0 -r. 3,$nbp,1,1,-1 3,3,1,1,$nR -transpose. -m*[-2,-1] -rm. # Small hack to orient 3d torus with matrix nR.
  22.           -+3d. $nX -col3d. $col # Translate torus and assign color
  23.           -nm. $nX,$nR,$nr # Associate its new parameters.
  24.         -done
  25.         -nm[0] 0 # Disable recursion for the parent torus in next iterations
  26.       -endif
  27.     -endl -done
  28.   -done
  29.   -+3d # Add all 3d object togethers
  30.   -m3d 5 -db3d 0 -md3d -1 # Define reasonable rendering mode
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement