用Python海归作图 |
您所在的位置:网站首页 › 椭圆怎么画最简单方法 › 用Python海归作图 |
想必大家都想过用Python中的turtle画出椭圆吧,自己思考了许久,终于琢磨着画出了椭圆,但是我不知道这个方法是不是最简单的,是不是正确的,如果有错误请指正,如果觉得好用就尽管拿去用,哈哈哈 代码如下: import turtle def half_a(x): a = x b = 90 while True: turtle.circle(a, 1) a = a - x / 100 b = b - 1 if b == 0: break def half_b(x): a = x * 0.1 b = 90 while True: turtle.circle(a, 1) a = a + x / 100 b = b - 1 if b == 0: break def ellipse(x): turtle.speed(0) #设置画笔速度 turtle.color("red") #设置画笔颜色 turtle.pensize(1) #设置画笔粗细 half_a(x) half_b(x) half_a(x) half_b(x) turtle.hideturtle() # 隐藏箭头显示 ellipse(100) #可根据自己的需要改变这个值 turtle.mainloop()运行效果: 运行效果: |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |