# For noobs: rotating regular polygons

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

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
``````

@quezadav Nice demo. I changed it a little and added parameters to it.

``````supportedOrientations(LANDSCAPE_ANY)

function setup()
r=0 -- frame index for rotation
nbr=6
xSize=200
ySize=200
parameter.integer("xSize",20,360,200,poly)
parameter.integer("ySize",20,360,200,poly)
parameter.integer("nbr",1,20,6,poly)
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()
pol={}
ang = 2*math.pi / nbr
for a = 0, 2*math.pi, ang do
sx = math.cos(a) * xSize
sy = math.sin(a) * ySize
table.insert(pol, vec2(sx,sy))
end
end
``````

Cool.