Skip to content

Instantly share code, notes, and snippets.

View baku89's full-sized avatar
🍡

Baku 麦 baku89

🍡
View GitHub Profile
@baku89
baku89 / chamfer.pave.js
Created June 27, 2024 13:47
chamfer.pave.js
const r = unite([
rect([20, 30], [80, 70]),
rect([40, 10], [60, 90]),
])
function chamfer(path, distance) {
return spawnVertex(r, (seg, index, curve) => {
const next = Curve.nextSegment(curve, index)
const point = Segment.point(next, {offset: distance})
return [
@baku89
baku89 / kamone-bezier.0412.pave.js
Last active April 11, 2024 18:04
kamone-bezier.0412.pave.js
const controls = [
[[10, 10], true],
[[50, 10], time < .1],
[[10, 50], time < .25],
[[50, 50], time > .5],
[[10, 90], time > .6],
[[50, 90], time > .8],
[[90, 50], time < .7],
[[90, 10], true],
]
r = merge([
circle([25, 50], 20),
line([50, 40], [50, 60]),
unarc(circle([75, 50], 20))
])
debug(r, '#eee', .5)
p = point(r, {curveIndex: 2, segmentIndex: 0, unit: -time})
c = subdiv(circle([50, 50], 40), 10)
w = spawn(c, (s, i) => {
dir = i % 2 === 0 ? 0 : 1
t = sin((i / segmentCount(c) * 2 + time) * 360)
p0 = Segment.point(s, 0)
p1 = Segment.point(s, 1)
n0 = vec2.rotate(Segment.normal(s, 0), t * 73)
c = subdiv(circle([50, 50], 40), 10)
w = spawn(c, (s, i) => {
dir = i % 2 === 0 ? 0 : 1
t = sin((i / segmentCount(c) * 2 + time) * 360)
p0 = Segment.point(s, 0)
p1 = Segment.point(s, 1)
n0 = vec2.rotate(Segment.normal(s, 0), t * 73)
c = transform(
subdiv(arc([50, 50], 20, 0, 720), 6),
mat2d.rotation(time * 120, [50, 50])
)
w = spawn(c, (s, i) => {
t = sinwave(i / segmentCount(c) * 3 - time)
dir = i % 2 === 0 ? 1 : -1
p0 = Segment.point(s, 0)
r = ngon([50, 50], 40, 4)
r = subdivide(r, 6)
r = spawn(r, (seg, i) =>
arcByPointsAngle(
seg.start,
seg.point,
scalar.sin(/*0*/time * 360/**/)
* 180 * (i % 2 ? 1 : -1)
)
)
p = ellipse([50, 50], [40, 30])
debug(p, 'wheat')
p = trim(
p,
sinwave(time),
coswave(time)
)
const c = Path.circle([50, 50], 45)
const cs = Path.subdiv(c, 5)
const p = Path.spawnVertex(cs, (s, i) => {
const t = scalar.coswave(i / 10 + time)
return Path.arcFromPointsAndAngle(
s.start,
s.point,
scalar.mix(36, -230, t)
).curves[0].vertices[1]
@baku89
baku89 / Path.arc.js
Last active February 26, 2024 05:38
Demo for Path.point
const p = Path.arc(
[50, 50], // center
40, // radius
-90,
180, // angle range
time < 0.25
? {count: Math.ceil(time * 4 * 8 + 1)}
: time < 0.5
? {align: 'uniform', step: scalar.fit(time, 0.25, 0.5, 90, 12.5)}
: time < 0.75