Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Action as keyword argument #174

Closed
9 tasks
Wikunia opened this issue Sep 28, 2021 · 8 comments
Closed
9 tasks

Action as keyword argument #174

Wikunia opened this issue Sep 28, 2021 · 8 comments

Comments

@Wikunia
Copy link
Contributor

Wikunia commented Sep 28, 2021

I think it would be great to have a dispatch version of all drawing functions which take an action as a keyword argument.
Then one can easily change the action from :path to :clip as an example for all kinds of different functions without caring about the other positional arguments. That would be for example useful for JuliaAnimators/Javis.jl#399

Currently it seems to be the last positional argument at least in

  • circle
  • poly
  • rect
  • star
  • ellipse
  • arc
  • arrow
  • box
  • line
@cormullion
Copy link
Member

I made some progress with this in on the branch here 58946d3. It's quite a disruptive change, though, so it will need a lot of testing.

using Luxor

@draw begin
    setopacity(0.7)
    squircle(O, 250, 250, action=:stroke)
    star(O, 260, 6, 0.4, 0.0, action=:stroke)
    for f in (:stroke, :fill, :path, :stroke)
        randomhue()
        circle(O, 250,                         action=f)
        poly([Point(50x, 60sin(x)) for x in -5:0.1:5], action=f)
        rect(O, 200, 200,                      action=f)
        star(O, 100, 6, 0.5,                   action=f)
        ellipse(O, O + (200, 200), 100,        action=f)
        arc(O, 100, 0, π/2,                    action=:path)
        arc(O, 150, π, 3π/2,                   action=f)
        box(O, 150, 150,                       action=f)
        ngon(O, 150, 15,                       action=f)
        sethue("black")
        polycross(O, 200, 6, 0.5, 0.0,         action=f)
        line(O,  O + (200, 200),               action=f)
    end
end

Screenshot 2021-09-30 at 16 14 36

@Wikunia
Copy link
Contributor Author

Wikunia commented Sep 30, 2021

Thanks @cormullion I would necessarily change anything from the current version as I don't wanna break things. Just adding versions where it can be used with keyword argument would be nice. Or what is your point on that?

@cormullion
Copy link
Member

I've made it possible to do either:

circle(O, 105, :stroke)
# or 
circle(O, 120, action = :stroke)

so all existing code should work, and all these functions can also be used with action = symbol keyword arguments as well as symbol actions. Apart from arrow (which I don't understand and might not do :)), they all work, and tests pass, after struggling with a few awkward methods with optional positional arguments.

@Wikunia
Copy link
Contributor Author

Wikunia commented Oct 2, 2021

You're awesome thanks! What is the error with arrow? Shall I have a look into it?

@cormullion
Copy link
Member

Thanks! I'm not sure whether arrow() has or needs a "fill" or any other action, but it might be used internally to control the filling of arrowheads. 😃 Not my favourite function...

It would be very helpful if sometime you could test your current Javis creations against Luxor#master to see whether I'm currently missed any method definitions...

@Wikunia
Copy link
Contributor Author

Wikunia commented Oct 5, 2021

Works perfectly fine with Javis. Haven't tested the usage of the keyword arguments though. Maybe @TheCedarPrince can use it to test the JImages approach though.

@cormullion
Copy link
Member

Thanks - hopefully this won't be a disruptive change! :)

@cormullion
Copy link
Member

I'll release v2.16 and see what happens!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants