用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实现外卖信息管理系统

python实现外卖信息管理系统

本文为大家分享了python实现外卖信息管理系统的具体代码,供大家参考,具体内容如下 一、需求分析 需求分析包含如下: 1、问题描述 以外卖信息系统管理员身份登陆该系统,实现对店铺信...

python面向对象_详谈类的继承与方法的重载

python面向对象_详谈类的继承与方法的重载

1. 类的继承与方法的重载 上面就是先定义了一个类A,然后由定义了一个类B,B继承了类A,这样B就有了A的非私有属性和方法。 class Washer: company='...

浅谈python标准库--functools.partial

浅谈python标准库--functools.partial

一.简单介绍:  functools模块用于高阶函数:作用于或返回其他函数的函数。一般而言,任何可调用对象都可以作为本模块用途的函数来处理。  functools....

python利用hook技术破解https的实例代码

相对于http协议,http是的特点就是他的安全性,http协议的通信内容用普通的嗅探器可以捕捉到,但是https协议的内容嗅探到的是加密后的内容,对我们的利用价值不是很高,所以一些大的...

python用10行代码实现对黄色图片的检测功能

本文实例讲述了python用10行代码实现对黄色图片的检测功能。分享给大家供大家参考。具体如下: 原理:将图片转换为YCbCr模式,在图片中寻找图片色值像素,如果在皮肤色值内的像素面积超...