Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void setup() {
- size(450, 450,P2D);
- rectMode(CENTER);
- strokeCap(SQUARE);
- noSmooth();
- }
- float wave=0;
- float tick=0;
- int seed = 69;
- void draw() {
- tick++;
- background(0);
- fill(255);
- randomSeed(seed);// fix the random
- noStroke();
- rect(width/2,height/2,400,400);
- for (float x = 50; x<450; x+=50) {
- for (float y = 50; y<450; y+=50) {
- if (x > 150 && x < 300 && y > 150 && y < 300) {
- continue; //skip this single loop run
- }
- pushMatrix();
- translate(x, y);
- module1(0, 0, 50, 50,wave-(dist(x,y,width/2,height/2)/width)*1.8);
- popMatrix();
- }
- }
- wave=sin(tick*0.04)+1;// +1 so sin is always positive E[0,2]
- if(wave>=1.99){
- seed++;
- }
- }
- void module1(float modx, float mody, float w, float h, float waveloc) {
- //w and h to constrain the draw
- //funky logic
- if(w<5){// prevents the recursion from going forever
- return;
- }
- float rRotate = random(0, 1);
- float r1 = random(0, 1);
- float r2 = random(0, 1);
- float r3 = random(0, 1);
- float awaveloc = constrain(waveloc*100/w,0,1); // lock to a value between 0 and 1
- float inverseloc = 1-awaveloc;
- //stroke(0,255,0);
- //noFill();
- //rect(0,0,50,50);
- float rotateby=0;
- if (rRotate<0.5) {
- rotateby=PI/2;
- }
- if (rRotate>0.6) {
- rotateby=PI;
- }
- rotate(rotateby);
- strokeWeight( max( 1 , min(w,h)*0.1 ) ); // lines get thinner as space is smaller, but not thinner then 1 pixel
- stroke(50);
- if (r1<0.8) {
- line(0, -h/2, 0, -h/2 + h*inverseloc);
- }
- //halfL
- if (r2<0.6) {
- line(-w*inverseloc/2f, 0, 0, 0);
- }
- //halfR
- if (r3<0.7) {
- line(0, -h/2, w*inverseloc/2f, -h/2);
- }
- //yes were calling the function inside itself, to draw more of itself, but smaller.
- if(random(r1+r2+r3)<1.5){
- pushMatrix();
- translate(-w/4, -h/4);
- module1(modx/2, mody/2, w/2, h/2,waveloc-0.1) ;
- translate(w/2, 0);
- module1(modx/2, mody/2, w/2, h/2,waveloc-0.1) ;
- translate(0, h/2);
- module1(modx/2, mody/2, w/2, h/2,waveloc-0.3) ;
- translate(-w/2, 0);
- module1(modx/2, mody/2, w/2, h/2,waveloc-0.3) ;
- popMatrix();
- }
- rotate(-rotateby);
- strokeWeight(1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement