Fixed bug in grids, added noise function

feature-more-radius-fns
Mike Lynch 2025-01-10 10:36:25 +11:00
parent 90c6a575b2
commit c9c970036f
3 changed files with 26 additions and 9 deletions

View File

@ -1,5 +1,10 @@
# CHANGELOG.md # CHANGELOG.md
## v1.0.2
* Fixed bug which was stopping slanted grids
* Added noise
## v1.0.1 ## v1.0.1
Added palettes Added palettes

View File

@ -20,6 +20,14 @@ function distance(dx, dy) {
return Math.sqrt(dx ** 2 + dy ** 2); 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 { class DotMaker {
constructor(width) { constructor(width) {
this.width = width; this.width = width;
@ -32,19 +40,17 @@ class DotMaker {
return []; return [];
} }
const ps = []; const ps = [];
const imin = -this.width; const is = int_range(-this.width, this.width / m)
const imax = this.width / m; is.map((i) => {
for( let i = imin; i <= imax; i++ ) { const js = int_range(m * i + (m - n) * this.width, m * i)
const jmin = m * i + (m - n) * this.width; js.map((j) => {
const jmax = m * i;
for( let j = jmin; j <= jmax; j++ ) {
const x = (j - m * i) / (m - n); const x = (j - m * i) / (m - n);
const y = m * (x + i); const y = m * (x + i);
if( x > 0 && y > 0 && x < this.width && y < this.width ) { if( x > 0 && y > 0 && x < this.width && y < this.width ) {
ps.push({i:i, j:j, x:x, y:y}); ps.push({i:i, j:j, x:x, y:y});
} }
} });
} });
return ps; return ps;
} }
@ -72,6 +78,12 @@ class DotMaker {
return 2 * maxr * distance((d.x - this.cx), (d.y - this.cy)) / this.width; return 2 * maxr * distance((d.x - this.cx), (d.y - this.cy)) / this.width;
case "in": case "in":
return 2 * maxr * (0.5 * this.width - distance((d.x - this.cx), (d.y - this.cy))) / this.width; 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": case "noise":
return maxr * Math.random(); return maxr * Math.random();
default: default:

View File

@ -4,7 +4,7 @@ toc: false
<h1>poptimal</h1> <h1>poptimal</h1>
<p>v1.0.1 | by <a href="https://mikelynch.org">mike lynch</a> | <a href="https://aus.social/@mikelynch">@mikelynch@aus.social</a> | <a href="https://git.tilde.town/bombinans/poptimal">source</a></p> <p>v1.0.2 | by <a href="https://mikelynch.org">mike lynch</a> | <a href="https://aus.social/@mikelynch">@mikelynch@aus.social</a> | <a href="https://git.tilde.town/bombinans/poptimal">source</a></p>
<div class="grid grid-cols-2"> <div class="grid grid-cols-2">