Hi all,

I want to try this, but do not want to use Pluto, is there any nice advice for me?

Hi all,

I want to try this, but do not want to use Pluto, is there any nice advice for me?

More advice: donâ€™t use Luxor for interactivity- unless you use, er, PlutoUI.

1 Like

Iâ€™ve never understood why 3.14 was chosen as â€śpi dayâ€ť when the 22nd of July, 22/7, is a better fit.

Apologies for veering off topic.

3 Likes

It is okay, it is a good logic to choose July 22nd

Maybe the code does not work, thus I do not want to use Pluto, rather use REPL instead

look at this warning and error I get for using the codes from the web above:

that is by using Plutoâ€¦

Anyway great news I manage to plot it manually without interactivity, which is all I need currently. Interactivity can wait later on. After I get 128 GB of RAM in the future hahaâ€¦

this is the working code if anyone wants to learn:

```
using Plots
gr()
function circumference_polygon(sides, radius=1.0)
# inner angle
Î± = 2Ď€ / sides
# angle between side and vertex-center line
Î˛ = (Ď€ - Î±) / 2
# using law of sines
side_length = radius * sin(Î±) / sin(Î˛)
return side_length * sides
end
function estimate_pi(sides)
circumference = circumference_polygon(sides, 1.0)
# as the circumference of the circle is 2rĎ€
return circumference / 2
end
function rotate_vector(v, Î±)
x, y = v
x2 = x * cos(Î±) - y * sin(Î±)
y2 = x * sin(Î±) + y * cos(Î±)
return (x2, y2)
end
function polygon_points(n)
start_point = (0.0, 1.0)
points = [start_point]
internal_degree = 2Ď€/n
for i in 2:n
last_point = points[end]
new_point = rotate_vector(last_point, internal_degree)
push!(points, new_point)
end
return points
end
#change the n_sides to any number you desire
n_sides = 3
pi_estimate = round(estimate_pi(n_sides), digits=5)
# plot a unit circle
plot(x -> sqrt(1 - x^2); color=:blue, aspect_ratio=1.0, legend=false)
plot!(x -> -sqrt(1 - x^2), color=:blue)
# plot the polygon
plot!(Shape(polygon_points(n_sides)), fillcolor=:green)
# annotate with sides and pi estimate
annotate!([(0, 0, ("n=$n_sides \n Ď€Ě‚=$pi_estimate", 20, :white, :center))])
```

This is not a warning but an error, and imho it is pretty clearly stated plus there are even links you can click to automatically fix things for you - just click on either â€śSplit this cell into 2 cellsâ€ť or â€śWrap all code in a begin â€¦ end blockâ€ť

Youâ€™ve wrapped most of your code in `begin ... end`

, but have another line of code (`using Plots`

) in the same cell outside `begin ... end`