Skip to content

Instantly share code, notes, and snippets.

@bogoreh
Last active March 2, 2021 14:39
Show Gist options
  • Save bogoreh/7268cee359afa05f369adcc4fb8557af to your computer and use it in GitHub Desktop.
Save bogoreh/7268cee359afa05f369adcc4fb8557af to your computer and use it in GitHub Desktop.
var drawShape = function(x, y, radius) {
//randomized variable to decide what shape
var r = random(1);
//randomizing all three colour variables
var red = floor(random(0, 255));
var blue = floor(random(0, 255));
var green = floor(random(0, 255));
//creating random colours
fill(red-radius, green+radius, blue+radius);
//if random number is less than 0.5, draw ellipses
if (r < 0.5){
ellipse(radius, radius, radius, radius);
ellipse(width-radius, radius, radius, radius);
}
//else if the random number is greater than 0.5, draw rectangles
else if (r >= 0.5){
rect(radius, radius, radius, radius);
rect(width-radius, radius, radius, radius);
}
//new radius variable so that it decreases each time
var newRadius = radius/2;
if (newRadius >= 2) {
drawShape(x-20, y, newRadius);
drawShape(x+20, y, newRadius);
}
};
//calling drawShape function
drawShape(width/2, height/2, 400);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment