Skip to content

Instantly share code, notes, and snippets.

@bready90
Last active August 31, 2017 01:21
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save bready90/67e41099fd2b686ca03976935d902e20 to your computer and use it in GitHub Desktop.
make some squares boi
/*
Draws a set number of overlapping squares in one place.
Squares can be randomly distorted as desired.
Each square is a random pastel colour (or white)
Not suitable for animation.
Usage:
squares(x, y, count, size, variation);
Parameters:
x = position of the top left corner of the square along the x-axis
y = position of the top left corner of the square along the y-axis
count = the number of squares
size = the size of the squares in pixels
variation = amount of distortion applied to the square in pixels. Set to 0 for no variation
Example:
squares(10, 10, 10, 50, 5);
10 squares at position 10, 10, each 10x10 pixels and slightly distorted
NOTE: Variation is always random, the variable just defines the upper limit of the random number.
DOUBLE NOTE: Not actually a proper square if you distort it I guess but hey.
*/
void squares(float x, float y, float count, float size, float variation) {
noFill(); //so you can see the squares, duh
for (int i = 0; i < count; i++) { //repeats for as long as defined by "count"
stroke(random(150,255), random(150,255), random(150,255)); //sets the stroke to a random pastel colour (or white)
//draws the actual square (woah)
beginShape();
vertex(x + random(variation),y + random(variation)); //first point
vertex(x + size + random(variation), y + random(variation)); //second point
vertex(x + size + random(variation), y + size + random(variation)); //third point
vertex(x + random(variation), y + size + random(variation)); //fourth point
endShape(CLOSE);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment