From 4fd49b8a65707a71ee6eb134fc5041b388981076 Mon Sep 17 00:00:00 2001 From: Valentin Vago Date: Tue, 26 Oct 2021 16:31:56 +0200 Subject: [PATCH] chore(demo): update demo setup --- .../layers/canvas/basics-animation.js | 23 +++++----- demo-project/layers/canvas/basics-setup.js | 42 ++++++++++++++++++- 2 files changed, 53 insertions(+), 12 deletions(-) diff --git a/demo-project/layers/canvas/basics-animation.js b/demo-project/layers/canvas/basics-animation.js index 3dd83863..23b7a39a 100644 --- a/demo-project/layers/canvas/basics-animation.js +++ b/demo-project/layers/canvas/basics-animation.js @@ -1,13 +1,16 @@ -// @ts-check - +clear(); const now = read('now', 0); -const n = (now % 10000) * 0.0001; -const h = (sin(n * PI2)) * 0.1; -const color = hsla(h + 0.75, 0.5, .7, 1); - -clear(); -fillStyle(color); +const beatP = beatPrct(now, read('bpm', 120) * (1 / 2)); +const beatNum = read('beatNum', 1); +const frq = read('frequency', []); +const vol = read('volume', []); +const frqAvg = arrayAvg(frq); -rect(width(2), height(2), width(4), height(4)); -fill(); +// if (frqAvg > 80) { +// cache.generate(); +// } +lineCap('round'); +lineCap('square'); +(cache.lines || []) + .forEach((line) => line.render(now)); \ No newline at end of file diff --git a/demo-project/layers/canvas/basics-setup.js b/demo-project/layers/canvas/basics-setup.js index d7d43e67..27e33000 100644 --- a/demo-project/layers/canvas/basics-setup.js +++ b/demo-project/layers/canvas/basics-setup.js @@ -1,3 +1,41 @@ -// @ts-check +class Line { + constructor(index) { + this.x = width(2) - (width() * random()); + this.y = height() * random(); + this.length = random() * width(0.75); + this.index = index + this.velocity = random() - 0.5; + this.width = random(); -// TODO \ No newline at end of file + const v = random(); + this.color = rgba(v, v, v, 1); + } + + render(now, beatNum) { + const lwidth = vmin(this.width * 20); + lineWidth(lwidth); + strokeStyle(this.color); + beginPath(); + + const distance = this.length + width() + lwidth; + const relative = abs(now * this.velocity) % distance; + + let x = relative - this.length; + + if (this.velocity < 0) { + x = width() - relative; + } + + moveTo(x, this.y); + lineTo(x + this.length, this.y); + stroke(); + } +} + +cache.lines = []; +cache.generate = () => { + repeat(50, (i) => { + cache.lines.push(new Line(i)); + }); +} +cache.generate();