xxxxxxxxxx
41
// This sketch demonstrates the workings of:
// Gen.spread(), Gen.sineFloat()
// Mod.combine(), Mod.reverse(), Mod.invert()
// require libraries from TotalSerialism
const Gen = TotalSerialism.Generative;
const Mod = TotalSerialism.Transform;
const amt = 120;
let time = 0;
function setup() {
createCanvas(windowWidth, windowHeight);
}
function draw() {
background(0);
translate(width/2, height/2);
// spread x coordinates in array
let posX = Gen.spread(amt, -width/2, width/2);
// generate multiple periods of a cosine in array
// for half the amount of lines + 1
let posY = Gen.sineFloat(amt/2 + 1, time);
// slice of the start of the array which is 0
posY = posY.slice(1, posY.length);
// reverse the array the array
// invert the left array around 0
// combine both to one
posY = Mod.combine(Mod.reverse(posY), Mod.invert(posY, 0));
for (let i in posX){
stroke(255);
strokeWeight(2);
line(posX[i], 0, posX[i], posY[i] * height/2);
}
time += 0.01;
}