From c9c970036fc004a6c36df67c094a47ed3bcca03b Mon Sep 17 00:00:00 2001 From: Mike Lynch Date: Fri, 10 Jan 2025 10:36:25 +1100 Subject: [PATCH] Fixed bug in grids, added noise function --- CHANGELOG.md | 5 +++++ src/components/dots.js | 28 ++++++++++++++++++++-------- src/index.md | 2 +- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 14c23c4..9705f1a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # CHANGELOG.md +## v1.0.2 + +* Fixed bug which was stopping slanted grids +* Added noise + ## v1.0.1 Added palettes diff --git a/src/components/dots.js b/src/components/dots.js index bbf73f2..03d2e9e 100644 --- a/src/components/dots.js +++ b/src/components/dots.js @@ -20,6 +20,14 @@ function distance(dx, dy) { return Math.sqrt(dx ** 2 + dy ** 2); } +function int_range(v1, v2) { + const vs = [v1, v2]; + vs.sort((a, b) => a - b); + const low = Math.floor(vs[0]); + const high = Math.ceil(vs[1]); + return [...Array(high - low + 1).keys()].map((i) => i + low); +} + class DotMaker { constructor(width) { this.width = width; @@ -32,19 +40,17 @@ class DotMaker { return []; } const ps = []; - const imin = -this.width; - const imax = this.width / m; - for( let i = imin; i <= imax; i++ ) { - const jmin = m * i + (m - n) * this.width; - const jmax = m * i; - for( let j = jmin; j <= jmax; j++ ) { + const is = int_range(-this.width, this.width / m) + is.map((i) => { + const js = int_range(m * i + (m - n) * this.width, m * i) + js.map((j) => { const x = (j - m * i) / (m - n); const y = m * (x + i); if( x > 0 && y > 0 && x < this.width && y < this.width ) { ps.push({i:i, j:j, x:x, y:y}); } - } - } + }); + }); return ps; } @@ -72,6 +78,12 @@ class DotMaker { return 2 * maxr * distance((d.x - this.cx), (d.y - this.cy)) / this.width; case "in": return 2 * maxr * (0.5 * this.width - distance((d.x - this.cx), (d.y - this.cy))) / this.width; + + // case "hyper-out": + // return 2 * maxr * Math.abs(d.x - this.cx) (d.y - this.cy)) / this.width; + // case "hyoer-in": + // return 2 * maxr * (0.5 * this.width - distance((d.x - this.cx), (d.y - this.cy))) / this.width; + case "noise": return maxr * Math.random(); default: diff --git a/src/index.md b/src/index.md index a5ce615..bf32c35 100644 --- a/src/index.md +++ b/src/index.md @@ -4,7 +4,7 @@ toc: false

poptimal

-

v1.0.1 | by mike lynch | @mikelynch@aus.social | source

+

v1.0.2 | by mike lynch | @mikelynch@aus.social | source