用户:
天启若风查看:0 回复:1 评论:0 创建时间:2022-01-12T18:44:26
求助!
怎么画椭圆
伴雪纷飞
import turtle
import math
def ellipse(a,b,angle,steps,rotateAngle):
'''
a->轴x长度
b->轴y长度
steps->椭圆弧度
rotateAngle->椭圆斜度
'''
minAngle = (2*math.pi/360) * angle / steps
rotateAngle = rotateAngle/360*2*math.pi
turtle.penup()
turtle.setpos(b*math.sin(rotateAngle),-b*math.cos(rotateAngle))
turtle.pendown()
for i in range(steps):
nextPoint = [a*math.sin((i+1)*minAngle),-b*math.cos((i+1)*minAngle)]
nextPoint = [nextPoint[0]*math.cos(rotateAngle)-nextPoint[1]*math.sin(rotateAngle),
nextPoint[0]*math.sin(rotateAngle)+nextPoint[1]*math.cos(rotateAngle)]
turtle.setpos(nextPoint)
if __name__=='__main__':
print('help(how to use the fanction->\n',vars()['ellipse'].__doc__)
vars()['ellipse'](100,200,360,50,50)
turtle.mainloop()
点赞0
评论