From c71b3fedf9f81238f69712b48f586fa056378fec Mon Sep 17 00:00:00 2001 From: cormullion Date: Fri, 6 Nov 2020 08:53:09 +0000 Subject: [PATCH] not sure about play yet --- Project.toml | 4 +- src/Luxor.jl | 10 +++-- src/play.jl | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 132 insertions(+), 6 deletions(-) diff --git a/Project.toml b/Project.toml index 8d09b61b..8dfcf243 100644 --- a/Project.toml +++ b/Project.toml @@ -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" @@ -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" diff --git a/src/Luxor.jl b/src/Luxor.jl index bb2d8912..9f9858a8 100644 --- a/src/Luxor.jl +++ b/src/Luxor.jl @@ -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, @@ -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 @@ -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, diff --git a/src/play.jl b/src/play.jl index de0c168f..eb9f59af 100644 --- a/src/play.jl +++ b/src/play.jl @@ -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) @@ -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() + +=#