xxxxxxxxxx
51
function setup() {
createCanvas(600, 600);
}
function smoothstep(edge0, edge1, x) {
// Clamp x to 0..1 range
x = constrain((x - edge0) / (edge1 - edge0), 0.0, 1.0);
// Evaluate polynomial
return x * x * (3 - 2 * x);
}
function draw() {
background(25);
const NUM_GRID = 100;
const W = width/(NUM_GRID);
// Grid
stroke(25);
for(let i=0; i<NUM_GRID; i++) {
line(i*W, 0, i*W, height);
}
for(let i=0; i<NUM_GRID; i++) {
line(0, i*W, width, i*W);
}
// Circle
let cx = NUM_GRID/2.0;
// print(cx);
let cy = NUM_GRID/2.0;
let r = NUM_GRID/3;
for(let i=0; i<NUM_GRID; i++) {
for(let j=0; j<NUM_GRID; j++) {
let dx = cx-j;
let dy = cy-i;
let d = sqrt(dx*dx + dy*dy);
// if()
noStroke();
let opacity = map(abs(d-r), 0, r, 1, 0);
opacity = map(opacity, 0.96, 1, 0,1);
// opacity = smoothstep(0.5, 0.55, opacity);
// if(d>=r)
// opacity = 0;
fill(255, 222, 0, 255*opacity);
rect(i*W, j*W, W, W);
}
}
}