Skip to content

Instantly share code, notes, and snippets.

@tsulej
Created May 11, 2016 19:51
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 tsulej/a6909b2db99eba899b5fc4cdc13f2767 to your computer and use it in GitHub Desktop.
Save tsulej/a6909b2db99eba899b5fc4cdc13f2767 to your computer and use it in GitHub Desktop.
// draw by stripes
// http://generateme.tumblr.com
PImage img;
// decay length each iteration
final static float decay_ratio = 0.99;
// initial length of stripe, used also a time
float len = 50;
// final length
final static float final_len = 10;
// stripe alpha
final static float stripe_alpha = 180;
void setup() {
img = loadImage("w.jpg");
size(img.width, img.height);
smooth(8);
image(img,0,0);
}
void draw() {
for (int iter=0; iter<600-4*len; iter++) {
// initial stripe position
float x1 = random(width);
float x2 = x1 + (random(1)<0.5?-1:1) * random(5, 5+len);
float y1 = random(height);
float y2 = y1 + (random(1)<0.5?-1:1) * random(5, 5+len);
// stripe color
color initcolor = img.get((int)x1, (int)y1);
fill(initcolor, stripe_alpha);
stroke(255-brightness(initcolor),20);
// direction of the stripe (left/right)
float dir = random(1)<0.5?-1:1;
int i=0;
color currentcolor = initcolor;
beginShape(TRIANGLE_STRIP);
// finish stripe when brightness is changed or length reached
while(i<len+20 && colordist(initcolor,currentcolor)<len) {
vertex(x1, y1);
vertex(x2, y2);
// take current color info randomly modified
float b1 = 2*TWO_PI*(0.005*randomGaussian()+brightness( img.get((int)x1, (int)y1) )/255.0);
float b2 = 2*TWO_PI*(0.005*randomGaussian()+brightness( img.get((int)x2, (int)y2) )/255.0);
// always move horizontally and turn slightly
x1 += dir*random(5,5+len)+(b1*5)*cos(b1);
x2 += dir*random(5,5+len)+(b2*5)*cos(b2);
// turn
y1 += (b1*2)*sin(b1);
y2 += (b2*2)*sin(b2);
i++;
currentcolor = img.get((int)x1, (int)y1);
}
endShape();
}
if(len>final_len) len *= decay_ratio;
println(len);
}
float colordist(color c1, color c2) {
return abs(brightness(c1)-brightness(c2));
}
void mouseClicked() {
save("result"+hex((int)random(0xffff+1))+".jpg");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment