Chris_M_Thomasson

Alien Code: First Try in Processing...

Aug 13th, 2017
801
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.79 KB | None | 0 0
  1. /*
  2. Alien Code?
  3. First try by: Chris M. Thomasson
  4. ____________________________________________________*/
  5. float g_pradius = 200;
  6.  
  7.  
  8. void setup()
  9. {
  10.   size(800, 800);
  11.   noFill();
  12.   noLoop();
  13.   background(0);
  14.   colorMode(RGB, 255);
  15.   translate(width / 2, height / 2);
  16.   ct_alien_code_render(0, 2, 0, 0, 100);
  17.   saveFrame("ct_alien_code.jpg");
  18. }
  19.  
  20.  
  21. void ct_alien_code_render(
  22.   int irecur,
  23.   int irecur_max,
  24.   float ox,
  25.   float oy,
  26.   int imax
  27. ) {
  28.   if (irecur >= irecur_max) return;
  29.  
  30.   float angle_start =  1 / (imax - 1.0) * (PI*2);
  31.  
  32.   float ptx = 1;
  33.   float pty = 0;
  34.  
  35.   float ptx_x = (cos(angle_start) + floor(sin(angle_start)) * 2 + 1) * .5;
  36.   float ptx_y = sin(angle_start) * .5;
  37.  
  38.   float dif_x = ptx_x - ptx;
  39.   float dif_y = ptx_y - pty;
  40.  
  41.   float dis = abs(dif_x * dif_x + dif_y * dif_y);
  42.  
  43.   for (int i = 1; i < imax; ++i)
  44.   {
  45.     float ir = i / (imax - 1.0);
  46.     float angle = (PI*2) * ir;
  47.    
  48.     float np_x = (cos(angle) + floor(sin(angle)) * 2 + 1) * .5;
  49.     float np_y = (sin(angle)) * .5;
  50.    
  51.     np_x += ox;
  52.     np_y += oy;
  53.    
  54.     float dif_np_x = np_x - ptx;
  55.     float dif_np_y = np_y - pty;
  56.     float ddd = abs(dif_np_x * dif_np_x + dif_np_y * dif_np_y);
  57.    
  58.     if (ddd <= dis && i > 1)
  59.     {
  60.       // line  in.plot.line(pt, np, CT_RGBF(0, 1, 1));
  61.      
  62.       float proj_pt_x = ptx * g_pradius;
  63.       float proj_pt_y = -pty * g_pradius;
  64.      
  65.       float proj_np_x = np_x * g_pradius;
  66.       float proj_np_y = -np_y * g_pradius;
  67.      
  68.       stroke(255, 255, 0);
  69.       line(proj_pt_x, proj_pt_y, proj_np_x, proj_np_y);
  70.      
  71.       stroke(255, 0, 0);
  72.       line(-proj_pt_x, -proj_pt_y, -proj_np_x, -proj_np_y);
  73.     }
  74.    
  75.     ct_alien_code_render(irecur + 1, irecur_max, np_x, np_y, imax);
  76.    
  77.     ptx = np_x;
  78.     pty = np_y;
  79.   }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment