-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c71b3fe
commit 4fd88b1
Showing
6 changed files
with
165 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
# Live graphics | ||
|
||
With the help of an external appication to manage windows, it's possible to use Luxor to create continuously changing graphics in a window. | ||
|
||
This example uses the [MiniFB](https://github.com/aviks/MiniFB.jl) package, which you can add using `] add MiniFB`. | ||
|
||
The file `play.jl` defines a simple macro, `@play`, which continuously evaluates and draws the graphics in a window. For example, this code: | ||
|
||
``` | ||
using Luxor | ||
include(dirname(pathof(Luxor)) * "/play.jl") | ||
let θ = 0 | ||
@play 400 400 begin | ||
# | ||
background("black") | ||
sethue("white") | ||
rotate(θ) | ||
hypotrochoid(200, 110, 37, :stroke) | ||
θ += π/120 | ||
sleep(0.01) | ||
# | ||
end | ||
end | ||
``` | ||
|
||
draws a continuously rotating hypotrochoid. | ||
|
||
## Clock | ||
|
||
This code also imports the `@play` macro. | ||
|
||
The call to `sleep()` reduces the CPU time, and allows other processes to run, but the millisecond | ||
animation will be less smooth as a result. | ||
|
||
![clock](assets/figures/clock.gif) | ||
|
||
``` | ||
using Luxor, Colors, Dates, ColorSchemes | ||
include(dirname(pathof(Luxor)) * "/play.jl") | ||
function clock(cscheme=ColorSchemes.leonardo) | ||
@play 400 600 begin | ||
# background | ||
sethue(get(cscheme, .0)) | ||
paint() | ||
# 24hour sector | ||
fontsize(30) | ||
sethue(get(cscheme, .2)) | ||
h = Dates.hour(now()) | ||
sector(O, 180, 200, π/2, π/2 + rescale(h, 0, 24, 0, 2pi), :fill) | ||
@layer begin | ||
fontsize(12) | ||
sethue("white") | ||
@. text(["0", "6", "12", "18"], polar(190, [i * π/2 for i in 1:4]), | ||
halign=:center, | ||
valign=:middle) | ||
end | ||
# minute sector | ||
sethue(get(cscheme, .4)) | ||
m = Dates.minute(now()) | ||
sector(O, 160, 180, 3π/2, 3π/2 + rescale(m, 0, 60, 0, 2pi), :fill) | ||
# second sector | ||
sethue(get(cscheme, .6)) | ||
s = Dates.second(now()) | ||
sector(O, 140, 160, 3π/2, 3π/2 + rescale(s, 0, 60, 0, 2pi), :fill) | ||
# millisecond indicator | ||
@layer begin | ||
setopacity(0.5) | ||
sethue(get(cscheme, .8)) | ||
ms = Dates.value(Dates.Millisecond(Dates.now())) | ||
circle(polar(120, 3π/2 + rescale(ms, 0, 1000, 0, 2pi)), 20, :fill) | ||
end | ||
# central text | ||
fontface("JuliaMono-Black") | ||
sethue(get(cscheme, 1.0)) | ||
text(Dates.format(Dates.now(), "HH:MM:SS"), halign=:center) | ||
sleep(0.05) | ||
end | ||
end | ||
clock(ColorSchemes.klimt) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters