How to plot shapes in Julia

Viewed 244

I would like to plot for example a square (or maybe more generally speaking a n-gon).
I know that I can plot "functions" that form a shape, like a circle:

n = 100
ϕ = range(0,stop=2*π,length=n)
x = cos.(ϕ)';
y = sin.(ϕ)';
plot(x,y)

enter image description here

But that turns out to be very difficult when it comes to a n-gon, I guess one could "stich" lines that can form a n-gon, but that seems very unpractical when you want to plot a 32-gon.
I talked a lot abou n-gons but I am more interested if Julia has some already build in way to plot different types of shapes.

1 Answers

You can use Luxor library, which provides ngon function (example from documentation).

using Luxor, Colors
Drawing(1200, 1400)

origin()
cols = diverging_palette(60, 120, 20) # hue 60 to hue 120
background(cols[1])
setopacity(0.7)
setline(2)

# circumradius of 500
ngon(0, 0, 500, 8, 0, :clip)

The documentation of the function itself can be found here.

Related