用python的turtle模块实现给女票画个小心心

yipeiwu_com6年前Python基础

晚上自习无聊

正好拿自己的平板电脑用python写了个小程序,运用turtle模块画一个小心心,并在心上画女票名字的首字母缩写,单纯只为红颜一笑。

代码贴出来,很简单

import turtle
import time
def liujia():
 for i in range (200):
 turtle.right(1)
 turtle.forward(1)
turtle.color('red','pink')
turtle.pensize(2)
turtle.speed(10)
turtle.goto(0,0)

turtle.begin_fill()
turtle.left(140)
turtle.forward(112)
liujia()
turtle.left(120)
liujia()
turtle.forward(112)
turtle.end_fill()
turtle.pensize(5)
turtle.up()
turtle.goto(-50,142.7)
turtle.left(50)
turtle.down()
turtle.forward(60)
turtle.left(90)
turtle.forward(25)
turtle.up()
turtle.goto(37.5,142.7)
turtle.down()
turtle.forward(25)
turtle.up()
turtle.goto(50,142.7)
turtle.right(90)
turtle.down()
turtle.forward(60)
for i in range (20):
 turtle.right(7.8)
 turtle.forward(0.3)
turtle.forward(8)
turtle.up()
turtle.goto(100,-10)
turtle.write("I Love you")

虽然丑丑的,但是她笑了啊

代码这样应该好理解了吧,各位老铁,不要再问怎么改名字了,网上学一下turtle库怎么使用,很简单的

import turtle
import time
Name=['L','J']
def draw_circle():
  for i in range (200):
    turtle.right(1)
    turtle.forward(1)
def draw_love():
  turtle.color('red','pink')
  turtle.pensize(2)
  turtle.speed(1000)
  turtle.goto(0,0)
  turtle.begin_fill()
  turtle.left(140)
  turtle.forward(112)
  draw_circle()
  turtle.left(120)
  draw_circle()
  turtle.forward(112)
  turtle.end_fill()
def draw_name():
  turtle.pensize(5)
  turtle.up()
  turtle.goto(-50,142.7)
  if Name[0]=='L':
    turtle.left(50)
    turtle.down()
    turtle.forward(60)
    turtle.left(90)
    turtle.forward(25)
  turtle.up()
  turtle.goto(37.5,142.7)
  if Name[1]=='J':
    turtle.down()
    turtle.forward(25)
    turtle.up()
    turtle.goto(50,142.7)
    turtle.right(90)
    turtle.down()
    turtle.forward(60)
    for i in range (20):
      turtle.right(7.8)
      turtle.forward(0.3)
    turtle.forward(8)
    turtle.up()
  turtle.goto(100,-10)
  turtle.write("I Love you")


draw_love()
draw_name()

以上这篇用python的turtle模块实现给女票画个小心心就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

python pytest进阶之fixture详解

前言 学pytest就不得不说fixture,fixture是pytest的精髓所在,就像unittest中的setup和teardown一样,如果不学fixture那么使用pytes...

Python sys.path详细介绍

如何将路径“永久"添加到sys.path? sys.path是python的搜索模块的路径集,是一个list 复制代码 代码如下:['', 'C:\\WINDOWS\\system32\...

python中正则表达式的使用详解

python中正则表达式的使用详解

从学习Python至今,发现很多时候是将Python作为一种工具。特别在文本处理方面,使用起来更是游刃有余。 说到文本处理,那么正则表达式必然是一个绝好的工具,它能将一些繁杂的字符搜索或...

Python3.2中的字符串函数学习总结

Sequence Types sequence类型有六种:strings, byte sequences (bytes objects), byte arrays(bytearray o...

Python自动化运维之IP地址处理模块详解

实用的IP地址处理模块IPy 在IP地址规划中,涉及到计算大量的IP地址,包括网段、网络掩码、广播地址、子网数、IP类型等 别担心,Ipy模块拯救你。Ipy模块可以很好的辅助我们高效的...