xxxxxxxxxx
56
var worldImage;
function preload() {
worldImage = loadImage("Test_img.png");
}
function setup() {
noLoop();
createCanvas(500, 500);
background(0,0,0,0);
brightness_to_op(worldImage);
}
function draw() {
loop();
log_color();
}
function brightness_to_op(worldImage){
for (var y = 0; y < worldImage.height; y++) {
for (var x = 0; x < worldImage.width; x++) {
var in_color = worldImage.get(x, y);
//get red,green, blue channels
var r = red(in_color);
var g = green(in_color);
var b = blue(in_color);
//
var l = round(((0.3 * r) + (0.59 * g) + (0.11 * b)));
var out_color;
out_color = color(0, 0, 0, 255-l);
worldImage.set(x, y, out_color);
}
}
worldImage.updatePixels();
noSmooth();
image(worldImage, 0, 0, width, height);
noLoop();
}
function keyTyped() {
if (key === 's') {
worldImage.save('photo', 'png');
}
}
function log_color(){
console.log("at this point the alpha is", get(mouseX,mouseY));
}