海龟绘图turtle模块

圆⚪

import turtle as t
t.circle(100)#100是圆的半径radius
t.done()

在这里插入图片描述

# -*- coding: UTF-8 -*-  @Date :2022/9/12 8:26

import turtle

# 速度
turtle.speed(0)
#颜色
turtle.color('blue')
for i in range(100):
    turtle.left(78)
    turtle.circle(i )  # 半径100像素


#两者效果一样,都是绘制完后定在屏幕上,
turtle.mainloop()
#turtle.done()

在这里插入图片描述

奥运五环

# -*- coding: UTF-8 -*-  @Date :2022/9/12 8:36
import turtle as t



t.pensize(5)# 笔的粗细
t.color('black')
t.circle(100)

t.penup()#抬笔
t.goto(-220,0)#让海龟去的位置,(x轴y轴坐标)

t.pendown()#落笔
t.color('blue')
t.circle(100)

t.penup()
t.goto(220,0)
t.pendown()
t.color('red')
t.circle(100)

t.penup()
t.goto(-120,-120)
t.pendown()
t.circle(100)
t.color('yellow')

t.penup()
t.goto(120,-120)
t.pendown()
t.circle(100)
t.color('green')


t.color('red')
t.penup()
t.goto(-150,250)
t.pendown()
#写字
t.write('北 京 欢 迎 你',font=('kaiti',32))

t.mainloop()#画面保持
  • 下图可见最后海龟写完北京欢迎你后,还留在画布上,我们可以使用t.hideturtle()隐藏海龟,
  • 隐藏后如果想显示海龟可以使用t.showturtle()方法来让海龟出现在画布上
    在这里插入图片描述

美国盾牌

# -*- coding: UTF-8 -*-  @Date :2022/9/12 8:58
import turtle as t

t.speed(0)
t.penup()
t.goto(0, -200)
t.pendown()
t.color('red')
t.begin_fill()  # 开始填充
t.circle(200)
t.end_fill()  # 结束填充

t.penup()
t.goto(0, -150)
t.pendown()
t.color('white')
t.begin_fill()
t.circle(150)
t.end_fill()

t.penup()
t.goto(0, -100)
t.pendown()
t.color('red')
t.begin_fill()
t.circle(100)
t.end_fill()

t.penup()
t.goto(0, -50)
t.pendown()
t.color('blue')
t.begin_fill()
t.circle(50)
t.end_fill()

t.penup()
t.goto(-40, 13)
t.pendown()
t.color('white')
t.begin_fill()
for i in range(5):
    t.forward(80)  # 往前走80像素
    t.right(144)
t.end_fill()
t.hideturtle()  # 隐藏海龟

t.mainloop()

在这里插入图片描述

彩旗飘飘

  • 引入了random模块,让气球出现的位置随机,气球的颜色也随机
# -*- coding: UTF-8 -*-  @Date :2022/9/12 9:12


"""
1.绘制一个气球(圆圈+直线)
2.填充随机颜色
3.出现随机位置
4.绘制画面中多个彩色气球


"""

import turtle as t
import random

t.colormode(255)  # 设置色彩模式
t.speed(0)

for i in range(20):
    red = random.randint(0, 255)
    green = random.randint(0, 255)
    blue = random.randint(0, 255)

    x = random.randint(-220, 220)
    y = random.randint(-100, 220)
    t.penup()
    t.goto(x,y)
    t.pendown()
    t.color(red, green, blue)
    t.begin_fill()
    t.circle(30)
    t.end_fill()
    t.right(90)
    t.forward(30)
    t.left(90)

t.mainloop()

在这里插入图片描述

繁星满天

  • 为了减少代码冗余,使用循环,减少代码量
  • 繁星出现的位置随机,颜色在黄色这个色域里面随机
# -*- coding: UTF-8 -*-  @Date :2022/9/12 9:29
import  random
import turtle as t
t.speed(0)
t.colormode(255)

t.bgcolor('black')  # 画布背景色
t.pensize(100)

# t.goto(-300,500)
# t.forward(600)

# t.color(50,50,50)
# t.penup()
# t.goto(-400,280)
# t.pendown()
# t.forward(900)
#
# t.color(75,75,75)
# t.penup()
# t.goto(-400,180)
# t.pendown()
# t.forward(900)
#
# t.color(110,110,100)
# t.penup()
# t.goto(-400,80)
# t.pendown()
# t.forward(900)
#
# t.color(125,125,125)
# t.penup()
# t.goto(-400,-20)
# t.pendown()
# t.forward(900)
#
# t.color(150,150,150)
# t.penup()
# t.goto(-400,-120)
# t.pendown()
# t.forward(900)
#
# t.color(175,175,175)
# t.penup()
# t.goto(-400,-220)
# t.pendown()
# t.forward(900)
#
# t.color(150,150,150)
# t.penup()
# t.goto(-400,-320)
# t.pendown()
# t.forward(900)

color_total=50
position=280

color_add=25
goto_jian=100
for i in range(7):
    t.color(color_total,color_total,color_total)
    t.penup()
    t.goto(-400,position)
    t.pendown()
    t.forward(900)
    color_total += color_add
    position-=goto_jian



#画星星
t.pensize(3)

for i in range(7):
    red=random.randint(180,255)
    green=random.randint(180,255)
    blue=0
    t.color(red,green,blue)
    x=random.randint(-200,200)
    y=random.randint(0,250)
    t.penup()
    t.goto(x,y)
    t.pendown()

    l=random.randint(10,20)
    t.begin_fill()
    for i in range(4):
        t.forward(l)
        t.left(30)
        t.forward(l)
        t.right(120)
        t.hideturtle()
    t.end_fill()
    t.left(30)




t.mainloop()

在这里插入图片描述

太阳花

# -*- coding: UTF-8 -*-  @Date :2022/9/12 10:21

import  turtle as t
t.penup()
t.goto(-100,0)
t.pendown()
t.color('red','yellow')
t.speed(10)
t.begin_fill()
for i in range(50):
    t.fd(200)     #t.forward()
    t.right(170)

t.end_fill()

t.done()

在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

过期的秋刀鱼-

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

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

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

打赏作者

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

抵扣说明:

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

余额充值