使用Python画出小人发射爱心的代码

yipeiwu_com5年前Python基础

我就废话不多说了,直接上代码吧!

#2.14
from turtle import *
from time import sleep
 
def go_to(x, y):
  up()
  goto(x, y)
  down()
 
def head(x,y,r):
  go_to(x,y)
  speed(1)
  circle(r)
  leg(x,y)
 
def leg(x,y):
 
  right(90)
  forward(180)
  right(30)
  forward(100)
  left(120)
  go_to(x,y-180)
  forward(100)
  right(120)
  forward(100)
  left(120)
  hand(x,y)
 
 
def hand(x,y):
  go_to(x,y-60)
  forward(100)
  left(60)
  forward(100)
  go_to(x, y - 90)
  right(60)
  forward(100)
  right(60)
  forward(100)
  left(60)
  eye(x,y)
 
def eye(x,y):
  go_to(x-50,y+130)
  right(90)
  forward(50)
  go_to(x+40,y+130)
  forward(50)
  left(90)
 
 
def big_Circle(size):
  speed(20)
  for i in range(150):
    forward(size)
    right(0.3)
def line(size):
  speed(1)
  forward(51*size)
 
def small_Circle(size):
  speed(10)
  for i in range(210):
    forward(size)
    right(0.786)
 
 
 
def heart(x, y, size):
  go_to(x, y)
  left(150)
  begin_fill()
  line(size)
  big_Circle(size)
  small_Circle(size)
  left(120)
  small_Circle(size)
  big_Circle(size)
  line(size)
  end_fill()
 
def main():
  pensize(2)
  color('red', 'pink')
  head(-120, 100, 100)
  heart(250, -80, 1)
  go_to(200, -300)
  write("To: 智慧与美貌并存的", move=True, align="left", font=("楷体", 20, "normal"))
  done()
 
main()

运行结果:

以上这篇使用Python画出小人发射爱心的代码就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

Python multiprocessing.Manager介绍和实例(进程间共享数据)

Python中进程间共享数据,处理基本的queue,pipe和value+array外,还提供了更高层次的封装。使用multiprocessing.Manager可以简单地使用这些高级接...

python 读取视频,处理后,实时计算帧数fps的方法

实时计算每秒的帧数 cap = cv2.VideoCapture("DJI_0008.MOV") #cap = cv2.VideoCapture(0) # Define the...

Python3 中作为一等对象的函数解析

Python3 函数 函数是组织好的,可重复使用的,用来实现单一,或相关联功能的代码段。 函数能提高应用的模块性,和代码的重复利用率。你已经知道Python提供了许多内建函数,比如pr...

python3安装speech语音模块的方法

python3安装speech语音模块的方法

在windows平台上使用pyhton编写语音识别程序需要用到speech模块,speech模块支持的主要功能有:文本合成语音,将键盘输入的文本信息转换为语音信号方式输出;语音识别,将输...

Python CSV模块使用实例

举几个例子来介绍一下,Python 的 CSV模块的使用方法,包括,reader, writer, DictReader, DictWriter.register_dialect 一直非...