python練習(xí)之曾經(jīng)很火的小人畫(huà)愛(ài)心表白代碼
導(dǎo)語(yǔ)
哈嘍!我是木木子,又到了今日更新時(shí)刻!
我們來(lái)看看寫(xiě)什么呢?
小編有個(gè)好兄弟最近在追妹子,跟妹子打得火熱!就差臨門(mén)一腳了,這一jio我?guī)兔ρa(bǔ)上去了!
他問(wèn)有沒(méi)有什么酷炫的表白方式,可以給人心動(dòng)的趕jio,表白的方式有許多種
今天木木子來(lái)教大家一個(gè)之前很火的小人畫(huà)愛(ài)心表白代碼!
正文
Turtle庫(kù)是python的基礎(chǔ)繪圖庫(kù),這個(gè)庫(kù)使用起來(lái)很方便,了解基礎(chǔ)的一些信息之后學(xué)起來(lái)很快是小編繪圖的首選!
首先繪制愛(ài)心
import turtle import time # 畫(huà)心形圓弧 def hart_arc(): for i in range(200): turtle.right(1) turtle.forward(2) def move_pen_position(x, y): turtle.hideturtle() # 隱藏畫(huà)筆(先) turtle.up() # 提筆 turtle.goto(x, y) # 移動(dòng)畫(huà)筆到指定起始坐標(biāo)(窗口中心為0,0) turtle.down()# 下筆 turtle.showturtle() # 顯示畫(huà)筆 # 初始化 turtle.setup(width=800, height=500) # 窗口(畫(huà)布)大小 turtle.color('red', 'pink') # 畫(huà)筆顏色 turtle.pensize(5) # 畫(huà)筆粗細(xì) turtle.speed(1) # 描繪速度 # 初始化畫(huà)筆起始坐標(biāo) move_pen_position(x=0,y=-180)# 移動(dòng)畫(huà)筆位置 turtle.left(140) # 向左旋轉(zhuǎn)140度 turtle.begin_fill() # 標(biāo)記背景填充位置 # 畫(huà)心形直線( 左下方 ) turtle.forward(224) # 向前移動(dòng)畫(huà)筆,長(zhǎng)度為224 # 畫(huà)愛(ài)心圓弧 hart_arc()# 左側(cè)圓弧 turtle.left(120) # 調(diào)整畫(huà)筆角度 hart_arc()# 右側(cè)圓弧 # 畫(huà)心形直線( 右下方 ) turtle.forward(224) turtle.end_fill() # 標(biāo)記背景填充結(jié)束位置 # 點(diǎn)擊窗口關(guān)閉程序 window = turtle.Screen() window.exitonclick()
效果如下:
其次繪制小人兒
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()
效果如下:
最后添加文字
t.write("To: 你知道我的缺點(diǎn)是什么嗎?", move=True, align="left", font=("楷體", 20, "normal"))
效果如下:
總結(jié)
好啦!這款簡(jiǎn)單的表白源碼就完成啦!喜歡的點(diǎn)點(diǎn)關(guān)注哦~
mua 你們的支持是我最大的動(dòng)力!
到此這篇關(guān)于python練習(xí)之曾經(jīng)很火的小人畫(huà)愛(ài)心表白代碼的文章就介紹到這了,更多相關(guān)python 畫(huà)愛(ài)心內(nèi)容請(qǐng)搜索本站以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持本站!
版權(quán)聲明:本站文章來(lái)源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來(lái)源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來(lái)源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來(lái),僅供學(xué)習(xí)參考,不代表本站立場(chǎng),如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。