xxxxxxxxxx
56
let res = 20
let step = 10
let pix = []
let spread = 4
function mousePix() {
let x = floor(mouseX/step)
let y = floor(mouseY/step)
return [x,y]
}
function setup() {
createCanvas(600, 600);
step = floor(width/res)
for (let i=0;i<res;i++) {
let r = []
for (let j=0;j<step;j++) {
r.push(1)
}
pix.push(r)
}
}
function draw() {
background(20);
for (let y=0;y<res;y++) {
for (let x=0;x<res;x++) {
let v = pix[y][x]
push()
translate((x+0.5)*step, (y+0.5)*step)
stroke(200, 200, 170);
strokeWeight(v)
point(0, 0)
pop()
if (pix[y][x] > 1) {
pix[y][x]*=0.9
}
}
}
if (mouseX > 0) {
let pos = mousePix()
pix[pos[1]][pos[0]] = step
for (let i=0;i<spread*2+1;i++) {
for (let j=0;j<spread*2+1;j++) {
dx = i-spread
dy = j-spread
px = pos[0]+dx
py = pos[1]+dy
if (px >= 0 && px < res &&
py >= 0 && py < res) {
pix[py][px] = step*pow(0.6, sqrt(dx*dx+dy*dy))
}
}
}
}
}