Published
Edited
Oct 31, 2020
Insert cell
Insert cell
Insert cell
Insert cell
x1 = new X(5, {x:s/2, y:s/2})
Insert cell
updater = {
while (true) {
let maxCount = 1500
let pointsNumber = 0+Math.floor(maxCount*(Math.sin(new Date() / 500)*.5+.5))

let dd = Object.keys(new Array(pointsNumber).fill(0)).map(d=>{
return x1.getPoint(d++)
})

let points = d3.select("svg.main").selectAll('circle')
.data( dd )

points.enter()
.append('circle')
.attr('cx', d => d.x)
.attr('cy', d => d.y)
.attr('r', 2)

points.exit()
.remove()

points
.attr('cx', d => d.x)
.attr('cy', d => d.y)

await Promises.tick(10)
}


}
Insert cell
Insert cell
Insert cell
Insert cell
pushNeighbour = (stack, n) => {
n.dist = distance(n)
let i = 0
for(; i < stack.length; i++){
if(n.dist<stack[i].dist) {
stack.splice(i, 0, n)
break
}
}
// if n.dist is the biggest, add it to the end
if(i==stack.length)
stack.push(n)
}
Insert cell
Insert cell
// sortStack = (stack) => {
// stack = stack.map(p => {
// return {x:p.x, y:p.y, dist:distance(p)}
// })
// return stack.sort((a,b)=>{
// return distance(a)-distance(b)
// })
// }
Insert cell
distance = (point) => {
let x = point.x, y = point.y
let distance
x+=y/2
y*=Math.sqrt(3)/2
// circle
distance = (x*x+y*y)+Math.atan2(point.x,point.y)*.001
// // hexagon
// distance = sdHexagon({x:x, y:y})+Math.atan2(point.x,point.y)*.001
// // 12-ctagon
// distance = sdNgon(rotate({x:x, y:y}, new Date()/1000), 4)
// // distance += sdNgon(rotate({x:x, y:y}, 3.14159/3), 3)
// // distance += Math.atan2(point.x,point.y)*.001
if(half){
distance -= donutRadius**2
// distance -= donutRadius
distance = Math.abs(distance)
if (y > .5) distance = Infinity
}
return distance
}
Insert cell
rotate = (point, a) => {
let {x, y} = point
let x2 = x*Math.cos(a)-y*Math.sin(a)
let y2 = x*Math.sin(a)+y*Math.cos(a)
return {x: x2, y: y2}
}
Insert cell
Insert cell
Insert cell
sdNgon = (point, N) => {
let pol = decartToPolar(point)
let step=2.*3.1415/N
pol.x=(pol.x % step)-3.14/N
let point2 = polarToDecart(pol)
return point2.y
}
Insert cell
sdHexagon = (point) => {
let x = point.x
let y = point.y
let r = 0 // radius
let k = {x:-0.866025404, y:0.5, z:0.577350269}
x = Math.abs(x)
y = Math.abs(y)
let dot = 2 * Math.min(k.x * x + k.y * y, 0)
x -= dot*k.x
y -= dot*k.y
let clampX = x
clampX < -k.z*r ? -k.z*r : clampX
clampX > k.z*r ? k.z*r : clampX
x -= clampX
y -= r
return Math.sqrt(x*x+y*y)*Math.sign(y)
}
Insert cell
Insert cell
import {checkbox, slider} from "@jashkenas/inputs"
Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell
d3 = require('d3@5')
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more