xxxxxxxxxx
65
const tileSize = 2;
const tileCount = 200;
const w = tileCount * tileSize,
h = tileCount * tileSize;
let poly,
polyRadius = 0.1;
let polyAngle;
function setup() {
createCanvas(w, h);
polyAngle = (PI * 2) /4;
poly = createPolygon(5, polyAngle, polyRadius, createVector(0, 0));
for (let i = 0; i < 5; i++) {
const p = poly[i];
p.x += random(-0.05, 0.05);
p.y += random(-0.05, 0.05);
// p.x += .0001;
}
}
function draw() {
background(220);
for (let y = 0; y < h; y += tileSize) {
for (let x = 0; x < w; x += tileSize) {
var uv = createVector(x / w - 0.5, y / h - 0.5);
var inside = 0;
for (let i = 0; i < 5; i++) {
const p = poly[i];
if (uv.dist(p) < polyRadius) {
fill(255 * uv.x, 255 * uv.y, 0);
circle(x, y, polyRadius*2);
}
}
// if (inside > 0) {
// fill(255 * uv.x, 255 * uv.y, 0);
// circle(x, y, 1);
// }
}
}
}
function createPolygon(sides, rotation, radius, translate) {
const points = [];
const angleInc = TWO_PI / sides;
let angle = rotation;
let x;
let y;
let counter = sides;
for (; counter > 0; counter--) {
x = translate.x + radius * Math.sin(angle);
y = translate.y + radius * Math.cos(angle);
points.push(createVector(x, y));
angle += angleInc;
}
return points;
}