xxxxxxxxxx
90
let img;
const SIZES = 5;
let colorArrays = []
let halfRes = []
function preload(){
img = loadImage("sargent.jpg")
}
function setup() {
rectMode(CENTER);
img.loadPixels();
for(let i=0;i<SIZES;i++){
colorArrays.push([])
let size = 2 ** i
for(let x=0;x<img.width/size;x++){
colorArrays[i].push([])
for(let y=0;y<img.height/size;y++){
let r = 0;
let g = 0;
let b = 0;
for(let j=0; j<size; j++){
for(let k=0; k<size; k++){
let index = ( (y + j - 1) * img.width + (x + k - 1) ) * 4 * size;
r += img.pixels[index];
g += img.pixels[index + 1];
b += img.pixels[index + 2];
}
}
if(isNaN(r)){
print('fuck')
}
r = floor(r/(size * size))
g = floor(g/(size * size))
b = floor(b/(size * size))
colorArrays[i][x].push("rgb(" + r + "," + g + "," + b + ")")
}
}
}
createCanvas(img.width, img.height);
// image(img,0,0)
print(colorArrays)
noCursor()
}
function draw() {
// background(220);
// tint(255, 10);
// image(img,0,0,width,height)
tint(255,255)
noStroke()
for(let i=0; i<1000; i++){
let coord = [ max( 0, min(width-1, round(randomGaussian(mouseX,width/4)) ) ) ,
max( 0, min(height-1, round(randomGaussian(mouseY,height/4)) ) ) ]
let mouseDist = sqrt((coord[0] - mouseX) ** 2 + (coord[1] - mouseY) ** 2) / width
// make the random somehow weighted depending on mousedist
let n = min(SIZES-1, max( 0,floor(randomGaussian(SIZES*mouseDist,SIZES/10)) ) );
let size = 2 ** n;
// print(n)
// print(colorArrays[n][floor(coord[0]/size)][floor(coord[1]/size)])
// fill(colorArrays[n][floor(coord[0]/size)][floor(coord[1]/size)])
const pixelIndex = 4*coord[1]*img.width + 4*coord[0];
fill(img.pixels[pixelIndex], img.pixels[pixelIndex+1], img.pixels[pixelIndex+2])
rect(coord[0],coord[1],size,size)
}
// fill(255)
// rect(0,0,100,10)
// fill(0)
// text(frameRate(),0,10)
}