蓝桥杯python自学笔记

画一个正方形

代码部分

import turtle as t#导入turtle库 as t 主要是简化turtle
t.speed(10)#画笔速度设置为10
t.fillcolor("red")#填充颜色
t.begin_fill()#开始填充
t.forward(180)#四边形边长为180像素,画笔前进180像素(单位)
t.left(90)#画笔左转90度
t.forward(180)#画笔向前走180
t.goto(0,0)#起点坐标
t.end_fill()#结束填充

t.fillcolor("yellow")#填充颜色
t.begin_fill()#开始填充
t.forward(180)
t.right(90)
t.forward(180)
t.goto(0,0)#起点坐标
t.end_fill()#结束

t.hideturtle()#隐藏画笔

画一个四叶风轮

代码部分

import turtle as t#导入turtle库
import time#导入时间模块
t.shape("turtle")#画笔的形状
t.seth(0) #海龟在原点 #0,90,180,270  t.seth(x)   angles=[0,90,180,270]  for x in angles:
t.fillcolor("red") # t.fillcolor(colors[y])   
                  #四个扇叶的颜色colors = ["red","yellow","blue","green"]
t.begin_fill()
t.forward(100)#风轮的半径是100,海龟向前走100
t.right(90)#海龟右转
t.circle(-100,45)#100是指半径,45是指角度 -100表示顺时针
t.right(90)#海龟右转90
t.forward(100)#海龟向前走100
t.end_fill()#结束填充

t.seth(90)#海龟头向上在原点
t.fillcolor("blue")#填充颜色是蓝色
t.begin_fill()#开始填充
t.forward(100)
t.right(90)
t.circle(-100,45)
t.right(90)
t.forward(100)
t.end_fill()

t.seth(180)#海龟头向左
t.fillcolor("yellow")
t.begin_fill()
t.forward(100)
t.right(90)
t.circle(-100,45)#
t.right(90)
t.forward(100)
t.end_fill()

t.seth(270)#海龟头向右
t.fillcolor("green")
t.begin_fill()
t.forward(100)
t.right(90)
t.circle(-100,45)
t.right(90)
t.forward(100)
t.end_fill()

#t.setheading(0)   #海龟头向右
#time.sleep(1)     #等待1秒
#t.setheading(90)  #海龟头向上
#time.sleep(1)
#t.setheading(180)  #海龟头向左
#time.sleep(1)
#t.setheading(270)   #海龟头向下
t.down()

菱形

代码部分

import turtle as t
t.pu() #put up 的缩写,抬起画笔
t.fd(120);t.pensize(4)#fd forward的缩写,画笔前进120,画笔宽度4
t.pd();t.speed(10)#pd put down的缩写,画笔落下,多条指令写一行,中间用分号隔开
t.hideturtle()#隐藏画笔
for x in range(12):
    t.color("black","pink")#画笔颜色是黑色,填充颜色是粉色
    t.begin_fill()#开始填充
    t.left(30)#画笔左转30度
    t.fd(80)#画笔前进80,菱形的边长
    t.right(60)
    t.fd(80)
    t.right(120)
    t.fd(80)
    t.right(60)
    t.fd(80)
    t.right(60)
    t.end_fill()
    t.color("red")
    t.circle(120,360/12)#半径120,角度30度
    t.right(90)#校准一下角度
t.done()#暂停程序,停止花笔画绘制,但绘制窗体不关闭

代码仅供参考

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

kiki,

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

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

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

打赏作者

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

抵扣说明:

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

余额充值