Created
December 8, 2017 14:11
-
-
Save fiskurgit/53a7792a60f85f323557e5cc8fe43723 to your computer and use it in GitHub Desktop.
This file contains 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
int[] xAnchors = new int[4]; | |
int[] yAnchors = new int[4]; | |
int columns = 12; | |
int rows = 8; | |
int columnWidth; | |
int rowHeight; | |
int frameSize = 40; | |
ArrayList shapes = new ArrayList(); | |
void setup(){ | |
size(900, 600, P3D); | |
columnWidth = (width - frameSize)/columns; | |
rowHeight = (height - frameSize)/rows; | |
generate(); | |
} | |
void generate(){ | |
shapes.clear(); | |
for(int c = 0 ; c < columns ; c++){ | |
for(int r = 0 ; r < rows ; r++){ | |
shapes.add(makeShape()); | |
} | |
} | |
} | |
PShape makeShape(){ | |
xAnchors[0] = (int)random(columnWidth/2); | |
xAnchors[1] = (int)random(columnWidth/2) + columnWidth/2; | |
xAnchors[2] = (int)random(columnWidth/2) + columnWidth/2; | |
xAnchors[3] = (int)random(columnWidth/2); | |
yAnchors[0] = rowHeight/2 + (int) random(rowHeight/8, -(rowHeight/8)); | |
yAnchors[1] = (int)random(rowHeight/2); | |
yAnchors[2] = rowHeight/2 + (int) random(rowHeight/8, -(rowHeight/8)); | |
yAnchors[3] = (int)random(rowHeight/2) + rowHeight/2; | |
PShape shape = createShape(); | |
shape.beginShape(); | |
shape.stroke(50); | |
shape.noFill(); | |
shape.vertex(xAnchors[0], yAnchors[0]); | |
shape.bezierVertex(xAnchors[0], yAnchors[0], xAnchors[1], yAnchors[1], xAnchors[2], yAnchors[2]); | |
shape.stroke(100); | |
shape.bezierVertex(xAnchors[2], yAnchors[2], xAnchors[3], yAnchors[3], xAnchors[0], yAnchors[0]); | |
shape.endShape(); | |
return shape; | |
} | |
void draw(){ | |
background(#e0ded5); | |
int index = 0; | |
for(int c = 0 ; c < columns ; c++){ | |
for(int r = 0 ; r < rows ; r++){ | |
PShape aShape = (PShape)shapes.get(index); | |
shape(aShape, frameSize/2 + columnWidth * c , frameSize/2 + rowHeight * r); | |
index++; | |
} | |
} | |
noLoop(); | |
} | |
void mousePressed(){ | |
generate(); | |
loop(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment