mirror of
https://github.com/tsulej/GenerateMe.git
synced 2026-02-06 10:39:39 +01:00
124 lines
2.9 KiB
Plaintext
Executable File
124 lines
2.9 KiB
Plaintext
Executable File
// Template for processing scripts
|
|
// Tomasz Sulej, generateme.blog@gmail.com, http://generateme.tumblr.com
|
|
// Licence: http://unlicense.org/
|
|
|
|
// Usage:
|
|
// * press SPACE to save
|
|
|
|
// set up filename
|
|
String filename = "test";
|
|
String fileext = ".jpg";
|
|
String foldername = "./";
|
|
|
|
int max_display_size = 1000; // viewing window size (regardless image size)
|
|
|
|
boolean do_blend = false; // blend image after process
|
|
int blend_mode = OVERLAY; // blend type
|
|
|
|
// working buffer
|
|
PGraphics buffer;
|
|
|
|
// image
|
|
PImage img;
|
|
|
|
String sessionid;
|
|
|
|
void setup() {
|
|
sessionid = hex((int)random(0xffff),4);
|
|
img = loadImage(foldername+filename+fileext);
|
|
|
|
buffer = createGraphics(img.width, img.height);
|
|
buffer.beginDraw();
|
|
buffer.noStroke();
|
|
buffer.smooth(8);
|
|
buffer.background(0);
|
|
buffer.image(img,0,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);
|
|
}
|
|
|
|
size(neww,newh);
|
|
|
|
processImage();
|
|
}
|
|
|
|
void draw() {
|
|
// fill for iterative processing
|
|
}
|
|
|
|
void processImage() {
|
|
buffer.beginDraw();
|
|
|
|
// START CODE HERE! use buffer to draw/manipulate
|
|
|
|
for(int x=0;x<buffer.width;x++) {
|
|
for(int y=0;y<buffer.height;y++) {
|
|
//swap hsb <> rgb
|
|
color c = img.get(x,y);
|
|
buffer.fill( hue(c), saturation(c), brightness(c) );
|
|
buffer.rect(x,y,1,1);
|
|
}
|
|
}
|
|
|
|
// END CODE HERE!
|
|
|
|
if(do_blend)
|
|
buffer.blend(img,0,0,img.width,img.height,0,0,buffer.width,buffer.height,blend_mode);
|
|
|
|
buffer.endDraw();
|
|
image(buffer,0,0,width,height);
|
|
}
|
|
|
|
void keyPressed() {
|
|
// SPACE to save
|
|
if(keyCode == 32) {
|
|
String fn = foldername + filename + "/res_" + sessionid + hex((int)random(0xffff),4)+"_"+filename+fileext;
|
|
buffer.save(fn);
|
|
println("Image "+ fn + " saved");
|
|
}
|
|
}
|
|
|
|
//
|
|
|
|
final static int[] blends = {ADD, SUBTRACT, DARKEST, LIGHTEST, DIFFERENCE, EXCLUSION, MULTIPLY, SCREEN, OVERLAY, HARD_LIGHT, SOFT_LIGHT, DODGE, BURN};
|
|
|
|
// ALL Channels, Nxxx stand for negative (255-value)
|
|
// 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;
|
|
|
|
float getChannel(color c, int channel) {
|
|
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;
|
|
}
|