Skip to content

Instantly share code, notes, and snippets.

@jsundram
Created January 24, 2012 16:35
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 jsundram/1671003 to your computer and use it in GitHub Desktop.
Save jsundram/1671003 to your computer and use it in GitHub Desktop.
// code taken from here:
// http://www.analogpixel.org/blog/2011/09/13/msced-148-boxy-lady-take-2/#more-764
// and formatted for readability.
PImage pic1;
PGraphics pg;
boolean grow;
int box_size;
int MAXS = 40;
int MINS = 1;
void setup()
{
pic1 = loadImage("pic1.jpg");
pg = createGraphics(pic1.width, pic1.height, JAVA2D);
size(pic1.width, pic1.height);
noStroke();
grow = false;
box_size = MAXS;
}
void draw()
{
make(box_size);
if (!grow)
{
box_size--;
if (box_size < MINS)
grow = true;
}
if (grow)
{
box_size++;
if (MAXS < box_size)
{
grow = false;
exit();
}
}
}
void make(int i)
{
pic1.loadPixels();
pg.beginDraw();
pg.noStroke();
for (int cc=0; cc < (width*height)/2; cc++)
{
int x = int(random(0, width));
int y = int(random(0, height));
pg.fill(pic1.get(x, y));
pg.rect(x, y, int(random(MINS, i)), int(random(MINS, i)));
}
pg.endDraw();
image(pg, 0, 0);
saveFrame("ani/image###.png");
}
void keyPressed()
{
if ( key == 's')
saveFrame("images/image##.jpg");
}
@jsundram
Copy link
Author

jsundram commented Apr 6, 2013

Can easily make an animated gif from the results via ImageMagick on OSX:

convert -delay 2 -loop 0 *.png out.gif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment