xxxxxxxxxx
57
let shape;
let shadow;
let points = [];
function setup() {
createCanvas(400, 400);
shape = createGraphics(width, height);
shadow = createGraphics(width, height);
generatePoints();
noLoop();
}
function generatePoints() {
points = [];
const x = width/2;
const y = height/2;
for(let i = 0; i < TAU; i += TAU/10) {
const r = random(100, 200);
points.push(createVector(cos(i) * r + x, sin(i) * r + y));
}
}
function draw() {
shape.clear();
shadow.clear();
shape.fill(255, 0, 0);
shape.noStroke();
shadow.noFill();
shadow.stroke(100, 0, 0);
shadow.strokeWeight(10);
shape.beginShape();
shadow.beginShape();
for(let p of points) {
shape.vertex(p.x, p.y);
shadow.vertex(p.x, p.y);
}
shape.endShape(CLOSE);
shadow.endShape(CLOSE);
shadow.filter(BLUR, 15);
let shadowImage = shadow.get();
shadowImage.mask(shape);
image(shape, 0, 0);
image(shadowImage, 0, 0, width, height);
}