JuliaGraphics / Luxor.jl

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

Update sethue() and setcolor() to accept Nothing arguement #273

Closed StevenSiew closed 4 months ago

StevenSiew commented 9 months ago

Please update sethue() amd setcolor() to accept Nothing arguement to return the current values of color and alpha

function sethue(::Nothing)
    (cr, r, g, b, a) = _get_current_cr_color()
    return current_color
end
function setcolor(::Nothing)
    (cr, r, g, b, a) = _get_current_cr_color()
    return current_color_and_alpha
end

and make two new functions

gethue() = sethue(nothing)

getcolor() = setcolor(nothing)

you can also add this

sethue() = sethue(nothing)

setcolor() = setcolor(nothing)
cormullion commented 9 months ago

Hi! It's a reasonable idea. There's already a getcolor() function, a gethue() function would be easy to add.

In general there's an inconsistency in the APl: the interface style of set...(nothing) to do the equivalent get...() is sometimes available and sometimes not. For example, there's a getline() to match setline(), but a setstrokescale(nothing) rather than a getstrokescale(). There's no setantialias(nothing) or setlinecap(nothing). And sometimes there aren't available hooks to get the information that you can set (getopacity()). So I think the interface will continue to be inconsistent even with these additions ... :)

cormullion commented 4 months ago

Luxor v3.9:

julia-1.10> Drawing()
 Luxor drawing: (type = :png, width = 800.0, height = 800.0, location = luxor-drawing.png)

julia-1.10> sethue()
RGB{Float64}(0.0,0.0,0.0)

julia-1.10> getcolor()
RGBA{Float64}(0.0,0.0,0.0,1.0)

julia-1.10> setcolor()
RGBA{Float64}(0.0,0.0,0.0,1.0)