IntroAJulia.jl
IntroAJulia.jl copied to clipboard
Luxor, Cairo, and Turtle graphics
Chapter 4 and other chapters use turtle graphics via the Luxor package which wraps Cairo. Apparently Cairo.jl is not building right now.
I wish there were a 100% Julia graphics package that we could use for the Turtle business.
Hi Christian
I had the same problem that Cairo.jl was not building. So I implemented a small native svg backend. The basic turtle graphics primitives are also available. Output is visible in Atom and Vscode (plotplane) and Jupyter.
using NativeSVG
t = Turtle()
forward(t, -200)
penup(t)
turn(t, -90)
forward(t, 200)
turn(t, 90)
pendown(t)
for c in (:black, :red, :orange, :yellow, :green, :blue, :indigo, :violet)
pencolor(t, c)
forward(t, 100)
turn(t, 45)
end
Drawing(t)
Can you look at it and give me some feedback? I really like to replace the Luxor dependency with something else;)
Kind regards
Ben
Hey Ben,
It looks good! It looks like a small, clean package. I tried it out in Jupyter, and it works very well there. I tried a few of the examples form Chapter 4, and they all seem to work well.
I looked around a bit to understand what would need to happen to display an SVG from the REPL. I guess one option is to to display the svg in a web browser window; is this the approach you're thinking of?
Chris
Hi Christian
Checkout NativeSVG. It should work now also from a REPL (to a web browser window). Kind regards
Ben
Wonderful! The example works well from the REPL; that's quick work on your part.
I have wondered if an introduction to a more typical plotting package would be more useful than turtle graphics. It seems the turtle graphics is targeting children; I wonder at what age or in what situations an introduction to something like Plots.jl would be as enjoyable. I don't have plans to change this in PiensaEnJulia; even so, I'm interested to learn if you have comments on this topic.
I was able to use this PR on Cairo.jl to get ThinkJulia.jl working. I was able to run the code in Chapter four of ThinkJulia.
Ben, do you plan to modify the book to use NativeSVG? If so, do you know when?