Skip to content

Instantly share code, notes, and snippets.

@u-ndefine
Last active April 25, 2024 12:07
Show Gist options
  • Star 51 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save u-ndefine/8e4bc21be4275f87fefe7b2a68487161 to your computer and use it in GitHub Desktop.
Save u-ndefine/8e4bc21be4275f87fefe7b2a68487161 to your computer and use it in GitHub Desktop.
Sketch of my generative art, "50 Lines"
float decel(float x) { // as an easing function
return 1-(x-1)*(x-1);
}
void setup() {
background(255);
size(750,750,P2D);
PImage img = loadImage("image.png");
strokeWeight(2);
noFill();
for(float y=0.0;y<50;y++) {
float l = 0;
beginShape(LINES);
for(float x=0;x<width*4;x++) {
float xx=x/4.0;
// using this version will generate a squished image due to using map(...) in line 26
// color c = img.get(int(xx),int(y*height/50.0));
color c = img.get(int(xx),int(map(y*height/50.0,0,height,50,height-50)));
l += (255-red(c))/255/4.0; // period of the wave
// 5*decel(m) sets the amplitude of the wave
// map(...) sets the position of the wave
float m = (255-red(c))/255.0; // separate it from an increasing variable (l)
vertex(xx,map((y+0.5)*height/50.0,0,height,50,height-50)+sin(l*PI/2.0)*5*decel(m));
}
endShape();
}
saveFrame("image-edit.png");
}
@Loskir
Copy link

Loskir commented Apr 26, 2020

Nice script! I've made web version of this using canvas: https://loskir.github.io/50-lines

@amantay-a
Copy link

amantay-a commented Apr 27, 2020

@kill-your-soul
Copy link

Hi, awesome script. I've made Telegram bot version on python
https://github.com/kill-your-soul/50_lines

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