Skip to content

Instantly share code, notes, and snippets.

@wonderburg7
Last active September 16, 2018 12:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wonderburg7/4a51019489520abc917e47b56157b219 to your computer and use it in GitHub Desktop.
Save wonderburg7/4a51019489520abc917e47b56157b219 to your computer and use it in GitHub Desktop.
int gridpoints = 10;
int height = 4000;
int width = 4000;
int distance = (height/gridpoints);
int x = distance;
int y = distance;
int size = 250;
void setup() {
size(4000, 4000);
background(246, 237, 219);
ellipseMode(CENTER);
rectMode(CENTER);
noStroke();
noLoop();
}
void draw() {
for (int j = 0; j < gridpoints-1; j++){
for (int i = 0; i < gridpoints-1; i++){
fill(int(random(255)), int(random(160, 200)), int(random(120, 180)), int(random(120, 220)));
float coin = random(0,1);
float offsetx = x - (size*0.5);
float offsety = y + (tan(30)+(size*0.5));
if (coin < 0.333){
triangleSimple(offsetx, offsety, size, (sqrt((size*size)-((size*0.5)*(size*0.5)))));
}
else if (coin < 0.666) {
rect(x,y, size, size);
}
else {
ellipse(x, y, size, size);
}
x += distance;
}
x = distance;
y = y + distance;
}
save("shape grid1.png");
}
void polygon(float x, float y, float radius, int npoints) {
float angle = TWO_PI / npoints;
beginShape();
for (float a = 0; a < TWO_PI; a += angle) {
float sx = x + cos(a) * radius;
float sy = y + sin(a) * radius;
vertex(sx, sy);
}
endShape(CLOSE);
}
void triangleSimple(float x, float y, float w, float h){
// A wrapper for standard triangle() command.
// triangleSimple has the lower left corner as x,y
triangle(x,y,
x+w/2, y-h,
x+w, y);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment