xxxxxxxxxx
41
// include the package as ts.
const ts = TotalSerialism;
// assign sub-libraries to the ts namespace
// otherwise some function names clash with p5
Object.assign(ts, ts.Stochastic, ts.Utility);
let hues;
let positionsX;
let positionsY;
let sizes;
let dots = 500;
function setup() {
createCanvas(windowWidth, windowHeight);
// random arrays for hues, positions, sizes
// in specified ranges;
hues = ts.random(dots, 0, 360);
positionsX = ts.random(dots, 0, width);
positionsY = ts.random(dots, 0, height);
sizes = ts.random(dots, 10, 80);
}
function draw() {
background(0);
stroke(255);
strokeWeight(2);
colorMode(HSB);
// draw the dots with assigned hue, x, y, size
for (let i=0; i<dots; i++){
fill(hues[i], 40, 255);
circle(positionsX[i], positionsY[i], sizes[i]);
}
// add a value to all numbers in the array to shrink the size
// and wrap between 10 and 80
sizes = ts.wrap(ts.add(sizes, -0.5), 10, 80);
}