Created
January 24, 2012 16:35
-
-
Save jsundram/1671003 to your computer and use it in GitHub Desktop.
Formatted code from analogpixel: http://www.analogpixel.org/blog/2011/09/13/msced-148-boxy-lady-take-2/#more-764
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
// 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"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can easily make an animated gif from the results via ImageMagick on OSX:
convert -delay 2 -loop 0 *.png out.gif