#用循环画一个正多边形
def setup():
size(1000,1000)
def draw():
pushMatrix()
polygon(45,20)#多边形,边数,边长,可改参数
popMatrix()
polygon1(45,100)#多边形,边数,到原点的距离,可改参数
def polygon(sides,sl):
translate(width/3,height/3)
step1=radians(360/2/sides)
step2=radians(360/sides)
r=sl/2/sin(step1)#顶点到原点的距离
circle(0,0,2*r)#外接圆0,0是圆心坐标,2*r是直径
beginShape()
for i in range(sides):
vertex(r*cos(step2*i),r*sin(step2*i))#给定顶点坐标作图
endShape(CLOSE)
for i in range(sides):
line(0,0,r*cos(step2*i),r*sin(step2*i))#画远点到顶点的连线
def polygon1(sides,r):
translate(width*2/3,height*2/3)
step=radians(360/sides)
circle(0,0,2*r)#外接圆0,0是圆心坐标,2*r是直径
beginShape()
for i in range(sides):
vertex(r*cos(step*i),r*sin(step*i))#给定顶点坐标作图
endShape(CLOSE)
for i in range(sides):
line(0,0,r*cos(step*i),r*sin(step*
processing画正多边形
于 2022-02-19 00:14:20 首次发布