xxxxxxxxxx
109
// initialize arrays to hold vectors, movers, and rings
let vectors = [];
let movers = [];
let rings = [];
// set the scale for the grid
let scl = 20;
let rows, cols;
// initialize an offset for noise
let offset = 0;
// define canvas size and A3 paper dimensions
let canvas;
let a3Paper = {
width: 3508,
height: 2480,
};
function setup() {
// set canvas dimensions based on A3 paper
let w = a3Paper.width;
let h = a3Paper.height;
canvas = createCanvas(w, h);
// calculate the number of rows and columns based on canvas size and scale
rows = floor(width / scl);
cols = floor(height / scl);
// create an array of mover objects
for (let i = 0; i < 200; i++) {
movers[i] = new Mover(random(width), random(height), random(0.1, 0.15));
}
// create an array of ring objects
for (let i = 0; i < 20; i++) {
let x = random(width);
let y = random(height);
rings[i] = new Rings(x, y);
}
// set pixel density to 1 for consistency
pixelDensity(1);
// set initial background color to black
background(0);
}
function draw() {
// draw movers continuously
drawMovers();
// draw rings between frames 300 and 600
if (frameCount > 300 && frameCount < 600) {
drawRings();
}
// increment the offset for noise to animate the scene
offset += 0.1;
}
function drawRings() {
for (let ring of rings) {
ring.update();
ring.display();
}
// remove rings with life >= 10
for (let i = rings.length - 1; i >= 0; i--) {
if (rings[i].life >= 10) {
rings.splice(i, 1);
}
}
}
function drawMovers() {
// generate a grid of vectors influenced by Perlin noise
for (let i = 0; i < rows; i++) {
for (let j = 0; j < cols; j++) {
let index = i + j * cols;
let angle = noise(i * 0.1, j * 0.1) * TWO_PI;
let v = p5.Vector.fromAngle(angle);
v.setMag(0.1);
vectors[index] = v;
}
}
// update, display, and apply edge checks for each mover object
for (let mover of movers) {
mover.update();
mover.display();
mover.follow(vectors);
}
}
// function to export the canvas as an SVG when the "E" key is released
function exportHighResolution() {
saveSVG("exported.svg");
}
// detect key release and trigger SVG export on "E" key release
function keyReleased() {
if (key == "e" || key == "E") {
exportHighResolution();
}
}