Last active
December 1, 2022 16:03
-
-
Save andrusenn/b6615c08005adbaddc45c71f643736fb to your computer and use it in GitHub Desktop.
Plexus network
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Plexus structure for p5js | |
Ponints connected | |
*/ | |
function Plexus(_op) { | |
let opts = { | |
num: 40, | |
cx: 0, | |
cy: 0, | |
radx: 100, | |
rady: 100, | |
mind: 20, | |
maxd: 50, | |
rp: (p) => {}, | |
rc: (p1, p2) => {}, | |
..._op, | |
}; | |
let p = []; | |
// create | |
for (let i = 0; i < opts.num; i++) { | |
let a = random(Math.PI * 2); | |
let x = opts.cx + cos(a) * random(-opts.radx, opts.radx); | |
let y = opts.cy + sin(a) * random(-opts.rady, opts.rady); | |
p.push({ x, y }); | |
} | |
// render | |
p.forEach((p1) => { | |
opts.rp(p1); | |
//conn | |
p.forEach((p2) => { | |
if (p1 != p2) { | |
let d = dist(p1.x, p1.y, p2.x, p2.y); | |
if (d > opts.mind && d < opts.maxd) { | |
opts.rc(p1, p2); | |
} | |
} | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment