xxxxxxxxxx
71
let capture, picture, imgSize = 200
let pixelImg
let minPixelDistance = 5,
lastPixel
function preload() {
picture = loadImage('CMYK-TEST1.png');
}
function setup() {
createCanvas(800, 800);
pixelDensity(1);
frameRate(4)
picture.loadPixels()
processCMYK()
}
function processCMYK() {
initImages()
imageCMYK()
}
function initImages() {
pixelImg = createImage(picture.width, picture.height);
pixelImg.loadPixels()
}
function imageCMYK() {
console.log(`w:${picture.width} h: ${picture.height} p:${picture.pixels.length}`)
for (var y = 0; y < picture.height; y++) {
for (var x = 0; x < picture.width; x++) {
if (!lastPixel){
lastPixel = {
x,
y
}
}
if(int(dist(lastPixel.x, lastPixel.y, x, y))<minPixelDistance)
continue
lastPixel = {
x,
y
}
var i = (x + y * picture.width) * 4;
r = picture.pixels[i]
g = picture.pixels[i + 1]
b = picture.pixels[i + 2]
a = picture.pixels[i + 3]
//let d = int(dist(x1, y1, x2, y2));
if (brightness(color(r, g, b, a)) < 200) {
pixelImg.pixels[i] = r
pixelImg.pixels[i + 1] = g
pixelImg.pixels[i + 2] = b
pixelImg.pixels[i + 3] = a
}
}
}
// UpdatePixels of the images
pixelImg.updatePixels();
}
function draw() {
background(255)
if (picture) image(picture, 0, 0, imgSize * 2, imgSize * 2)
if (pixelImg) image(pixelImg, imgSize * 2, imgSize * 2, imgSize * 2, imgSize * 2)
}