Hello!
I’m a beginner at coding and making art through technology.
I watch the coding train to learn but I also like to experiment with existing code made by the community.
Here, I wanted to make art, and Generate_me does exactly that, it’s a sort of compilation of codes altering images you give them, in an glitch/artsy way.
But it’s kinda bugged:
The save thing doesn’t stop at 30 iterations + In my experience I think it saved every iterations.
But now it just doesn’t work at all anymore, seems like it can’t get the image in? I don’t know.
I just get this:
It seems to have the size of the image I gave it, so it does receive that, but yeah… It’s not the image I gave it
Which is this:
And it should give something like this:
And here is the code!
// Original: http://www.openprocessing.org/sketch/145401
// adaptation to images, Tomasz Sulej, generateme.blog@gmail.com
// Licence CC-BY-SA 3.0
// put image filename here:
String filename = "test";
String fileext = ".jpg";
String foldername = "/";
// choose channel
int channel = SATURATION;
// run, after 30 iterations result will be saved automatically
// or press SPACE
int max_display_size = 800; // viewing window size (regardless image size)
/////////////////////////////////////
// channels to work with
final static int RED = 0;
final static int GREEN = 1;
final static int BLUE = 2;
final static int HUE = 3;
final static int SATURATION = 4;
final static int BRIGHTNESS = 5;
final static int NRED = 6;
final static int NGREEN = 7;
final static int NBLUE = 8;
final static int NHUE = 9;
final static int NSATURATION = 10;
final static int NBRIGHTNESS = 11;
int n=2000;
float [] cx=new float[n];
float [] cy=new float[n];
PImage img;
int len;
// working buffer
PGraphics buffer;
String sessionid;
void setup() {
sessionid = hex((int)random(0xffff),4);
img = loadImage(foldername+filename+fileext);
buffer = createGraphics(img.width, img.height);
buffer.smooth(8);
buffer.beginDraw();
buffer.noFill();
buffer.strokeWeight(0.3);
buffer.background(0);
buffer.endDraw();
// calculate window size
float ratio = (float)img.width/(float)img.height;
int neww, newh;
if(ratio < 1.0) {
neww = (int)(max_display_size * ratio);
newh = max_display_size;
} else {
neww = max_display_size;
newh = (int)(max_display_size / ratio);
}
surface.setSize(neww,newh);
len = (img.width<img.height?img.width:img.height)/6;
background(0);
for (int i=0;i<n;i++) {
cx[i]=random(img.width);
cy[i]=random(img.height);
}
}
int tick = 0;
void draw() {
buffer.beginDraw();
for (int i=1;i<n;i++) {
color c = img.get((int)cx[i], (int)cy[i]);
buffer.stroke(c);
buffer.point(cx[i], cy[i]);
// you can choose channels: red(c), blue(c), green(c), hue(c), saturation(c) or brightness(c)
cy[i]+=sin(map(getChannel(c),0,255,0,TWO_PI));
cx[i]+=cos(map(getChannel(c),0,255,0,TWO_PI));
}
if (frameCount>len) {
frameCount=0;
println("iteration: " + tick++);
for (int i=0;i<n;i++) {
cx[i]=random(img.width);
cy[i]=random(img.height);
}
}
buffer.endDraw();
if (tick == 30) keyPressed();
image(buffer,0,0,width,height);
}
float getChannel(color c) {
int ch = channel>5?channel-6:channel;
float cc;
switch(ch) {
case RED: cc = red(c); break;
case GREEN: cc = green(c); break;
case BLUE: cc = blue(c); break;
case HUE: cc = hue(c); break;
case SATURATION: cc = saturation(c); break;
default: cc= brightness(c); break;
}
return channel>5?255-cc:cc;
}
void keyPressed() {
buffer.save(foldername + filename + "/res_" + sessionid +"_"+filename+fileext);
println("image saved");
}
Thanks for reading and even more if you answer and help!
Have a nice day.