I have been fighting with some python code I found on the web, and I dont get it. How can I do this in Processing / Java ?
Interesting webpage with super ideas:
There is a nice kind of step sorting, that kind of does the job best.
python code from Alan Zucconi:
def step (r,g,b, repetitions=1):
lum = math.sqrt( .241 * r + .691 * g + .068 * b )
h, s, v = colorsys.rgb_to_hsv(r,g,b)
h2 = int(h * repetitions)
lum2 = int(lum * repetitions)
v2 = int(v * repetitions)
return (h2, lum, v2)
colours.sort(key=lambda (r,g,b): step(r,g,b,8) )
This is what I have in Processing so far:
color [] colours = new color[1000];
float lum;
int repetitions = 0;
void setup() {
size(1024, 500);
// pick 1000 random color and put in array
for (int i=0; i<colours.length; i++) {
colours[i]= color(random(255), random(255), random(255));
}
printBar(0);
//simple rgb sort
colours = sort(colours);
printBar(50);
// step sort
for (int j=0; j<colours.length; j++) {
lum = sqrt(.241 * red(colours[j]) + .691 * green(colours[j]) + .068 * blue(colours[j]));
int h2 = int(hue(colours[j]) * repetitions);
int lum2 = int(lum * repetitions);
int v2 = int(brightness(colours[j]) * repetitions);
//I am stuck.......
}
printBar(100);
}
void draw() {
}
void printBar(int step) {
//show all the random colors in a bar
for (int j=0; j<colours.length; j++) {
//strokeWeight(2);
stroke(colours[j]);
line(j+5, 20+step, j+5, 50+step);
}
}
Can this code be converted to Java / Processing ? Looks like the variable repititions is an other loop from 0 to 7 ? I dont get it. I need help.