Created
January 27, 2020 13:59
-
-
Save raunaqsingh2020/76983609018dd33607ec051fba4ccc51 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
float theta; | |
void setup() { | |
size(750, 750); | |
//strokeWeight(1); | |
//noStroke(); | |
//fill(0,45); | |
} | |
void draw() { | |
background(255); | |
drawPattern(0, 0, width/2, 2); | |
drawCircle(0, 0, width, 2);// change last argument to 1 for more detail | |
theta = map(mouseX,0,width,0,PI/2); | |
translate(width/2, height); | |
//stroke(0); | |
branch(75); | |
} | |
void drawPattern(float x, float y, float squareSize, float minSize) { | |
stroke(0,0,0); | |
strokeWeight(1); | |
fill(random(1, 255), random(1, 255), random(1, 255)); | |
rect(x, y, squareSize, squareSize); | |
rect(x+squareSize, y, squareSize, squareSize); | |
rect(x, y+squareSize, squareSize, squareSize); | |
if (squareSize > minSize) { | |
drawPattern(x, y, squareSize/2, minSize); | |
drawPattern(x+squareSize, y, squareSize/2, minSize); | |
drawPattern(x, y+squareSize, squareSize/2, minSize); | |
} | |
} | |
void drawCircle(float x, float y, float squareSize, float minSize) { | |
stroke(0,0,0); | |
strokeWeight(1); | |
fill(random(1, 255), random(1, 255), random(1, 255)); | |
ellipse(x, y, squareSize, squareSize); | |
ellipse(x+squareSize, y, squareSize, squareSize); | |
ellipse(x, y+squareSize, squareSize, squareSize); | |
if (squareSize > minSize) { | |
drawCircle(x, y, squareSize/2, minSize); | |
drawCircle(x+squareSize, y, squareSize/2, minSize); | |
drawCircle(x, y+squareSize, squareSize/2, minSize); | |
} | |
} | |
void branch(float len) { | |
float theta = random(0,PI/3); | |
stroke(random(0,255), random(0,255), random(0,255)); | |
strokeWeight(10); | |
line(0, 0, 0, -len); | |
translate(0, -len); | |
len *= 0.75; | |
if (len > 2) { | |
pushMatrix(); | |
rotate(theta); | |
branch(len); | |
popMatrix(); | |
pushMatrix(); | |
rotate(-theta); | |
branch(len); | |
popMatrix(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment