Transparent background with Luxor.jl

Hi.

Does somebody know how I can generate a .png file with a transparent background?

The docs here say that it should suffice to put background(0,0,0,0).

Using the MWE from Simple examples · Luxor

using Luxor
@png begin
   background(0,0,0,0)
   setopacity(0.85)
   steps = 20
   gap   = 2
   for (n, θ) in enumerate(range(0, step=2π/steps, length=steps))
       sethue([Luxor.julia_green,
           Luxor.julia_red,
           Luxor.julia_purple,
           Luxor.julia_blue][mod1(n, 4)])
       sector(Point(0, 0), 50, 250 + 2n, θ, θ + 2π/steps - deg2rad(gap), action = :fill)
   end
end

I only ever get a white background (my image viewer is set to show a checker pattern instead)

What am I doing wrong here?

You’re using the “quick” macros, which set the foreground and background to “sensible” defaults. Use the Drawing() constructor directly.

2 Likes

That was it!
Thanks a lot for the amazing package and the quick tech support :slight_smile:

For completeness:

using Luxor

Drawing()
origin()

background(0,0,0,0)
setopacity(0.85)
steps = 20
gap   = 2
for (n, θ) in enumerate(range(0, step=2π/steps, length=steps))
    sethue([Luxor.julia_green,
        Luxor.julia_red,
        Luxor.julia_purple,
        Luxor.julia_blue][mod1(n, 4)])
    sector(Point(0, 0), 50, 250 + 2n, θ, θ + 2π/steps - deg2rad(gap), action = :fill)
end

finish()
preview()
1 Like