Created
September 28, 2018 19:23
-
-
Save LadyScream/22aa7103ad39571ea948292200406de4 to your computer and use it in GitHub Desktop.
Procedural geometric shapes, inspired by: https://twitter.com/sasj_nl/status/1045340932424560641
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
ArrayList<Way> ways = new ArrayList<Way>(); | |
int cols = 10; | |
int rows = 10; | |
int gaps = 30; | |
void setup() { | |
size(600, 600, P3D); | |
float cw = (width-gaps*2)/cols; | |
float ch = (height-gaps*2)/rows; | |
for (int i = 0; i < cols; i++) { | |
for (int j = 0; j < rows; j++) { | |
ways.add(new Way(i*cw+gaps+cw/2, j*ch+gaps+ch/2, cw, ch, 1)); | |
} | |
} | |
noLoop(); | |
} | |
void draw() { | |
background(255, 200, 200); | |
for (Way w: ways) { | |
w.draw(); | |
} | |
save("test.png"); | |
} | |
class Way { | |
float x, y, w, h, gap; | |
int[][] colors = new int[4][3]; | |
int[][] c = { | |
{144, 76, 119}, | |
{207, 139, 169}, | |
{177, 94, 108}, | |
{149, 125, 149}, | |
{255, 200, 200}, | |
{255, 200, 200}, | |
{255, 200, 200}, | |
{255, 200, 200} | |
}; | |
Way(float xa, float ya, float wa, float ha, float gapa) { | |
x = xa; | |
y = ya; | |
w = wa; | |
h = ha; | |
gap = gapa; | |
for (int i = 0; i < 4; i++) { | |
int index = (int) random(c.length); | |
colors[i][0] = c[index][0]; | |
colors[i][1] = c[index][1]; | |
colors[i][2] = c[index][2]; | |
} | |
} | |
void draw() { | |
noStroke(); | |
for (int i = 0; i < 4; i++) { | |
pushMatrix(); | |
translate(x, y); | |
rotate(i*PI/2); | |
fill(colors[i][0], colors[i][1], colors[i][2]); | |
triangle(0, -gap, 0 - w/2 + gap, 0-h/2, 0 + w/2 - gap, 0-h/2); | |
popMatrix(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment