千帆共进-python-turtle库画图

背景图必须是gif格式
小船从右侧移动到左侧,小船数量、大小、移动速度随机生成
请添加图片描述

from turtle import *
import turtle as t
from random import *

t.setup(800, 800,0,0)
# t.bgpic(r"D:\Users\86180\PycharmProjects\myPictures\ig.gif")
t.pencolor("blue")
t.pensize(1)
t.speed(10)

t.pendown()

t.pensize(5)
t.penup()
t.left(90)
t.forward(250)

t.left(155)
t.pendown()
t.fd(200)

t.left(135)
t.fd(200)

t.left(112)
t.fd(150)
t.penup()
t.right(155)
t.fd(50)

t.left(270)
t.pendown()
t.fd(200)

t.left(135)
t.fd(200)

t.left(112)
t.fd(150)

t.penup()

t.left(100)
t.fd(325)

# right(90)
t.pendown()
t.left(145)
t.fd(350)
t.right(165)
t.fd(300)

t.right(65)
t.fd(100)

t.right(75)
t.penup()
t.fd(250)

t.pendown()
t.circle(20)

t.penup()
t.goto(220,20)


t.pendown()
t.circle(225)
width, height = 800, 800
screen = Screen()
screen.setup(width, height,0,0)
screen.delay(0)

class Heart:
    def __init__(self, x, y, size):
        self.size = size
        self.speed = size    # 移动速度根据大小变化
        print(size)
        t = Turtle(visible=False, shape='arrow')
        t.shapesize(size, size)
        color = (0.2,0.2, (1-size/5))     # 颜色修改为根据大小变化
        t.pencolor(color)
        t.fillcolor(color)
        t.penup()

        self.circle1 = t.clone()
        self.circle1.goto(x, y)
        self.circle2 = t.clone()
        self.circle2.goto(x-size/2, y-size*10)
        self.circle2.setheading(-90)
        self.circle1.showturtle()
        self.circle2.showturtle()


    def move(self):
        self.circle1.setx(self.circle1.xcor()-self.speed)
        self.circle2.setx(self.circle2.xcor() - self.speed)


hearts = []
for i in range(40):
    heart = Heart(width/2 + randint(1, width), randint(-height/2,height/2), random()*3)
    hearts.append(heart)

while True:
    for heart in hearts:
        heart.move()

t.exitonclick()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值