Skip to content

Instantly share code, notes, and snippets.

@edmorais edmorais/Pattern_Gen.pde
Last active Aug 29, 2015

Embed
What would you like to do?
Basic generator script that I use to make the source images for some pattern artwork. I usually run this a few times (sometimes a lot) until an image catches my eye. And of course, I'm constantly fiddling with it.
// inits
size(900,900);
background(0);
color[] cols = new color[5];
// config vars
cols[0] = color(#8E2800); // background
cols[1] = color(#B64926);
cols[2] = color(#FFB03B);
cols[3] = color(#FFF0A5);
cols[4] = color(#468966);
int s = 120; // cell size
int sratio = 4; // foreground ratio
PGraphics im = createGraphics(6000, 6000); // width, height
int num = 10; // number of images to generate
String name = "earthtones";
// begin
im.beginDraw();
im.background(cols[0]);
im.strokeWeight(s/sratio);
im.smooth();
// draw pattern
for (int iy = 0; iy < im.height; iy += s) {
im.stroke(cols[int(random(1,5))]);
for (int ix = 0; ix < im.width; ix += s) {
int r = int(random(0,100));
if (r < 35) {
im.line(ix,iy+s,ix+s,iy);
} else if (r < 70) {
im.line(ix,iy,ix+s,iy+s);
} else if (r < 85) {
im.line(ix,iy+s/2,ix+s,iy+s/2);
} else {
im.line(ix+s/2,iy,ix+s/2,iy+s);
}
}
}
// save
im.endDraw();
// Display image
if (im.width > im.height) {
image(im, 0, (height-height*float(im.height)/float(im.width))/2, width, height*(float(im.height)/float(im.width)));
} else {
image(im, (width-width*float(im.width)/float(im.height))/2, 0, width*(float(im.width)/float(im.height)), height);
}
im.save(name+"_"+im.width+"x"+im.height+".jpg");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.