Skip to content

Instantly share code, notes, and snippets.

@jkwok91
Created April 25, 2014 11:10
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 jkwok91/d6671faebc07aae685ae to your computer and use it in GitHub Desktop.
Save jkwok91/d6671faebc07aae685ae to your computer and use it in GitHub Desktop.
patternmaker
/*
have the user drop a series of circles on the page
this is sort of a pattern creator.
*/
String mode;
int side;
ArrayList<PVector> placed;
ArrayList<PVector> repeat;
void setup() {
size(300, 300);
stroke(255);
mode = "drawing";
placed = new ArrayList<PVector>();
repeat = new ArrayList<PVector>();
side = 20;
}
void draw() {
background(0);
noFill();
stroke(255);
if (mode != "admire") {
for (PVector c : placed) {
ellipse(c.x, c.y, 10, 10);
}
if (mode == "selection") {
stroke(color(255, 0, 0));
rect(mouseX, mouseY, side, side);
}
}
if (mode == "admire") {
background(0);
for (int i = 60; i < height; i+=side) {
for (int j = 0; j < width; j+=side) {
pushMatrix();
translate(j, i);
stroke(255);
for (PVector c : repeat) {
ellipse(c.x, c.y, 10, 10);
}
popMatrix();
}
}
}
fill(color(255,255,0));
text("MODE: "+mode,0,20);
text("press spacebar to change mode",0,40);
text("click to draw/capture",0,50);
}
void mousePressed() {
PVector origin = new PVector(mouseX, mouseY);
if (mode == "drawing") {
placed.add(origin);
}
else if (mode == "selection") {
//clear the repeat area
repeat = new ArrayList<PVector>();
for (PVector c : placed) {
if ((c.x+5 > origin.x && c.x-5 < origin.x+side) &&
(c.y+5 > origin.y && c.y-5 < origin.y+side)) {
PVector newCoor = PVector.sub(c, origin);
repeat.add(newCoor);
}
}
}
}
void keyPressed() {
if (key == ' ') {
if (mode == "drawing") {
mode = "selection";
}
else if (mode == "selection") {
mode = "admire";
}
else {
mode = "drawing";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment