当前位置: 首页 > 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. 数组的动态创建
  • 多人称华为手机忽现拍照模糊疑存缺陷,售后回应:主摄像头故障
  • 魔都眼|上海多家商场打开绿色通道,助力外贸出口商品转内销
  • 上海黄浦区拟73.2654亿元协议出让余庆里7宗组合地块
  • 青年与城市共成长,第六届上海创新创业青年50人论坛将举办
  • 上海虹桥机场至北京首都机场快线试运行跨航司自愿签转服务
  • 罗马尼亚临时总统博洛让任命普雷多尤为看守政府总理