Skip to content

Commit

Permalink
add squirclepath method
Browse files Browse the repository at this point in the history
  • Loading branch information
cormullion committed Jul 2, 2024
1 parent 37707e4 commit ef03568
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
17 changes: 16 additions & 1 deletion docs/src/howto/simplegraphics.md
Original file line number Diff line number Diff line change
Expand Up @@ -1073,9 +1073,24 @@ end
finish() # hide
nothing # hide
```

![squircles](../assets/figures/squircle.png)

`squirclepath()` builds a squircle shape using Bézier curves as paths, rather than using polygons. Here, `kappa` determines the circularity.

```@example
using Luxor # hide
@drawsvg begin # hide
background("grey10") # hide
setfillrule(:even_odd)
sethue("white")
for x in 280:-10:10
squirclepath(O, x, x;
kappa = x/150, action=:path)
end
fillpath()
end 800 700 # hide
```

## Stars and crosses

Use [`star`](@ref) to make a star. You can draw it immediately, or use the array of points it can create.
Expand Down
11 changes: 10 additions & 1 deletion src/curves.jl
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ the shape is a resonable approximation to a circle.
Use the `reversepath` option to construct the path in the opposite direction.
The difference betweeen `squircle()` and `squirclepath()` is that the former
builds polygons from points, the latter uses Bezier curves to build paths.
builds polygons from points, the latter uses Bezier curves to build paths.
See also `circlepath()`.
"""
Expand Down Expand Up @@ -302,6 +302,15 @@ function squirclepath(cpos, w, h;
end
return result
end

squirclepath(cpos, w, h, the_action::Symbol;
action = :none,
kappa = 0.75,
reversepath = false) = squirclepath(cpos, w, h;
action = the_action,
kappa = kappa,
reversepath = reversepath)

function arc(xc, yc, radius, angle1, angle2;
action = :none)
Cairo.arc(_get_current_cr(), xc, yc, radius, angle1, angle2)
Expand Down

0 comments on commit ef03568

Please sign in to comment.