xxxxxxxxxx
56
/**
* Genuary day #2
* Dithering
* ---
* No real dithering, but simple halftone
*/
let img;
let threshold = 127;
function preload() {
img = loadImage('kitten.png');
}
function setup() {
createCanvas(852, 568);
imageMode(CENTER);
strokeWeight(0);
imageMode(CENTER);
background(255);
//noStroke();
fill(0);
let lineLen = 10;
threshold = map(mouseY, 0, img.height, 0, 500);
displayByColor("K", 0, 7);
//displayByColor("C", 1, 5);
//displayByColor("M", 2, 4);
//displayByColor("J", 3, 3);
}
function displayByColor(col, shifting, maxSize) {
if (col == "K") fill(0);
else if (col == "R") fill(255, 0, 0);
else if (col == "G") fill(0, 255, 0);
else if (col == "B") fill(0, 0, 255);
else if (col == "C") fill(0, 255, 255);
else if (col == "M") fill(255, 0, 255);
else if (col == "J") fill(255, 255, 0);
let c = 255;
for (let i = shifting; i < img.width; i+=6) {
for (let j = shifting; j < img.height; j+=6) {
if (col == "K") c = brightness(img.get(i, j));
else if (col == "R") c = red(img.get(i, j));
else if (col == "G") c = green(img.get(i, j));
else if (col == "B") c = blue(img.get(i, j));
else if (col == "C") c = (blue(img.get(i, j)) + green(img.get(i, j)) ) /2;
else if (col == "M") c = (blue(img.get(i, j)) + red(img.get(i, j)) ) /2;
else if (col == "J") c = (red(img.get(i, j)) + green(img.get(i, j)) ) /2;
let size = map(c, 0, 255, maxSize, 0);
circle(i-size/2, j-size/2, size);
}
}
}