源碼:
#!/usr/bin/env python # -*- coding:utf-8 -*- import turtle import time # 畫心形圓弧 def hart_arc(): for i in range(200): turtle.right(1) turtle.forward(2) def move_pen_position(x, y): turtle.hideturtle() # 隱藏畫筆(先) turtle.up() # 提筆 turtle.goto(x, y) # 移動(dòng)畫筆到指定起始坐標(biāo)(窗口中心為0,0) turtle.down() # 下筆 turtle.showturtle() # 顯示畫筆 # 初始化 turtle.setup(width=800, height=500) # 窗口(畫布)大小 turtle.color('red', 'pink') # 畫筆顏色 turtle.pensize(3) # 畫筆粗細(xì) turtle.speed(1) # 描繪速度 # 初始化畫筆起始坐標(biāo) move_pen_position(x=0,y=-180) # 移動(dòng)畫筆位置 turtle.left(140) # 向左旋轉(zhuǎn)140度 turtle.begin_fill() # 標(biāo)記背景填充位置 # 畫心形直線( 左下方 ) turtle.forward(224) # 向前移動(dòng)畫筆,長(zhǎng)度為224 # 畫愛心圓弧 hart_arc() # 左側(cè)圓弧 turtle.left(120) # 調(diào)整畫筆角度 hart_arc() # 右側(cè)圓弧 # 畫心形直線( 右下方 ) 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() def main(): t.pensize(2) t.color('red', 'pink') head(-120, 100, 100) heart(250, -80, 1) go_to(100, -300) t.write("To: 智慧與美貌并存的", move=True, align="left", font=("楷體", 20, "normal")) t.done() main()
效果圖:
總結(jié)
到此這篇關(guān)于利用Python如何畫一顆心、小人發(fā)射愛心的文章就介紹到這了,更多相關(guān)Python畫小人發(fā)射愛心內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
標(biāo)簽:大慶 烏蘭察布 平頂山 合肥 郴州 海南 烏蘭察布 哈爾濱
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《利用Python如何畫一顆心、小人發(fā)射愛心》,本文關(guān)鍵詞 利用,Python,如何,畫,一顆,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。