Skip to content

Instantly share code, notes, and snippets.

@yumu19
Created February 28, 2015 09:24
Show Gist options
  • Save yumu19/ea8fa071e6584062c57b to your computer and use it in GitHub Desktop.
Save yumu19/ea8fa071e6584062c57b to your computer and use it in GitHub Desktop.
change color of dress (need dress.png file)
import controlP5.*;
ControlP5 ctls;
PImage img;
float bg_hue = 40.0;
float bg_sat = 0.1;
float bg_bri = 1.0;
float dress_hue = 0;
float dress_sat = 0.0;
float dress_bri = 0.0;
color bg;
void setup() {
size(400, 800);
colorMode(HSB, 255, 1.0, 1.0);
prepareControlers();
}
void draw() {
bg = color(bg_hue,bg_sat,bg_bri);
img = loadImage("dress.png");
img.loadPixels();
for (int y = 0; y < img.height; y++)
{
for (int x = 0; x < img.width; x++)
{
int index = y * img.width + x;
int pixel = img.pixels[index];
float value = brightness(pixel);
float h = hue(pixel)+dress_hue;
if (h > 255) {
h = h - 255;
}
float s = saturation(pixel)+dress_sat;
float b = brightness(pixel)+dress_bri;
if (saturation(pixel) > 0.001) {
img.pixels[index] = color(h,s,b);
} else {
img.pixels[index] = bg;
}
}
}
img.updatePixels();
background(bg);
image(img, 0, 0);
}
void prepareControlers() {
ctls = new ControlP5(this);
ctls.setColorBackground (0xdd666666);
ctls.setColorForeground (0xdd888888);
ctls.setColorActive (0xeecccccc);
ControllerGroup g = ctls.addGroup("Controls",0,650);
ctls.addSlider("bg_hue", 0,255, 180, 10, 10, 320,16).setGroup(g);
ctls.addSlider("bg_sat", 0,1.0, 0.5, 10, 30, 320,16).setGroup(g);
ctls.addSlider("bg_bri", 0,1.0, 0.5, 10, 50, 320,16).setGroup(g);
ctls.addSlider("dress_hue",0,255, 0.0, 10, 80, 320,16).setGroup(g);
ctls.addSlider("dress_sat",-0.5,0.5,0, 10,100, 320,16).setGroup(g);
ctls.addSlider("dress_bri",-0.5,0.5,0, 10,120, 320,16).setGroup(g);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment