Hi. I just wanted to share this little piece of code, based on a simple but fantastic code of dave1707 (discussion 5768). The regular polygon is created by means of its angles.
displayMode(FULLSCREEN)
function setup()
r=0 -- frame index for rotation
pol={} -- initialization of vertices' array
poly(0,0,200,6) -- polygon's vertices creation (x0,y0,radius,number of sides)
end
function draw()
background(40, 40, 50)
stroke(255)
strokeWidth(2)
pushMatrix()
translate(WIDTH/2,HEIGHT/2)
r=r+1
rotate(r)
j=#pol
for z=1,#pol do
line(pol[z].x,pol[z].y,pol[j].x,pol[j].y)
j=z
end
popMatrix()
end
function poly(x, y, radius, npoints)
ang = 2*math.pi / npoints
for a = 0, 2*math.pi, ang do
sx = x + math.cos(a) * radius
sy = y + math.sin(a) * radius
table.insert(pol, vec2(sx,sy))
end
end