JuliaGraphics / Luxor.jl

Simple drawings using vector graphics; Cairo "for tourists!"
http://juliagraphics.github.io/Luxor.jl/
Other
575 stars 72 forks source link

set_next_drawing_index` not defined #290

Closed mpeters2 closed 6 months ago

mpeters2 commented 7 months ago

I've been trying some of the demos on this page, and I get an "set_next_drawing_index` not defined" error at the first Luxor.set_next_drawing_index() .

# First, we'll setup our display buffers and MiniFB windows, one for each Luxor drawing:
using MiniFB, Luxor, Colors, FixedPointNumbers

WIDTH=500
HEIGHT=500

function window_update_task(window,buffer)
    state=mfb_update(window,buffer)
    while state == MiniFB.STATE_OK
        state=mfb_update(window,buffer)
        sleep(1.0/120.0)
    end
    println("\nWindow closed\n")
end

window1 = mfb_open_ex("1", WIDTH, HEIGHT, MiniFB.WF_RESIZABLE)
buffer1 = zeros(ARGB32, WIDTH, HEIGHT)
@async window_update_task(window1,buffer1)

window2 = mfb_open_ex("2", WIDTH, HEIGHT, MiniFB.WF_RESIZABLE)
buffer2 = zeros(ARGB32, WIDTH, HEIGHT)
@async window_update_task(window2,buffer2)

window3 = mfb_open_ex("3=1+2", WIDTH, HEIGHT, MiniFB.WF_RESIZABLE)
buffer3 = zeros(ARGB32, WIDTH, HEIGHT)
@async window_update_task(window3,buffer3)

# Buffers 1, 2, and 3 are the buffers for the three MiniFB windows. They'll appear on your display.
# Next we'll create three Luxor drawings that connect to these buffers.

d1 = Drawing(buffer1)    

Luxor.set_next_drawing_index()   
d2 = Drawing(buffer2)

Luxor.set_next_drawing_index()   
d3 = Drawing(buffer3, "julia.png")

# We now have three drawings which are continuously updated and visible in three separate windows. 
# Let's start by drawing on drawing 1.

Luxor.set_drawing_index(1) 
origin()
setopacity(0.4)
foregroundcolors = Colors.diverging_palette(
    rand(0:360), 
    rand(0:360), 
    200, s=0.99, b=0.8)
gsave()
for i in 1:500
    sethue(foregroundcolors[rand(1:end)])
    circle(Point(rand(-300:300), rand(-300:300)), 15, :fill)
end
grestore()

# Now let's switch to drawing 2 and draw the Julia logo:

Luxor.set_drawing_index(2)
origin()
setopacity(1.0)
gsave()
julialogo(centered=true, bodycolor=colorant"white")
grestore()

# Finally, we'll switch to drawing 3, and set its contents by ANDing the buffers of drawings 1 and 2:

Luxor.set_drawing_index(3)  
background("black")
buffer3 .= reinterpret(ARGB{N0f8}, 
    (reinterpret.(UInt32,buffer1) .& 
     reinterpret.(UInt32,buffer2)))

# To finish, we'll set the opacity of each pixel to 1.0:

buffer3.=ARGB32.(RGB24.(buffer3))

finish()
preview()

Error:

ERROR: UndefVarError: `set_next_drawing_index` not defined
Stacktrace:
 [1] getproperty(x::Module, f::Symbol)
   @ Base ./Base.jl:31

Julia 1.9.3 MacOS 14 Luxor v3.8.0

cormullion commented 7 months ago

Try it with a preceding underscore perhaps?

With that change, it looks like it does something similar to the documentation.

Screenshot 2023-12-09 at 08 23 03

Documentation needs updating. Although, I'm not really sure why the function is 'internal'... 🤔

mpeters2 commented 6 months ago

That did the trick. I've made a pull request.

cormullion commented 6 months ago

Thanks!