python教程

如何用python画月饼

python教程 51源码 2023-05-08 人阅读

1、环境安装。turtle自带所以不用单独安装。

2、创建一个月饼.py文件。

import turtle

3、定义pen函数,就是画笔。

t = turtle.Pen()

4、circle指令画出月饼形状。

for i in range(30):   #使用for循环,可以把上面的图形重复绘制多次。直到绘制成一个园。
    t.begin_fill()
    t.forward(200)    #我们让画笔t朝着箭头方向移动200像素点的距离
    t.circle(30,180)  #我们画出了一个小的弧形
    t.goto(0,0)       #我们让画笔t回到原始位置(0,0)
    t.right(180)
t.right(12)

5、给月饼上色。

import turtle
t = turtle.Pen()
t.speed(0)              # 用来控制画图的速度
turtle.colormode(255)   #告诉Python我们使用RGB来指定颜色
 
t.color((0,0,0))        #表示颜色由红色0 绿色0  蓝色0 组成巧克力颜色纯黑。
 
for i in range(30):
    t.begin_fill()
    t.forward(200)
    t.circle(30,180)
    t.goto(0,0)
    t.right(180)
    t.right(12)
    t.end_fill()      #在begin_fill() 到 end_fill() 之间的图形会填充我们指定的颜色

以上就是用python画月饼的方法,希望对大家有所帮助。更多Python学习指路:python基础教程

本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。

版权声明:文章搜集于网络,如有侵权请联系本站,转载请说明出处:https://www.51yma.cn/jiaocheng/python/1233.html
文章来源:Python学习网-https://www.py.cn//jishu/jichu/33587.html
标签 python