Advertisement
Guest User

3D Repulsive Particle System [G'MIC]

a guest
Apr 4th, 2020
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.49 KB | None | 0 0
  1. # A G'MIC implementation of a system of 3D repulsive particules
  2. # (Author: David Tschumperlé, April 2020).
  3. #-----------------------------------------------------------------
  4. particles3d :
  5.   512,512,1,3
  6.   1,900,1,3,u(w#-1-1)
  7.  
  8.   t=0
  9.   do
  10.     xrep,yrep,zrep={w#0*(0.5+0.3*[cos(4.2*$t),sin(2.7*$t),cos(1.9*$t)])}
  11.     t+=0.01
  12.  
  13.     # Render particles.
  14.     N=$!
  15.     repeat h circle3d {"I[#1,"$>"]"},4 done
  16.     +3d[$N--1] col3d. 255 o3d. 0.75
  17.     circle3d $xrep,$yrep,$zrep,20 col3d. 255,0,0
  18.     +3d[-2,-1]
  19.     box3d 512,512,512 p3d. 1 o3d. 0.4 +3d[-2,-1]
  20.  
  21.     -3d. {0,[w,w,w]/2} r3d. 1,1,0,34 #r3d. 0,1,0,{80*$t}
  22.     f3d 400
  23.     +f[0] 0 j3d. ..,50%,50%,150,1,2
  24.     *[0] 'd=y/h;[0.24+0.75*d,0.92,0.99-0.3*d]' max[0,-1]
  25.     rm. w[0]
  26.  
  27.     # Compute and apply particle velocity.
  28.     +. '"*
  29.      add_veloc(Q,strength,sigma) = (
  30.        U = P - Q;
  31.        nU = norm(U);
  32.        U/=max(1e-5,nU);
  33.        w = strength*(sigma>0?gauss(nU,sigma,0):1/(1e-5+nU));
  34.        sumw+=w;
  35.        V+=w*U;
  36.      );
  37.  
  38.      P = I(#1);
  39.      V = [ 0,0,0 ];
  40.      sumw = 0;
  41.  
  42.      for (p = 0, p<h, ++p, p!=y?add_veloc(I[#1,p],5,20));
  43.  
  44.      const W = w#0-1;
  45.  
  46.      add_veloc([0,P[1],P[2]],10,0);
  47.      add_veloc([P[0],0,P[2]],10,0);
  48.      add_veloc([P[0],P[1],0],10,0);
  49.      add_veloc([W,P[1],P[2]],10,0);
  50.      add_veloc([P[0],W,P[2]],10,0);
  51.      add_veloc([P[0],P[1],W],10,0);
  52.  
  53.      add_veloc(["$xrep,$yrep,$zrep"],50,70);
  54.      2.8*V/sumw"'
  55.     wait 30
  56.  
  57.   while {*}" && "!{*,ESC}
  58.   rm w[] 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement