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

Python使用turtle庫繪制小豬佩奇(實例代碼)

 更新時間:2020年01月16日 09:22:36   作者:皮皮魚喲  
這篇文章主要介紹了Python使用turtle庫繪制小豬佩奇,本文通過實例代碼給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下

turtle(海龜)是Python重要的標準庫之一,它能夠進行基本的圖形繪制。turtle圖形繪制的概念誕生于1969年,成功應用于LOGO編程語言。

turtle庫繪制圖形有一個基本框架:一個小海龜在坐標系中爬行,其爬行軌跡形成了繪制圖形。剛開始繪制時,小海龜位于畫布正中央,此處坐標為(0,0),前進方向為水平右方。
在Python3系列版本安裝目錄的Lib文件夾下可以找到turtle.py文件。

下面通過代碼給大家介紹Python使用turtle庫繪制小豬佩奇,

具體代碼如下所示:

# -*- coding:utf-8 -*-
import turtle as t
import time
def main():
 t.pensize(4)
 t.hideturtle()
 t.colormode(255)
 t.color((255, 155, 192), "pink")
 t.setup(840, 500)
 t.speed(10)
 # 鼻子
 t.pu()
 t.goto(-100, 100)
 t.pd()
 t.seth(-30)
 t.begin_fill()
 a = 0.4
 for i in range(120):
  if 0 <= i < 30 or 60 <= i < 90:
   a = a + 0.08
   t.lt(3) # 向左轉(zhuǎn)3度
   t.fd(a) # 向前走a的步長
  else:
   a = a - 0.08
   t.lt(3)
   t.fd(a)
 t.end_fill()
 t.pu()
 t.seth(90)
 t.fd(25)
 t.seth(0)
 t.fd(10)
 t.pd()
 t.pencolor(255, 155, 192)
 t.seth(10)
 t.begin_fill()
 t.circle(5)
 t.color(160, 82, 45)
 t.end_fill()
 t.pu()
 t.seth(0)
 t.fd(20)
 t.pd()
 t.pencolor(255, 155, 192)
 t.seth(10)
 t.begin_fill()
 t.circle(5)
 t.color(160, 82, 45)
 t.end_fill()
 # 頭
 t.color((255, 155, 192), "pink")
 t.pu()
 t.seth(90)
 t.fd(41)
 t.seth(0)
 t.fd(0)
 t.pd()
 t.begin_fill()
 t.seth(180)
 t.circle(300, -30)
 t.circle(100, -60)
 t.circle(80, -100)
 t.circle(150, -20)
 t.circle(60, -95)
 t.seth(161)
 t.circle(-300, 15)
 t.pu()
 t.goto(-100, 100)
 t.pd()
 t.seth(-30)
 a = 0.4
 for i in range(60):
  if 0 <= i < 30 or 60 <= i < 90:
   a = a + 0.08
   t.lt(3) # 向左轉(zhuǎn)3度
   t.fd(a) # 向前走a的步長
  else:
   a = a - 0.08
   t.lt(3)
   t.fd(a)
 t.end_fill()
 # 耳朵
 t.color((255, 155, 192), "pink")
 t.pu()
 t.seth(90)
 t.fd(-7)
 t.seth(0)
 t.fd(70)
 t.pd()
 t.begin_fill()
 t.seth(100)
 t.circle(-50, 50)
 t.circle(-10, 120)
 t.circle(-50, 54)
 t.end_fill()
 t.pu()
 t.seth(90)
 t.fd(-12)
 t.seth(0)
 t.fd(30)
 t.pd()
 t.begin_fill()
 t.seth(100)
 t.circle(-50, 50)
 t.circle(-10, 120)
 t.circle(-50, 56)
 t.end_fill()
 # 眼睛
 t.color((255, 155, 192), "white")
 t.pu()
 t.seth(90)
 t.fd(-20)
 t.seth(0)
 t.fd(-95)
 t.pd()
 t.begin_fill()
 t.circle(15)
 t.end_fill()
 t.color("black")
 t.pu()
 t.seth(90)
 t.fd(12)
 t.seth(0)
 t.fd(-3)
 t.pd()
 t.begin_fill()
 t.circle(3)
 t.end_fill()
 t.color((255, 155, 192), "white")
 t.pu()
 t.seth(90)
 t.fd(-25)
 t.seth(0)
 t.fd(40)
 t.pd()
 t.begin_fill()
 t.circle(15)
 t.end_fill()
 t.color("black")
 t.pu()
 t.seth(90)
 t.fd(12)
 t.seth(0)
 t.fd(-3)
 t.pd()
 t.begin_fill()
 t.circle(3)
 t.end_fill()
 # 腮
 t.color((255, 155, 192))
 t.pu()
 t.seth(90)
 t.fd(-95)
 t.seth(0)
 t.fd(65)
 t.pd()
 t.begin_fill()
 t.circle(30)
 t.end_fill()
 # 嘴
 t.color(239, 69, 19)
 t.pu()
 t.seth(90)
 t.fd(15)
 t.seth(0)
 t.fd(-100)
 t.pd()
 t.seth(-80)
 t.circle(30, 40)
 t.circle(40, 80)
 # 身體
 t.color("red", (255, 99, 71))
 t.pu()
 t.seth(90)
 t.fd(-20)
 t.seth(0)
 t.fd(-78)
 t.pd()
 t.begin_fill()
 t.seth(-130)
 t.circle(100, 10)
 t.circle(300, 30)
 t.seth(0)
 t.fd(230)
 t.seth(90)
 t.circle(300, 30)
 t.circle(100, 3)
 t.color((255, 155, 192), (255, 100, 100))
 t.seth(-135)
 t.circle(-80, 63)
 t.circle(-150, 24)
 t.end_fill()
 # 手
 t.color((255, 155, 192))
 t.pu()
 t.seth(90)
 t.fd(-40)
 t.seth(0)
 t.fd(-27)
 t.pd()
 t.seth(-160)
 t.circle(300, 15)
 t.pu()
 t.seth(90)
 t.fd(15)
 t.seth(0)
 t.fd(0)
 t.pd()
 t.seth(-10)
 t.circle(-20, 90)
 t.pu()
 t.seth(90)
 t.fd(30)
 t.seth(0)
 t.fd(237)
 t.pd()
 t.seth(-20)
 t.circle(-300, 15)
 t.pu()
 t.seth(90)
 t.fd(20)
 t.seth(0)
 t.fd(0)
 t.pd()
 t.seth(-170)
 t.circle(20, 90)
 # 腳
 t.pensize(10)
 t.color((240, 128, 128))
 t.pu()
 t.seth(90)
 t.fd(-75)
 t.seth(0)
 t.fd(-180)
 t.pd()
 t.seth(-90)
 t.fd(40)
 t.seth(-180)
 t.color("black")
 t.pensize(15)
 t.fd(20)
 t.pensize(10)
 t.color((240, 128, 128))
 t.pu()
 t.seth(90)
 t.fd(40)
 t.seth(0)
 t.fd(90)
 t.pd()
 t.seth(-90)
 t.fd(40)
 t.seth(-180)
 t.color("black")
 t.pensize(15)
 t.fd(20)
 # 尾巴
 t.pensize(4)
 t.color((255, 155, 192))
 t.pu()
 t.seth(90)
 t.fd(70)
 t.seth(0)
 t.fd(95)
 t.pd()
 t.seth(0)
 t.circle(70, 20)
 t.circle(10, 330)
if __name__ == '__main__':
 # 畫小豬佩奇
 main()
 time.sleep(10)

執(zhí)行結(jié)果:

小豬佩奇

總結(jié)

以上所述是小編給大家介紹的Python使用turtle庫繪制小豬佩奇,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
如果你覺得本文對你有幫助,歡迎轉(zhuǎn)載,煩請注明出處,謝謝!

相關(guān)文章

  • python檢測代理ip是否有效問題

    python檢測代理ip是否有效問題

    這篇文章主要介紹了python檢測代理ip是否有效問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-08-08
  • python日期與時間戳的各種轉(zhuǎn)換示例

    python日期與時間戳的各種轉(zhuǎn)換示例

    這篇文章主要介紹了python日期與時間戳的各種轉(zhuǎn)換示例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-02-02
  • 如何在C++中調(diào)用Python

    如何在C++中調(diào)用Python

    雖然現(xiàn)在Python編程語言十分的火爆,但是實際上非要用一門語言去完成所有的任務,并不是說不可以,而是不合適。在一些特定的、對于性能要求比較高的場景,還是需要用到傳統(tǒng)的C++來進行編程的。本文將用C++的代碼去調(diào)用Python函數(shù)中實現(xiàn)的一些功能
    2021-05-05
  • 用Python實現(xiàn)插值算法

    用Python實現(xiàn)插值算法

    大家好,本篇文章主要講的是用Python實現(xiàn)插值算法,感興趣的同學趕快來看一看吧,對你有幫助的話記得收藏一下
    2022-02-02
  • 基于python框架Scrapy爬取自己的博客內(nèi)容過程詳解

    基于python框架Scrapy爬取自己的博客內(nèi)容過程詳解

    這篇文章主要介紹了基于python框架Scrapy爬取自己的博客內(nèi)容過程詳解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2019-08-08
  • python 實現(xiàn)批量替換文本中的某部分內(nèi)容

    python 實現(xiàn)批量替換文本中的某部分內(nèi)容

    今天小編就為大家分享一篇python 實現(xiàn)批量替換文本中的某部分內(nèi)容,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-12-12
  • Python函數(shù)的迭代器與生成器的示例代碼

    Python函數(shù)的迭代器與生成器的示例代碼

    這篇文章主要介紹了Python函數(shù)的迭代器與生成器的相關(guān)知識,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-06-06
  • 跟老齊學Python之坑爹的字符編碼

    跟老齊學Python之坑爹的字符編碼

    本文主要介紹了在Python2.x中的編碼問題,非常的坑爹,不過如果用python3,坑爹的編碼問題就不煩惱了。
    2014-09-09
  • Python中的隨機函數(shù)random詳解

    Python中的隨機函數(shù)random詳解

    大家好,本篇文章主要講的是Python中的隨機函數(shù)random詳解,感興趣的同學趕快來看一看吧,對你有幫助的話記得收藏一下,方便下次瀏覽
    2021-12-12
  • Python列表中存放字典遇到的問題及處理

    Python列表中存放字典遇到的問題及處理

    這篇文章主要介紹了Python列表中存放字典遇到的問題及處理,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-02-02

最新評論

鄂尔多斯市| 溧水县| 锡林浩特市| 乐山市| 河源市| 彩票| 绥德县| 宜阳县| 乡城县| 泰兴市| 南部县| 贡觉县| 霍林郭勒市| 名山县| 晋州市| 安阳县| 汝城县| 老河口市| 明星| 凤山市| 英吉沙县| 富阳市| 石楼县| 肃南| 和静县| 拉孜县| 蒙山县| 济阳县| 保康县| 铁岭市| 静海县| 得荣县| 遂川县| 义乌市| 吉木萨尔县| 龙井市| 佛学| 天水市| 陇川县| 永春县| 普兰店市|