最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python繪制的愛心樹與表白代碼(完整代碼)

 更新時(shí)間:2021年04月06日 11:26:46   作者:有趣好玩的代碼  
這篇文章主要介紹了Python繪制的愛心樹與表白代碼,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

Python給女朋友帶來的快樂

用的的開發(fā)工具為pycham,pycham也是廣泛用于做Python開發(fā)的工具。運(yùn)用的turtle庫,當(dāng)然了如果是安裝了anaconda3這個(gè)庫那更好,以為這里面有我們會(huì)做Python程序設(shè)計(jì)時(shí)用到的大部分的庫,turtle它是python中一個(gè)繪制圖像的函數(shù)庫,可以用它來繪制很多的東西,比如簡單的小黃人、玫瑰花等,這個(gè)庫也可以生說是一只馬良的神筆的吧。比如以下是為女朋友準(zhǔn)備的小小的驚喜吧。

1、愛心樹

在這里插入圖片描述

import turtle
import random

def love(x,y):#在(x,y)處畫愛心lalala
 lv=turtle.Turtle()

 lv.hideturtle()

 lv.up()

 lv.goto(x,y)#定位到(x,y)

 def curvemove():#畫圓弧
 for i in range(20):
  lv.right(10)
  lv.forward(2)
 lv.color('red','pink')

 lv.speed(100)

 lv.pensize(1)

 #開始畫愛心lalala

 lv.down()

 lv.begin_fill()

 lv.left(140)

 lv.forward(22)

 curvemove()

 lv.left(120)

 curvemove()

 lv.forward(22)

 lv.write("楊冪",font=("Arial",12,"normal"),align="center")#寫上表白的人的名字

 lv.left(140)#畫完復(fù)位

 lv.end_fill()

def tree(branchLen,t):
 if branchLen > 5:#剩余樹枝太少要結(jié)束遞歸
 if branchLen<20:

  t.color("green")

  t.pensize(random.uniform((branchLen + 5) / 4 - 2, (branchLen + 6) / 4 + 5))

  t.down()

  t.forward(branchLen)

  love(t.xcor(),t.ycor())#傳輸現(xiàn)在turtle的坐標(biāo)

  t.up()

  t.backward(branchLen)

  t.color("brown")

  return

 t.pensize(random.uniform((branchLen+5)/4-2,(branchLen+6)/4+5))

 t.down()

 t.forward(branchLen)

 # 以下遞歸

 ang=random.uniform(15,45)

 t.right(ang)

 tree(branchLen-random.uniform(12,16),t)#隨機(jī)決定減小長度

 t.left(2*ang)

 tree(branchLen-random.uniform(12,16),t)#隨機(jī)決定減小長度

 t.right(ang)

 t.up()

 t.backward(branchLen)

myWin = turtle.Screen()

t = turtle.Turtle()

t.hideturtle()

t.speed(1000)

t.left(90)

t.up()

t.backward(200)

t.down()

t.color("brown")

t.pensize(32)

t.forward(60)

tree(100,t)

myWin.exitonclick()

2、畫桃心

在這里插入圖片描述

# -*- coding:utf-8 -*-
import turtle
import time


# 畫愛心的頂部
def LittleHeart():
 for i in range(200):
 turtle.right(1)
 turtle.forward(2)


# 輸入表白的語句,默認(rèn)I Love you
love = input('請輸入表白語句,默認(rèn)為輸入為"I Love you": ')
# 輸入署名或者贈(zèng)誰,沒有不執(zhí)行
me = input('請輸入您心上人的姓名或者昵稱: ')
if love == '':
 love = 'I Love you'
# 窗口大小
turtle.setup(width=800, height=500)
# 顏色
turtle.color('red', 'pink')
# 筆粗細(xì)
turtle.pensize(5)
# 速度
turtle.speed(1)
# 提筆
turtle.up()
# 隱藏筆
turtle.hideturtle()
# 去到的坐標(biāo),窗口中心為0,0
turtle.goto(0, -180)
turtle.showturtle()
# 畫上線
turtle.down()
turtle.speed(1)
turtle.begin_fill()
turtle.left(140)
turtle.forward(224)
# 調(diào)用畫愛心左邊的頂部
LittleHeart()
# 調(diào)用畫愛右邊的頂部
turtle.left(120)
LittleHeart()
# 畫下線
turtle.forward(224)
turtle.end_fill()
turtle.pensize(5)
turtle.up()
turtle.hideturtle()
# 在心中寫字 一次
turtle.goto(0, 0)
turtle.showturtle()
turtle.color('#CD5C5C', 'pink')
# 在心中寫字 font可以設(shè)置字體自己電腦有的都可以設(shè) align開始寫字的位置
turtle.write(love, font=('gungsuh', 30,), align="center")
turtle.up()
turtle.hideturtle()
time.sleep(2)
# 在心中寫字 二次
turtle.goto(0, 0)
turtle.showturtle()
turtle.color('red', 'pink')
turtle.write(love, font=('gungsuh', 30,), align="center")
turtle.up()
turtle.hideturtle()
# 寫署名
if me != '':
 turtle.color('black', 'pink')
 time.sleep(2)
 turtle.goto(180, -180)
 turtle.showturtle()
 turtle.write(me, font=(20,), align="center", move=True)

# 點(diǎn)擊窗口關(guān)閉
window = turtle.Screen()
window.exitonclick()

3、一箭穿心

一箭穿心

import turtle


def getPosition(x, y):
 turtle.setx(x)
 turtle.sety(y)
 print(x, y)


class Pikachu:

 def __init__(self):
 self.t = turtle.Turtle()
 t = self.t
 t.pensize(3)
 t.speed(9)
 t.ondrag(getPosition)

 def noTrace_goto(self, x, y):
 self.t.penup()
 self.t.goto(x, y)
 self.t.pendown()

 def leftEye(self, x, y):
 self.noTrace_goto(x, y)
 t = self.t
 t.seth(0)
 t.fillcolor('#333333')
 t.begin_fill()
 t.circle(22)
 t.end_fill()

 self.noTrace_goto(x, y + 10)
 t.fillcolor('#000000')
 t.begin_fill()
 t.circle(10)
 t.end_fill()

 self.noTrace_goto(x + 6, y + 22)
 t.fillcolor('#ffffff')
 t.begin_fill()
 t.circle(10)
 t.end_fill()

 def rightEye(self, x, y):
 self.noTrace_goto(x, y)
 t = self.t
 t.seth(0)
 t.fillcolor('#333333')
 t.begin_fill()
 t.circle(22)
 t.end_fill()

 self.noTrace_goto(x, y + 10)
 t.fillcolor('#000000')
 t.begin_fill()
 t.circle(10)
 t.end_fill()

 self.noTrace_goto(x - 6, y + 22)
 t.fillcolor('#ffffff')
 t.begin_fill()
 t.circle(10)
 t.end_fill()

 def mouth(self, x, y):
 self.noTrace_goto(x, y)
 t = self.t

 t.fillcolor('#88141D')
 t.begin_fill()
 # 下嘴唇
 l1 = []
 l2 = []
 t.seth(190)
 a = 0.7
 for i in range(28):
  a += 0.1
  t.right(3)
  t.fd(a)
  l1.append(t.position())

 self.noTrace_goto(x, y)

 t.seth(10)
 a = 0.7
 for i in range(28):
  a += 0.1
  t.left(3)
  t.fd(a)
  l2.append(t.position())

 # 上嘴唇

 t.seth(10)
 t.circle(50, 15)
 t.left(180)
 t.circle(-50, 15)

 t.circle(-50, 40)
 t.seth(233)
 t.circle(-50, 55)
 t.left(180)
 t.circle(50, 12.1)
 t.end_fill()

 # 舌頭
 self.noTrace_goto(17, 54)
 t.fillcolor('#DD716F')
 t.begin_fill()
 t.seth(145)
 t.circle(40, 86)
 t.penup()
 for pos in reversed(l1[:20]):
  t.goto(pos[0], pos[1] + 1.5)
 for pos in l2[:20]:
  t.goto(pos[0], pos[1] + 1.5)
 t.pendown()
 t.end_fill()

 # 鼻子
 self.noTrace_goto(-17, 94)
 t.seth(8)
 t.fd(4)
 t.back(8)

 # 紅臉頰
 def leftCheek(self, x, y):
 turtle.tracer(False)
 t = self.t
 self.noTrace_goto(x, y)
 t.seth(300)
 t.fillcolor('#DD4D28')
 t.begin_fill()
 a = 2.3
 for i in range(120):
  if 0 <= i < 30 or 60 <= i < 90:
  a -= 0.05
  t.lt(3)
  t.fd(a)
  else:
  a += 0.05
  t.lt(3)
  t.fd(a)
 t.end_fill()
 turtle.tracer(True)

 def rightCheek(self, x, y):
 t = self.t
 turtle.tracer(False)
 self.noTrace_goto(x, y)
 t.seth(60)
 t.fillcolor('#DD4D28')
 t.begin_fill()
 a = 2.3
 for i in range(120):
  if 0 <= i < 30 or 60 <= i < 90:
  a -= 0.05
  t.lt(3)
  t.fd(a)
  else:
  a += 0.05
  t.lt(3)
  t.fd(a)
 t.end_fill()
 turtle.tracer(True)

 def colorLeftEar(self, x, y):
 t = self.t
 self.noTrace_goto(x, y)
 t.fillcolor('#000000')
 t.begin_fill()
 t.seth(330)
 t.circle(100, 35)
 t.seth(219)
 t.circle(-300, 19)
 t.seth(110)
 t.circle(-30, 50)
 t.circle(-300, 10)
 t.end_fill()

 def colorRightEar(self, x, y):
 t = self.t
 self.noTrace_goto(x, y)
 t.fillcolor('#000000')
 t.begin_fill()
 t.seth(300)
 t.circle(-100, 30)
 t.seth(35)
 t.circle(300, 15)
 t.circle(30, 50)
 t.seth(190)
 t.circle(300, 17)
 t.end_fill()

 def body(self):
 t = self.t

 t.fillcolor('#F6D02F')
 t.begin_fill()
 # 右臉輪廓
 t.penup()
 t.circle(130, 40)
 t.pendown()
 t.circle(100, 105)
 t.left(180)
 t.circle(-100, 5)

 # 右耳朵
 t.seth(20)
 t.circle(300, 30)
 t.circle(30, 50)
 t.seth(190)
 t.circle(300, 36)

 # 上輪廓
 t.seth(150)
 t.circle(150, 70)

 # 左耳朵
 t.seth(200)
 t.circle(300, 40)
 t.circle(30, 50)
 t.seth(20)
 t.circle(300, 35)
 # print(t.pos())

 # 左臉輪廓
 t.seth(240)
 t.circle(105, 95)
 t.left(180)
 t.circle(-105, 5)

 # 左手
 t.seth(210)
 t.circle(500, 18)
 t.seth(200)
 t.fd(10)
 t.seth(280)
 t.fd(7)
 t.seth(210)
 t.fd(10)
 t.seth(300)
 t.circle(10, 80)
 t.seth(220)
 t.fd(10)
 t.seth(300)
 t.circle(10, 80)
 t.seth(240)
 t.fd(12)
 t.seth(0)
 t.fd(13)
 t.seth(240)
 t.circle(10, 70)
 t.seth(10)
 t.circle(10, 70)
 t.seth(10)
 t.circle(300, 18)

 t.seth(75)
 t.circle(500, 8)
 t.left(180)
 t.circle(-500, 15)
 t.seth(250)
 t.circle(100, 65)

 # 左腳
 t.seth(320)
 t.circle(100, 5)
 t.left(180)
 t.circle(-100, 5)
 t.seth(220)
 t.circle(200, 20)
 t.circle(20, 70)

 t.seth(60)
 t.circle(-100, 20)
 t.left(180)
 t.circle(100, 20)
 t.seth(300)
 t.circle(10, 70)

 t.seth(60)
 t.circle(-100, 20)
 t.left(180)
 t.circle(100, 20)
 t.seth(10)
 t.circle(100, 60)

 # 橫向
 t.seth(180)
 t.circle(-100, 10)
 t.left(180)
 t.circle(100, 10)
 t.seth(5)
 t.circle(100, 10)
 t.circle(-100, 40)
 t.circle(100, 35)
 t.left(180)
 t.circle(-100, 10)

 # 右腳
 t.seth(290)
 t.circle(100, 55)
 t.circle(10, 50)

 t.seth(120)
 t.circle(100, 20)
 t.left(180)
 t.circle(-100, 20)

 t.seth(0)
 t.circle(10, 50)

 t.seth(110)
 t.circle(100, 20)
 t.left(180)
 t.circle(-100, 20)

 t.seth(30)
 t.circle(20, 50)

 t.seth(100)
 t.circle(100, 40)

 # 右側(cè)身體輪廓
 t.seth(200)
 t.circle(-100, 5)
 t.left(180)
 t.circle(100, 5)
 t.left(30)
 t.circle(100, 75)
 t.right(15)
 t.circle(-300, 21)
 t.left(180)
 t.circle(300, 3)

 # 右手
 t.seth(43)
 t.circle(200, 60)

 t.right(10)
 t.fd(10)

 t.circle(5, 160)
 t.seth(90)
 t.circle(5, 160)
 t.seth(90)

 t.fd(10)
 t.seth(90)
 t.circle(5, 180)
 t.fd(10)

 t.left(180)
 t.left(20)
 t.fd(10)
 t.circle(5, 170)
 t.fd(10)
 t.seth(240)
 t.circle(50, 30)

 t.end_fill()
 self.noTrace_goto(130, 125)
 t.seth(-20)
 t.fd(5)
 t.circle(-5, 160)
 t.fd(5)

 # 手指紋
 self.noTrace_goto(166, 130)
 t.seth(-90)
 t.fd(3)
 t.circle(-4, 180)
 t.fd(3)
 t.seth(-90)
 t.fd(3)
 t.circle(-4, 180)
 t.fd(3)

 # 尾巴
 self.noTrace_goto(168, 134)
 t.fillcolor('#F6D02F')
 t.begin_fill()
 t.seth(40)
 t.fd(200)
 t.seth(-80)
 t.fd(150)
 t.seth(210)
 t.fd(150)
 t.left(90)
 t.fd(100)
 t.right(95)
 t.fd(100)
 t.left(110)
 t.fd(70)
 t.right(110)
 t.fd(80)
 t.left(110)
 t.fd(30)
 t.right(110)
 t.fd(32)

 t.right(106)
 t.circle(100, 25)
 t.right(15)
 t.circle(-300, 2)
 ##############
 # print(t.pos())
 t.seth(30)
 t.fd(40)
 t.left(100)
 t.fd(70)
 t.right(100)
 t.fd(80)
 t.left(100)
 t.fd(46)
 t.seth(66)
 t.circle(200, 38)
 t.right(10)
 t.fd(10)
 t.end_fill()

 # 尾巴花紋
 t.fillcolor('#923E24')
 self.noTrace_goto(126.82, -156.84)
 t.begin_fill()

 t.seth(30)
 t.fd(40)
 t.left(100)
 t.fd(40)
 t.pencolor('#923e24')
 t.seth(-30)
 t.fd(30)
 t.left(140)
 t.fd(20)
 t.right(150)
 t.fd(20)
 t.left(150)
 t.fd(20)
 t.right(150)
 t.fd(20)
 t.left(130)
 t.fd(18)
 t.pencolor('#000000')
 t.seth(-45)
 t.fd(67)
 t.right(110)
 t.fd(80)
 t.left(110)
 t.fd(30)
 t.right(110)
 t.fd(32)
 t.right(106)
 t.circle(100, 25)
 t.right(15)
 t.circle(-300, 2)
 t.end_fill()

 # 帽子、眼睛、嘴巴、臉頰
 self.cap(-134.07, 147.81)
 self.mouth(-5, 25)
 self.leftCheek(-126, 32)
 self.rightCheek(107, 63)
 self.colorLeftEar(-250, 100)
 self.colorRightEar(140, 270)
 self.leftEye(-85, 90)
 self.rightEye(50, 110)
 t.hideturtle()

 def cap(self, x, y):
 self.noTrace_goto(x, y)
 t = self.t
 t.fillcolor('#CD0000')
 t.begin_fill()
 t.seth(200)
 t.circle(400, 7)
 t.left(180)
 t.circle(-400, 30)
 t.circle(30, 60)
 t.fd(50)
 t.circle(30, 45)
 t.fd(60)
 t.left(5)
 t.circle(30, 70)
 t.right(20)
 t.circle(200, 70)
 t.circle(30, 60)
 t.fd(70)
 # print(t.pos())
 t.right(35)
 t.fd(50)
 t.circle(8, 100)
 t.end_fill()
 self.noTrace_goto(-168.47, 185.52)
 t.seth(36)
 t.circle(-270, 54)
 t.left(180)
 t.circle(270, 27)
 t.circle(-80, 98)

 t.fillcolor('#444444')
 t.begin_fill()
 t.left(180)
 t.circle(80, 197)
 t.left(58)
 t.circle(200, 45)
 t.end_fill()

 self.noTrace_goto(-58, 270)
 t.pencolor('#228B22')
 t.dot(35)

 self.noTrace_goto(-30, 280)
 t.fillcolor('#228B22')
 t.begin_fill()
 t.seth(100)
 t.circle(30, 180)
 t.seth(190)
 t.fd(15)
 t.seth(100)
 t.circle(-45, 180)
 t.right(90)
 t.fd(15)
 t.end_fill()
 t.pencolor('#000000')

 def start(self):
 self.body()


def main():
 print('Painting the Pikachu... ')
 turtle.screensize(800, 600)
 turtle.title('Pikachu')
 pikachu = Pikachu()
 pikachu.start()
 turtle.mainloop()


if __name__ == '__main__':
 main()

到此這篇關(guān)于Python繪制的愛心樹與表白代碼的文章就介紹到這了,更多相關(guān)python愛心樹表白代碼內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Python函數(shù)返回值實(shí)例分析

    Python函數(shù)返回值實(shí)例分析

    這篇文章主要介紹了Python函數(shù)返回值,實(shí)例分析了Python中返回一個(gè)返回值與多個(gè)返回值的方法,需要的朋友可以參考下
    2015-06-06
  • python del()函數(shù)用法

    python del()函數(shù)用法

    del用于list列表操作,刪除一個(gè)或者連續(xù)幾個(gè)元素
    2013-03-03
  • Python使用BeautifulSoup進(jìn)行XPath和CSS選擇器定位

    Python使用BeautifulSoup進(jìn)行XPath和CSS選擇器定位

    在 Python 中,BeautifulSoup 是一個(gè)常用的 HTML 和 XML 解析庫,它允許我們輕松地定位和提取網(wǎng)頁中的特定元素,本文將詳細(xì)介紹如何在 BeautifulSoup 中使用 XPath 和 CSS 選擇器定位 HTML 元素,并提供示例代碼以幫助新手理解這些概念,需要的朋友可以參考下
    2024-11-11
  • Python字符串拼接的幾種方法整理

    Python字符串拼接的幾種方法整理

    這篇文章主要介紹了Python字符串拼接的幾種方法整理的相關(guān)資料,這里提供了五種方法及實(shí)現(xiàn),需要的朋友可以參考下
    2017-08-08
  • python 魔法函數(shù)實(shí)例及解析

    python 魔法函數(shù)實(shí)例及解析

    這篇文章主要介紹了python 魔法函數(shù)實(shí)例及解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-09-09
  • Python使用paramiko連接遠(yuǎn)程服務(wù)器執(zhí)行Shell命令的實(shí)現(xiàn)

    Python使用paramiko連接遠(yuǎn)程服務(wù)器執(zhí)行Shell命令的實(shí)現(xiàn)

    這篇文章主要介紹了Python使用paramiko連接遠(yuǎn)程服務(wù)器執(zhí)行Shell命令的實(shí)現(xiàn),本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-03-03
  • Python粒子煙花動(dòng)態(tài)效果實(shí)現(xiàn)

    Python粒子煙花動(dòng)態(tài)效果實(shí)現(xiàn)

    這篇文章主要介紹了Python實(shí)現(xiàn)粒子煙花動(dòng)態(tài)效果,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧
    2023-01-01
  • python在windows調(diào)用svn-pysvn的實(shí)現(xiàn)

    python在windows調(diào)用svn-pysvn的實(shí)現(xiàn)

    本文主要介紹了python在windows調(diào)用svn-pysvn的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-02-02
  • Python生成ubuntu apt鏡像地址實(shí)現(xiàn)

    Python生成ubuntu apt鏡像地址實(shí)現(xiàn)

    本文主要介紹了Python生成ubuntu apt鏡像地址實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-05-05
  • Python3學(xué)習(xí)urllib的使用方法示例

    Python3學(xué)習(xí)urllib的使用方法示例

    本篇文章主要介紹了Python3學(xué)習(xí)urllib的使用方法示例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-11-11

最新評論

建始县| 枣强县| 建水县| 长兴县| 新余市| 南召县| 新余市| 榆社县| 文水县| 达州市| 祁门县| 合川市| 体育| 怀集县| 沁水县| 富阳市| 蒙山县| 平邑县| 师宗县| 蓬溪县| 周至县| 思茅市| 辛集市| 大厂| 邵阳县| 田林县| 明溪县| 定南县| 石门县| 百色市| 德化县| 乌兰察布市| 津市市| 和林格尔县| 神池县| 定安县| 宜都市| 喀什市| 兴和县| 镇巴县| 北京市|