python实现火柴人游戏_火柴人发射爱心.py

本文介绍了一段使用Python Turtle库创作的代码,通过绘制火柴人和爱心,表达对特定用户的祝福。作者展示了如何定义函数来创建火柴人的头部、腿部、手部、眼睛以及绘制不同大小的圆圈。主要技术包括路径移动、图形绘制和循环控制。
摘要由CSDN通过智能技术生成

#!/usr/bin/env python

# -*- coding:utf-8 -*-

# @File: 火柴人发射爱心.py

# Author: Chen jun

# @Time: 2019/11/2 15:54

# 来自:https://blog.csdn.net/July__July/article/details/99543992

import turtle as t

from time import sleep

def go_to(x, y):

t.up()

t.goto(x, y)

t.down()

def head(x, y, r):

go_to(x, y)

t.speed(20)

t.circle(r)

leg(x, y)

def leg(x, y):

t.right(90)

t.forward(180)

t.right(30)

t.forward(100)

t.left(120)

go_to(x, y - 180)

t.forward(100)

t.right(120)

t.forward(100)

t.left(120)

hand(x, y)

def hand(x, y):

go_to(x, y - 60)

t.forward(100)

t.left(60)

t.forward(100)

go_to(x, y - 90)

t.right(60)

t.forward(100)

t.right(60)

t.forward(100)

t.left(60)

eye(x, y)

def eye(x, y):

go_to(x - 50, y + 130)

t.right(90)

t.forward(50)

go_to(x + 40, y + 130)

t.forward(50)

t.left(90)

def big_Circle(size):

t.speed(20)

for i in range(150):

t.forward(size)

t.right(0.3)

def line(size):

t.speed(20)

t.forward(51 * size)

def small_Circle(size):

t.speed(20)

for i in range(210):

t.forward(size)

t.right(0.786)

def heart(x, y, size):

go_to(x, y)

t.left(150)

t.begin_fill()

line(size)

big_Circle(size)

small_Circle(size)

t.left(120)

small_Circle(size)

big_Circle(size)

line(size)

t.end_fill()

def main():

t.pensize(2)

t.color('red', 'pink')

head(-120, 100, 100)

heart(250, -80, 1)

go_to(100, -300)

t.write("To: 智慧与美貌并存的你", move=True, align="left", font=("楷体", 20, "normal"))

t.done()

main()

一键复制

编辑

Web IDE

原始数据

按行查看

历史

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值