Advertisement
Guest User

gayag

a guest
Mar 29th, 2020
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.21 KB | None | 0 0
  1. void setup() {
  2.   size(450, 450,P2D);
  3.   rectMode(CENTER);
  4.   strokeCap(SQUARE);
  5.   noSmooth();
  6. }
  7. float wave=0;
  8. float tick=0;
  9. int seed = 69;
  10. void draw() {
  11.  
  12.   tick++;
  13.   background(0);
  14.   fill(255);
  15.  
  16.   randomSeed(seed);// fix the random
  17.   noStroke();
  18.   rect(width/2,height/2,400,400);
  19.   for (float x = 50; x<450; x+=50) {
  20.     for (float y = 50; y<450; y+=50) {
  21.       if (x > 150 && x < 300 && y > 150 && y < 300) {
  22.         continue; //skip this single loop run
  23.       }
  24.       pushMatrix();
  25.       translate(x, y);
  26.       module1(0, 0, 50, 50,wave-(dist(x,y,width/2,height/2)/width)*1.8);
  27.       popMatrix();
  28.     }
  29.   }
  30.  
  31.   wave=sin(tick*0.04)+1;// +1 so sin is always positive  E[0,2]
  32.   if(wave>=1.99){
  33.     seed++;
  34.   }
  35. }
  36.  
  37. void module1(float modx, float mody, float w, float h, float waveloc) {
  38.   //w and h to constrain the draw
  39.   //funky logic
  40.  
  41.   if(w<5){// prevents the recursion from going forever
  42.     return;
  43.   }
  44.  
  45.   float rRotate = random(0, 1);
  46.   float r1 = random(0, 1);
  47.   float r2 = random(0, 1);
  48.   float r3 = random(0, 1);
  49.   float awaveloc = constrain(waveloc*100/w,0,1); // lock to a value between 0 and 1
  50.   float inverseloc = 1-awaveloc;
  51.    //stroke(0,255,0);
  52.    //noFill();
  53.    //rect(0,0,50,50);
  54.    float rotateby=0;
  55.   if (rRotate<0.5) {
  56.     rotateby=PI/2;
  57.   }
  58.   if (rRotate>0.6) {
  59.     rotateby=PI;
  60.   }
  61.   rotate(rotateby);
  62.  
  63.   strokeWeight( max( 1 ,  min(w,h)*0.1   ) ); // lines get thinner as space is smaller, but not thinner then 1 pixel
  64.    
  65.   stroke(50);
  66.   if (r1<0.8) {
  67.     line(0, -h/2, 0, -h/2 + h*inverseloc);
  68.   }
  69.   //halfL
  70.   if (r2<0.6) {
  71.     line(-w*inverseloc/2f, 0, 0, 0);
  72.   }
  73.   //halfR
  74.   if (r3<0.7) {
  75.     line(0, -h/2, w*inverseloc/2f, -h/2);
  76.   }
  77.  
  78.   //yes were calling the function inside itself, to draw more of itself, but smaller.
  79.   if(random(r1+r2+r3)<1.5){
  80.     pushMatrix();
  81.     translate(-w/4, -h/4);
  82.     module1(modx/2, mody/2, w/2, h/2,waveloc-0.1) ;
  83.     translate(w/2, 0);
  84.     module1(modx/2, mody/2, w/2, h/2,waveloc-0.1) ;
  85.     translate(0, h/2);
  86.     module1(modx/2, mody/2, w/2, h/2,waveloc-0.3) ;
  87.     translate(-w/2, 0);
  88.     module1(modx/2, mody/2, w/2, h/2,waveloc-0.3) ;
  89.     popMatrix();
  90.   }
  91.   rotate(-rotateby);
  92.   strokeWeight(1);
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement