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

Python繪制燈籠的示例代碼

 更新時(shí)間:2022年02月18日 09:53:29   作者:阿黎逸陽(yáng)  
這篇文章主要為大家介紹了如何通過(guò)Python繪制一個(gè)燈籠,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)Python有一定幫助,感興趣的小伙伴可以跟隨小編學(xué)習(xí)一下

一年一度的元宵節(jié)剛剛過(guò)去,由于時(shí)間關(guān)系,在元宵節(jié)當(dāng)天晚上11點(diǎn)多才完成本文燈籠的繪制。這兩天又在忙著別的事情,所以現(xiàn)在才跟大家分享。

一、效果展示

在介紹代碼之前,先來(lái)看下本文的實(shí)現(xiàn)效果。

視頻鏈接

二、代碼展示

接下來(lái)展示繪制燈籠的全量源代碼

import os
import pygame
import turtle as t 


##畫(huà)外輪廓
t.title('元宵節(jié)字謎燈籠')
t.setup(startx=0, starty = 0)
#畫(huà)燈籠提線(xiàn)
t.penup()
t.goto(-50, 180)
t.pendown()
t.left(100)
t.pensize(2)
t.color('orangered')
t.circle(-15, 80)
t.right(140)
t.forward(20)
#畫(huà)燈籠蓋
t.penup()
t.goto(-57, 179)
t.pendown()
t.left(120)
t.pensize(1)
#t.pencolor('gold')
t.pencolor('#fedf08')
t.fillcolor('#fedf08')
#t.pencolor('orange')
t.begin_fill()
t.forward(14)
t.right(15)
t.forward(20)
t.right(165)
t.forward(52)
t.goto(-57, 179)
t.end_fill()
t.penup()
t.goto(-78, 174)
t.pendown()
t.left(135)
t.pencolor('#feb209')
t.fillcolor('#feb209')
t.begin_fill()
t.forward(5)
t.left(45)
t.forward(47)
t.goto(-22, 174)
t.end_fill()
#紅色的柱子
t.penup()
t.goto(-70, 170)
t.pendown()
t.color('red')
t.begin_fill()
t.right(90)
t.forward(10)
t.left(90)
t.forward(40)
t.left(90)
t.forward(10)
t.end_fill()
def zz(x):
    t.penup()
    t.color('#feb209')
    t.pensize(1)
    t.begin_fill()
    t.goto(x, 160)
    t.forward(10)
    t.right(90)
    t.forward(3)
    t.right(90)
    t.forward(10)
    t.right(90)
    t.forward(3)
    t.end_fill()
    t.right(90)
zz(-64)  #第一根柱子
zz(-55)  #第二根柱子
zz(-45)  #第三根柱子
zz(-37)  #第四根柱子
#棕色的柱子
t.penup()
t.goto(-74, 160)
t.pendown()
t.color('#7f4e1e')
t.left(90)
t.begin_fill()
t.circle(2, 90)
t.forward(5)
t.left(90)
t.forward(52)
t.left(90)
t.forward(5)
t.circle(2, 90)
t.forward(50)
t.end_fill()

#燈籠外殼
t.penup()
t.goto(-76, 153)
t.pendown()
t.begin_fill()
t.color('orangered')
t.circle(30, 90)
t.forward(70)
t.circle(30,90)
t.forward(52)
t.circle(30, 90)
t.forward(70)
t.circle(30, 90)
t.end_fill()
#棕色的柱子
t.penup()
t.goto(-74, 23)
t.pendown()
t.color('#7f4e1e')
#t.left(90)
t.begin_fill()
t.circle(2, 90)
t.forward(5)
t.left(90)
t.forward(52)
t.left(90)
t.forward(5)
t.circle(2, 90)
t.forward(50)
t.end_fill()
#黃色的線(xiàn)
t.penup()
t.goto(-50, 15)
t.pendown()
t.left(90)
t.color('yellow')
t.pensize(1)
t.forward(25)
#玫紅色的球
t.right(90)
t.color('red')
t.begin_fill()
t.circle(8, 360)
t.end_fill()
#畫(huà)流蘇
t.penup()
t.goto(-50, -26)
t.pendown()
t.begin_fill()
t.color('orangered')
t.circle(9, 90)
t.forward(80)
t.left(90)
t.forward(18)
t.left(90)
t.forward(80)
t.circle(9, 90)
t.end_fill()
#畫(huà)流蘇中黃色的圈
t.penup()
t.goto(-59, -42)
t.left(90)
t.pendown()
t.begin_fill()
t.color('#fedf08')
t.forward(10)
t.left(90)
t.forward(18)
t.left(90)
t.forward(10)
t.left(90)
t.forward(18)
t.end_fill()

#中文
t.hideturtle()
t.penup()
t.goto(-72, 120)
t.pendown()
t.pencolor('black')
#t.write('猜謎語(yǔ)', font=('Times New Roman', 12, 'normal'))
t.write('猜燈謎', font=('Comic Sans', 11, 'normal'))
t.penup()
t.goto(-87, 91)
t.pendown()
t.pencolor('black')
#t.write('猜謎語(yǔ)', font=('Times New Roman', 12, 'normal'))
t.write('云 蓋 中 秋 月', font=('Times New Roman', 10, 'normal'))
t.penup()
t.goto(-87, 65)
t.pendown()
t.pencolor('black')
#t.write('猜謎語(yǔ)', font=('Times New Roman', 12, 'normal'))
t.write('雨 淋 元 宵 燈', font=('Times New Roman', 10, 'normal'))
t.penup()
t.goto(-84, 40)
t.pendown()
t.pencolor('black')
#t.write('猜謎語(yǔ)', font=('Times New Roman', 12, 'normal'))
t.write('(打 一 成 語(yǔ))', font=('Times New Roman', 10, 'normal'))
t.delay(50)
def write_1():
    #元
    t.penup()
    t.goto(90, 150)
    t.pendown()
    t.pensize(8)
    t.pencolor('red')
    #t.write('猜謎語(yǔ)', font=('Times New Roman', 12, 'normal'))
    t.write('共', font=('Times New Roman', 18, 'normal'))
    #宵
    t.penup()
    t.goto(90, 120)
    t.pendown()
    t.pensize(8)
    t.pencolor('red')
    #t.write('猜謎語(yǔ)', font=('Times New Roman', 12, 'normal'))
    t.write('飲', font=('Times New Roman', 18, 'normal'))
    #節(jié)
    t.penup()
    t.goto(90, 90)
    t.pendown()
    t.pensize(8)
    t.pencolor('red')
    #t.write('猜謎語(yǔ)', font=('Times New Roman', 12, 'normal'))
    t.write('太', font=('Times New Roman', 18, 'normal'))
    #快
    t.penup()
    t.goto(90, 60)
    t.pendown()
    t.pensize(8)
    t.pencolor('red')
    #t.write('猜謎語(yǔ)', font=('Times New Roman', 12, 'normal'))
    t.write('平', font=('Times New Roman', 18, 'normal'))
    #樂(lè)
    t.penup()
    t.goto(90, 30)
    t.pendown()
    t.pensize(8)
    t.pencolor('red')
    #t.write('猜謎語(yǔ)', font=('Times New Roman', 12, 'normal'))
    t.write('酒', font=('Times New Roman', 18, 'normal'))
def write_2():
    #元
    t.penup()
    t.goto(150, 150)
    t.pendown()
    t.pensize(8)
    t.pencolor('red')
    #t.write('猜謎語(yǔ)', font=('Times New Roman', 12, 'normal'))
    t.write('同', font=('Times New Roman', 18, 'normal'))
    #宵
    t.penup()
    t.goto(150, 120)
    t.pendown()
    t.pensize(8)
    t.pencolor('red')
    #t.write('猜謎語(yǔ)', font=('Times New Roman', 12, 'normal'))
    t.write('猜', font=('Times New Roman', 18, 'normal'))
    #節(jié)
    t.penup()
    t.goto(150, 90)
    t.pendown()
    t.pensize(8)
    t.pencolor('red')
    #t.write('猜謎語(yǔ)', font=('Times New Roman', 12, 'normal'))
    t.write('元', font=('Times New Roman', 18, 'normal'))
    #快
    t.penup()
    t.goto(150, 60)
    t.pendown()
    t.pensize(8)
    t.pencolor('red')
    #t.write('猜謎語(yǔ)', font=('Times New Roman', 12, 'normal'))
    t.write('宵', font=('Times New Roman', 18, 'normal'))
    #樂(lè)
    t.penup()
    t.goto(150, 30)
    t.pendown()
    t.pensize(8)
    t.pencolor('red')
    #t.write('猜謎語(yǔ)', font=('Times New Roman', 12, 'normal'))
    t.write('謎', font=('Times New Roman', 18, 'normal'))
write_1()
write_1()
write_1()
write_2()
write_2()
write_2()
t.penup()
t.goto(-280, -200)
t.pendown()
t.pensize(8)
t.pencolor('red')
#t.write('猜謎語(yǔ)', font=('Times New Roman', 12, 'normal'))
t.write('Happy Lantern Festival !', font=('Times New Roman', 15, 'normal'))

三、拓展

下面將展示帶有背景音樂(lè)的繪制燈籠的示例代碼,有需要的可以參考一下

import os
import pygame
import turtle as t 

#播放音樂(lè)
pygame.mixer.init()
pygame.mixer.music.load(r"F:\公眾號(hào)\48.元宵節(jié)快樂(lè)\Sing, R. Sing! - おばちゃ!.mp3") 
pygame.mixer.music.set_volume(0.5) 
pygame.mixer.music.play()
##畫(huà)外輪廓
t.title('元宵節(jié)字謎燈籠')
t.setup(startx=0, starty = 0)
#畫(huà)燈籠提線(xiàn)
t.penup()
t.goto(-50, 180)
t.pendown()
t.left(100)
t.pensize(2)
t.color('orangered')
t.circle(-15, 80)
t.right(140)
t.forward(20)
#畫(huà)燈籠蓋
t.penup()
t.goto(-57, 179)
t.pendown()
t.left(120)
t.pensize(1)
#t.pencolor('gold')
t.pencolor('#fedf08')
t.fillcolor('#fedf08')
#t.pencolor('orange')
t.begin_fill()
t.forward(14)
t.right(15)
t.forward(20)
t.right(165)
t.forward(52)
t.goto(-57, 179)
t.end_fill()
t.penup()
t.goto(-78, 174)
t.pendown()
t.left(135)
t.pencolor('#feb209')
t.fillcolor('#feb209')
t.begin_fill()
t.forward(5)
t.left(45)
t.forward(47)
t.goto(-22, 174)
t.end_fill()
#紅色的柱子
t.penup()
t.goto(-70, 170)
t.pendown()
t.color('red')
t.begin_fill()
t.right(90)
t.forward(10)
t.left(90)
t.forward(40)
t.left(90)
t.forward(10)
t.end_fill()
def zz(x):
    t.penup()
    t.color('#feb209')
    t.pensize(1)
    t.begin_fill()
    t.goto(x, 160)
    t.forward(10)
    t.right(90)
    t.forward(3)
    t.right(90)
    t.forward(10)
    t.right(90)
    t.forward(3)
    t.end_fill()
    t.right(90)
zz(-64)  #第一根柱子
zz(-55)  #第二根柱子
zz(-45)  #第三根柱子
zz(-37)  #第四根柱子
#棕色的柱子
t.penup()
t.goto(-74, 160)
t.pendown()
t.color('#7f4e1e')
t.left(90)
t.begin_fill()
t.circle(2, 90)
t.forward(5)
t.left(90)
t.forward(52)
t.left(90)
t.forward(5)
t.circle(2, 90)
t.forward(50)
t.end_fill()

#燈籠外殼
t.penup()
t.goto(-76, 153)
t.pendown()
t.begin_fill()
t.color('orangered')
t.circle(30, 90)
t.forward(70)
t.circle(30,90)
t.forward(52)
t.circle(30, 90)
t.forward(70)
t.circle(30, 90)
t.end_fill()
#棕色的柱子
t.penup()
t.goto(-74, 23)
t.pendown()
t.color('#7f4e1e')
#t.left(90)
t.begin_fill()
t.circle(2, 90)
t.forward(5)
t.left(90)
t.forward(52)
t.left(90)
t.forward(5)
t.circle(2, 90)
t.forward(50)
t.end_fill()
#黃色的線(xiàn)
t.penup()
t.goto(-50, 15)
t.pendown()
t.left(90)
t.color('yellow')
t.pensize(1)
t.forward(25)
#玫紅色的球
t.right(90)
t.color('red')
t.begin_fill()
t.circle(8, 360)
t.end_fill()
#畫(huà)流蘇
t.penup()
t.goto(-50, -26)
t.pendown()
t.begin_fill()
t.color('orangered')
t.circle(9, 90)
t.forward(80)
t.left(90)
t.forward(18)
t.left(90)
t.forward(80)
t.circle(9, 90)
t.end_fill()
#畫(huà)流蘇中黃色的圈
t.penup()
t.goto(-59, -42)
t.left(90)
t.pendown()
t.begin_fill()
t.color('#fedf08')
t.forward(10)
t.left(90)
t.forward(18)
t.left(90)
t.forward(10)
t.left(90)
t.forward(18)
t.end_fill()

#中文
t.hideturtle()
t.penup()
t.goto(-72, 120)
t.pendown()
t.pencolor('black')
#t.write('猜謎語(yǔ)', font=('Times New Roman', 12, 'normal'))
t.write('猜燈謎', font=('Comic Sans', 11, 'normal'))
t.penup()
t.goto(-87, 91)
t.pendown()
t.pencolor('black')
#t.write('猜謎語(yǔ)', font=('Times New Roman', 12, 'normal'))
t.write('云 蓋 中 秋 月', font=('Times New Roman', 10, 'normal'))
t.penup()
t.goto(-87, 65)
t.pendown()
t.pencolor('black')
#t.write('猜謎語(yǔ)', font=('Times New Roman', 12, 'normal'))
t.write('雨 淋 元 宵 燈', font=('Times New Roman', 10, 'normal'))
t.penup()
t.goto(-84, 40)
t.pendown()
t.pencolor('black')
#t.write('猜謎語(yǔ)', font=('Times New Roman', 12, 'normal'))
t.write('(打 一 成 語(yǔ))', font=('Times New Roman', 10, 'normal'))
t.delay(50)
def write_1():
    #元
    t.penup()
    t.goto(90, 150)
    t.pendown()
    t.pensize(8)
    t.pencolor('red')
    #t.write('猜謎語(yǔ)', font=('Times New Roman', 12, 'normal'))
    t.write('共', font=('Times New Roman', 18, 'normal'))
    #宵
    t.penup()
    t.goto(90, 120)
    t.pendown()
    t.pensize(8)
    t.pencolor('red')
    #t.write('猜謎語(yǔ)', font=('Times New Roman', 12, 'normal'))
    t.write('飲', font=('Times New Roman', 18, 'normal'))
    #節(jié)
    t.penup()
    t.goto(90, 90)
    t.pendown()
    t.pensize(8)
    t.pencolor('red')
    #t.write('猜謎語(yǔ)', font=('Times New Roman', 12, 'normal'))
    t.write('太', font=('Times New Roman', 18, 'normal'))
    #快
    t.penup()
    t.goto(90, 60)
    t.pendown()
    t.pensize(8)
    t.pencolor('red')
    #t.write('猜謎語(yǔ)', font=('Times New Roman', 12, 'normal'))
    t.write('平', font=('Times New Roman', 18, 'normal'))
    #樂(lè)
    t.penup()
    t.goto(90, 30)
    t.pendown()
    t.pensize(8)
    t.pencolor('red')
    #t.write('猜謎語(yǔ)', font=('Times New Roman', 12, 'normal'))
    t.write('酒', font=('Times New Roman', 18, 'normal'))
def write_2():
    #元
    t.penup()
    t.goto(150, 150)
    t.pendown()
    t.pensize(8)
    t.pencolor('red')
    #t.write('猜謎語(yǔ)', font=('Times New Roman', 12, 'normal'))
    t.write('同', font=('Times New Roman', 18, 'normal'))
    #宵
    t.penup()
    t.goto(150, 120)
    t.pendown()
    t.pensize(8)
    t.pencolor('red')
    #t.write('猜謎語(yǔ)', font=('Times New Roman', 12, 'normal'))
    t.write('猜', font=('Times New Roman', 18, 'normal'))
    #節(jié)
    t.penup()
    t.goto(150, 90)
    t.pendown()
    t.pensize(8)
    t.pencolor('red')
    #t.write('猜謎語(yǔ)', font=('Times New Roman', 12, 'normal'))
    t.write('元', font=('Times New Roman', 18, 'normal'))
    #快
    t.penup()
    t.goto(150, 60)
    t.pendown()
    t.pensize(8)
    t.pencolor('red')
    #t.write('猜謎語(yǔ)', font=('Times New Roman', 12, 'normal'))
    t.write('宵', font=('Times New Roman', 18, 'normal'))
    #樂(lè)
    t.penup()
    t.goto(150, 30)
    t.pendown()
    t.pensize(8)
    t.pencolor('red')
    #t.write('猜謎語(yǔ)', font=('Times New Roman', 12, 'normal'))
    t.write('謎', font=('Times New Roman', 18, 'normal'))
write_1()
write_1()
write_1()
write_2()
write_2()
write_2()
t.penup()
t.goto(-280, -200)
t.pendown()
t.pensize(8)
t.pencolor('red')
#t.write('猜謎語(yǔ)', font=('Times New Roman', 12, 'normal'))
t.write('Happy Lantern Festival !', font=('Times New Roman', 15, 'normal'))

以上就是Python繪制燈籠的示例代碼的詳細(xì)內(nèi)容,更多關(guān)于Python繪制燈籠的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • OneFlow源碼解析之Eager模式下Tensor存儲(chǔ)管理

    OneFlow源碼解析之Eager模式下Tensor存儲(chǔ)管理

    這篇文章主要為大家介紹了OneFlow源碼解析之Eager模式下Tensor的存儲(chǔ)管理實(shí)現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-04-04
  • Python實(shí)現(xiàn)獲取當(dāng)前目錄下文件名代碼詳解

    Python實(shí)現(xiàn)獲取當(dāng)前目錄下文件名代碼詳解

    這篇文章主要介紹了Python實(shí)現(xiàn)獲取當(dāng)前目錄下文件名,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-03-03
  • pandas的排序、分組groupby及cumsum累計(jì)求和方式

    pandas的排序、分組groupby及cumsum累計(jì)求和方式

    這篇文章主要介紹了pandas的排序、分組groupby及cumsum累計(jì)求和方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-05-05
  • opencv python圖像梯度實(shí)例詳解

    opencv python圖像梯度實(shí)例詳解

    這篇文章主要介紹了opencv python圖像梯度實(shí)例詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-02-02
  • Python中方法的缺省參數(shù)問(wèn)題解讀

    Python中方法的缺省參數(shù)問(wèn)題解讀

    這篇文章主要介紹了Python中方法的缺省參數(shù)問(wèn)題解讀,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-12-12
  • 如何把外網(wǎng)python虛擬環(huán)境遷移到內(nèi)網(wǎng)

    如何把外網(wǎng)python虛擬環(huán)境遷移到內(nèi)網(wǎng)

    這篇文章主要介紹了如何把外網(wǎng)python虛擬環(huán)境遷移到內(nèi)網(wǎng),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-05-05
  • 詳解python中的lambda與sorted函數(shù)

    詳解python中的lambda與sorted函數(shù)

    這篇文章主要介紹了python中的lambda與sorted函數(shù)的相關(guān)資料,幫助大家更好的理解和學(xué)習(xí)python,感興趣的朋友可以了解下
    2020-09-09
  • tensorflow之如何使用GPU而不是CPU問(wèn)題

    tensorflow之如何使用GPU而不是CPU問(wèn)題

    這篇文章主要介紹了tensorflow之如何使用GPU而不是CPU問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-05-05
  • python中編寫(xiě)config文件并及時(shí)更新的方法

    python中編寫(xiě)config文件并及時(shí)更新的方法

    在pytorch或者其他深度學(xué)習(xí)框架中,有許多超參數(shù)需要調(diào)整,包括learning_rate,training_data_path等,因此編寫(xiě)一個(gè)config文件統(tǒng)一存放這些參數(shù),方便調(diào)用/查看/修改還是很有必要,這篇文章主要介紹了python中一種編寫(xiě)config文件并及時(shí)更新的方法,需要的朋友可以參考下
    2023-02-02
  • python網(wǎng)絡(luò)爬蟲(chóng)精解之pyquery的使用說(shuō)明

    python網(wǎng)絡(luò)爬蟲(chóng)精解之pyquery的使用說(shuō)明

    PyQuery是一個(gè)類(lèi)似于jQuery的解析網(wǎng)頁(yè)工具,使用lxml操作xml和html文檔,它的語(yǔ)法和jQuery很像。和XPATH,Beautiful Soup比起來(lái),PyQuery更加靈活,提供增加節(jié)點(diǎn)的class信息,移除某個(gè)節(jié)點(diǎn),提取文本信息等功能
    2021-09-09

最新評(píng)論

天长市| 辛集市| 成安县| 濮阳市| 阿克陶县| 岳池县| 游戏| 竹山县| 克拉玛依市| 乐安县| 新宁县| 驻马店市| 大庆市| 抚顺县| 临城县| 太原市| 台北市| 灵丘县| 奇台县| 泽州县| 水城县| 罗定市| 普陀区| 清河县| 贡嘎县| 虞城县| 长兴县| 山阳县| 澜沧| 曲沃县| 盐源县| 洛阳市| 淅川县| 公主岭市| 克东县| 拉萨市| 温州市| 贵德县| 重庆市| 宜兴市| 阆中市|