Skip to content

Instantly share code, notes, and snippets.

@s-celles
Forked from cormullion/luxorminifb.jl
Created November 16, 2021 13:23
Show Gist options
  • Save s-celles/ac17f9e755c474b0ce6bfc25dce09abc to your computer and use it in GitHub Desktop.
Save s-celles/ac17f9e755c474b0ce6bfc25dce09abc to your computer and use it in GitHub Desktop.
Luxor -> MiniFB test
using Luxor, MiniFB, Colors
mutable struct Guilloche
f1::Float64
f2::Float64
f3::Float64
f4::Float64
# damping factors: increase to make the energy losses faster
xd1::Float64
xd2::Float64
yd1::Float64
yd2::Float64
# phase factors
xp1::Float64
xp2::Float64
yp3::Float64
yp4::Float64
end
function drawguilloche(g::Guilloche, radius=20;
npoints=100, limit=1000, stepby=0.025, colorfunction=(t) -> setopacity(1.0))
function nextposition(t)
x = exp(-g.xd1 * t) * (radius * sin((g.f1 * t) + g.xp1)) + exp(-g.xd2 * t) * (radius * sin((g.f2 * t) + g.xp2))
y = exp(-g.yd1 * t) * (radius * cos((g.f3 * t) + g.yp3)) + exp(-g.yd2 * t) * (radius * cos((g.f4 * t) + g.yp4))
return (x, y)
end
counter = 0
move(nextposition(0)...)
for t in 0:stepby:npoints
colorfunction(t)
line(nextposition(t)...)
counter += 1
if counter > limit
counter = 0
strokepath()
colorfunction(t)
move(nextposition(t)...)
end
end
strokepath()
end
function main()
WIDTH = 600
HEIGHT = 600
window = mfb_open_ex("Luxor ➛ MiniFB", WIDTH, HEIGHT, MiniFB.WF_RESIZABLE)
y = 0.1
g2 = Guilloche(2, 1.5, 3, 1,
0.0005, 0.0005, 0.0005, 0.0005,
.1, .1, .1, .1)
t1 = time_ns()
while true
buffer = @imagematrix begin
background("grey10")
fontsize(20)
sethue("orange")
g2.xd1 = y/70
g2.xd2 = y/80
g2.yd1 = y/90
g2.yd2 = y/100
g2.xp1 = 8y
g2.xp2 = 4y
g2.yp3 = 1y
g2.yp4 = 3y
drawguilloche(g2, 150,
npoints=300,
stepby=0.05,
limit=10,
colorfunction = (t) -> sethue(HSL(rescale(t, 0, 300, 0, 359), 0.9, 0.7)))
t2 = time_ns()
text(string("fps: ", round(1E9/(t2-t1), digits=2)),
boxtopleft(BoundingBox() * 0.9))
end 600 600
y = y + 0.001
(y > 1) && (y = 0.1)
state = mfb_update(window, permutedims(buffer, (2, 1)))
t1 = t2
if state != MiniFB.STATE_OK
break
end
end
mfb_close(window)
end
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment