Python学习打卡—海龟画图

Python学习第一天——turtle画国旗

由于已经有了C的基础,所以基础知识不再讲解,直接上代码!

一、画国旗背景
import turtle

#画国旗背景
turtle.up()#抬笔
turtle.goto(-200,200)#将笔移动到坐标(-200,200)
turtle.down()#开始画
turtle.begin_fill()#准备开始填充颜色
turtle.fillcolor("red")#填充颜色为红色
turtle.pencolor("red")#画笔颜色为红色
#turtle.color('red','red')

for i in range(2):
    turtle.forward(300)#向前画300像素长度
    turtle.right(90)#顺时针旋转90度
    turtle.forward(200)#向前画200像素长度
    turtle.right(90)#顺时针旋转90度
turtle.end_fill()#填充完成

turtle.forward(distance) :向当前画笔方向移动distance像素长度
turtle.right(degree) : 顺时针移动degree°
turtle.goto(x,y) : 将画笔移动到坐标为x,y的位置
turtle.penup() : 提起笔移动,不绘制图形,用于另起一个地方绘制
turtle.pendown() : 移动时绘制图形,缺省时也为绘制
turtle.begin_fill() : 准备开始填充图形
turtle.end_fill() : 填充完成
turtle.color(color1, color2) : 同时设置pencolor=color1, fillcolor=color2

二、画五角星
#画第一个大五角星
turtle.up()
turtle.goto(-170,145)
turtle.down()
turtle.begin_fill()
turtle.fillcolor("yellow")
turtle.pencolor("yellow")

for x in range(5):
    turtle.forward(45)
    turtle.right(144)
turtle.end_fill()
#第二个五角星
turtle.up()
turtle.goto(-115,175)
turtle.down()
turtle.begin_fill()
turtle.fillcolor("yellow")
turtle.pencolor("yellow")

turtle.right(30)
for x in range(5):
    turtle.forward(18)
    turtle.right(144)
turtle.end_fill()
#第三个五角星 
turtle.up()
turtle.goto(-90,157)
turtle.down()
turtle.begin_fill()
turtle.fillcolor("yellow")
turtle.pencolor("yellow")

turtle.right(30)
for x in range(5):
    turtle.forward(18)
    turtle.right(144)
turtle.end_fill()
#第四个五角星 
turtle.up()
turtle.goto(-87,130)
turtle.down()
turtle.begin_fill()
turtle.fillcolor("yellow")
turtle.pencolor("yellow")

turtle.right(30)
for x in range(5):
    turtle.forward(18)
    turtle.right(144)
turtle.end_fill()
#最后一个五角星
turtle.up()
turtle.goto(-106,106)
turtle.down()
turtle.begin_fill()
turtle.fillcolor("yellow")
turtle.pencolor("yellow")

turtle.right(30)
for x in range(5):
    turtle.forward(18)
    turtle.right(144)
turtle.end_fill()

turtle.hideturtle()#隐藏画笔形状
turtle.done()#落笔

turtle.hideturtle() : 隐藏画笔的turtle形状
turtle.showturtle() : 显示画笔的turtle形状

以下为效果图
在这里插入图片描述

发布了32 篇原创文章 · 获赞 14 · 访问量 1228

猜你喜欢

转载自blog.csdn.net/qq_45770364/article/details/104387141
今日推荐