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形状

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

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

UPC. 故里

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值