Skip to content

Commit

Permalink
not sure about play yet
Browse files Browse the repository at this point in the history
  • Loading branch information
cormullion committed Nov 6, 2020
1 parent 0499205 commit c71b3fe
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1"
Juno = "e5e0dc1b-0480-54bc-9374-aad01c23163d"
QuartzImageIO = "dca85d43-d64c-5e67-8c65-017450d5d020"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
MiniFB = "cc649173-1898-4bb8-8a16-ca5f88bd87d9"
# MiniFB = "cc649173-1898-4bb8-8a16-ca5f88bd87d9"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand All @@ -28,4 +28,4 @@ FileIO = "1.0, 1.1, 1.2, 1.3, 1.4"
ImageMagick = "0.7, 1.0, 1.1"
Juno = "0.7, 0.8"
QuartzImageIO = "0.6, 0.7"
MiniFB = "0.1"
# MiniFB = "0.1"
10 changes: 7 additions & 3 deletions src/Luxor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ end
"""
module Luxor

using Juno, Cairo, Colors, FileIO, Dates, MiniFB
using Juno, Cairo, Colors, FileIO, Dates

# , MiniFB

#= from Cairo use: CairoARGBSurface, CairoEPSSurface, CairoMatrix, CairoPDFSurface, CairoPattern, CairoPatternMesh, CairoSurface, CairoSVGSurface,
CairoContext, arc, arc_negative, circle, clip, clip_preserve, close_path,
Expand Down Expand Up @@ -52,7 +54,7 @@ include("Boxmaptile.jl")
include("noise.jl")
include("deprecations.jl")
include("graphlayout.jl")
include("play.jl")
# include("play.jl")
include("Style.jl")
#include("shapefile.jl") # don't load unless you've loaded Shapefile.jl

Expand All @@ -67,7 +69,9 @@ export Drawing,
finish, preview,
origin, rulers, background,

@png, @pdf, @svg, @eps, @draw, @play,
@png, @pdf, @svg, @eps, @draw,

# @play,

newpath, closepath, newsubpath,

Expand Down
124 changes: 123 additions & 1 deletion src/play.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
macro play(w, h, body)
quote
window = mfb_open_ex("julia:clock", $w, $h, MiniFB.WF_RESIZABLE)
window = mfb_open_ex("julia", $w, $h, MiniFB.WF_RESIZABLE)
buffer = zeros(UInt32, $w, $h)
while true
Drawing($w, $h, :image)
Expand All @@ -16,3 +16,125 @@ macro play(w, h, body)
mfb_close(window)
end
end

#= bez path thingy
using Luxor, Colors, Dates
function bez()
j = rand(1:15)
n = 1
pgon = [Point(-100, -100), Point(100, 100), Point(100, -50), Point(-50, 100)]
@play 500 500 begin
t1 = time_ns()
background(0, 0, 0)
sethue(HSB(285, .7, .9))
k = 3
# for i in 1:5
for s in 1:30
setopacity(rescale(s, 1, 30, 0.1, 1.0))
pgon[1] += (k * rand(-1:1), k * rand(-1:1))
pgon[2] += (k * rand(-1:1), k * rand(-1:1))
pgon[3] += (k * rand(-1:1), k * rand(-1:1))
pgon[4] += (k * rand(-1:1), k * rand(-1:1))
bp = makebezierpath(pgon)
drawbezierpath(bp, :stroke)
end
# end
if !isinside(polycentroid(pgon), box(BoundingBox() * 0.8), allowonedge=true)
pgon = [Point(-100, -100), Point(100, 100), Point(100, -50), Point(-50, 100)]
end
n = mod1(n + 1, 200)
sethue("white")
fontface("JuliaMono-Black")
fontsize(20)
text(Dates.format(now(), "HH:MM:SS"), halign=:center)
# time calc
sethue("white")
t2 = time_ns()
text(string("fps: ", round(1E9/(t2-t1), digits=2)), boxtopleft(BoundingBox() * 0.9))
t1 = t2
sleep(0.1)
end
end
bez()
=#

#= some balls
using Luxor, Colors, Dates
mutable struct Ball
position::Point
velocity::Point
radius::Float64
hue::Float64
end
function f()
balls = [Ball(rand(BoundingBox(Point(-300, -300), Point(300, 300))), rand(BoundingBox(Point(-300, -300), Point(300, 300))), rand(1:10), rand(0:360)) for i in 1:450]
@play 600 600 begin
w = 500
h = 500
background("black")
for ball in balls
sethue(HSB(ball.hue, .8, 0.8))
circle(ball.position, ball.radius, :fill)
if !(-w/2 < ball.position.x < w/2)
ball.velocity = -ball.velocity
ball.position = Point(-w/2, ball.position.y)
end
if !(-h/2 < ball.position.y < h/2)
ball.velocity = -ball.velocity
ball.position = Point(ball.position.x, -h/2)
end
ball.velocity = Point(rand(-4:4, 2) ...)
ball.position = ball.position + ball.velocity
end
sleep(0.01)
end
end
f()
=#

#= clock
using Luxor, Colors, Dates
function clock()
@play 400 600 begin
fontface("JuliaMono-Regular")
# outer
sethue("black")
paint()
sethue("white")
fontsize(30)
text(Dates.format(Dates.now(), "HH:MM:SS"), halign=:center)
sethue("cyan")
h = Dates.hour(now())
sector(O, 180, 200, 3π/2, 3π/2 + rescale(h, 0, 24, 0, 2pi), :fill)
sethue("magenta")
m = Dates.minute(now())
sector(O, 160, 180, 3π/2, 3π/2 + rescale(m, 0, 60, 0, 2pi), :fill)
sethue("red")
s = Dates.second(now())
sector(O, 140, 160, 3π/2, 3π/2 + rescale(s, 0, 60, 0, 2pi), :fill)
sethue("orange")
ms = Dates.value(Dates.Millisecond(Dates.now()))
sector(O, 137, 140, 3π/2, 3π/2 + rescale(ms, 0, 1000, 0, 2pi), :fill)
end
end
clock()
=#

0 comments on commit c71b3fe

Please sign in to comment.