当前位置: 首页 > news >正文

Python绘画案例2——用Python写动态小人发射爱心~~,包含源码

Python绘画案例2——用Python写动态小人发射爱心,包含源码

写在开始

这个Python专栏大概会出一百多个绘画作品,大家有喜欢的收藏关注一下,谢谢咯~

运行结果展示

小人发射爱心~

话不多说,展示源代码

import turtle as t
import time


def draw_people(x, y):
    t.penup()
    t.goto(x, y)
    t.pendown()
    t.pensize(2)
    t.color('white')
    t.setheading(0)
    t.circle(35, 360)
    t.penup()
    t.pensize(3)
    t.setheading(90)
    t.fd(45)
    t.setheading(180)
    t.fd(20)
    t.setheading(0)
    t.fd(35)
    t.pendown()
    t.circle(4, 360)
    t.penup()
    t.goto(x, y)
    t.pensize(2)
    t.setheading(0)
    t.fd(20)
    t.setheading(90)
    t.fd(20)
    t.setheading(-90)
    t.pendown()
    t.circle(5, 180)
    t.penup()
    t.goto(x, y)
    t.setheading(-90)
    t.pendown()
    t.fd(20)
    t.setheading(0)
    t.fd(35)
    t.setheading(60)
    t.fd(10)
    t.penup()
    t.goto(x, y)
    t.setheading(-90)
    t.pendown()
    t.fd(40)
    t.setheading(0)
    t.fd(35)
    t.setheading(-60)
    t.fd(10)
    t.penup()
    t.goto(x, y)
    t.setheading(-90)
    t.pendown()
    t.fd(60)
    t.setheading(-135)
    t.fd(60)
    t.bk(60)
    t.setheading(-45)
    t.fd(30)
    t.setheading(-135)
    t.fd(35)
    t.penup()


def draw_heart(size):
    t.color('pink', 'pink')
    t.pensize(2)
    t.pendown()
    t.setheading(150)
    t.begin_fill()
    t.fd(size)
    t.circle(size * -3.745, 45)
    t.circle(size * -1.431, 165)
    t.left(120)
    t.circle(size * -1.431, 165)
    t.circle(size * -3.745, 45)
    t.fd(size)
    t.end_fill()


def draw():
    t.speed(10.4)
    draw_people(-250, 20)
    t.penup()
    t.goto(-150, -30)
    draw_heart(14)
    t.penup()
    t.goto(-20, -60)
    draw_heart(25)
    t.penup()
    t.goto(205, -100)
    draw_heart(43)
    t.hideturtle()
    time.sleep(2)


if __name__ == '__main__':
    t.setup(1.0, 1.0)
    t.title("爱心发射")
    t.bgcolor('black')
    draw()
    t.done()









相关文章:

  • C++ 类和对象(友元、内部类、匿名对像)
  • c++第一课(基础c)
  • 【Python爬虫(55)】Scrapy进阶:深入剖析下载器与下载中间件
  • 服务器系统都更新到windowsserver2025了
  • 完美解决:.vmx 配置文件是由 VMware 产品创建,但该产品与此版 VMware Workstation 不兼容
  • 如何将 Excel 数据转换为 SQL 脚本:从入门到实战
  • 机器学习---KNN算法核心原理和思路分析
  • 【2025深度学习环境搭建-1】在Win11上用WSL2和Docker解锁GPU加速
  • 2023 年 6 月大学英语四级考试真题(第 3 套)——解析版
  • 《Kali Linux从安装到武器化配置:打造你的数字军火库》
  • Qt常用控件之进度条QProgressBar
  • 调试无痛入手
  • 柠檬水找零(力扣860)
  • Mybatis-Plus使用page类实现分页查询
  • 基础dp——动态规划
  • AIGC-Stable Diffusion模型介绍
  • 数据库高安全—openGauss安全整体架构安全认证
  • GEE | 基于Landsat的1984-2024年归一化水体指数NDWI分析
  • 网络传输的七层协议
  • 7. 数组的动态创建
  • 宋徽宗《芙蓉锦鸡图》亮相,故宫首展历代动物绘画
  • 五一“拼假”催热超长假期,热门酒店民宿一房难求
  • 习近平在上海考察时强调,加快建成具有全球影响力的科技创新高地
  • 韩国下届大选执政党初选4进2结果揭晓,金文洙、韩东勋胜出
  • 路边“僵尸车”被人以1450元卖了,嫌疑人被刑拘
  • 香港警务处高级助理处长叶云龙升任警务处副处长(行动)