python制作游戲,python海龜繪圖小豬佩奇_寶寶愛看小豬佩奇,很簡單,讓我們用python搞定它

 2023-10-08 阅读 27 评论 0

摘要:現在很多寶寶喜歡看小豬佩奇,今天就教大家用python的海龜畫圖畫一個乖巧萌萌的小豬佩奇,引導對編程產生濃濃 的興趣。 畫圖前引導 1、讓我們打開百度,輸入python進入python官網 2、在官網選擇docs菜單,在左上角選擇中文 python制作游戲。3、點擊

現在很多寶寶喜歡看小豬佩奇,今天就教大家用python的海龜畫圖畫一個乖巧萌萌的小豬佩奇,引導對編程產生濃濃 的興趣。

畫圖前引導

1、讓我們打開百度,輸入python進入python官網

2、在官網選擇docs菜單,在左上角選擇中文

python制作游戲。3、點擊右邊的標準庫參考,往下拉找到程序框架里邊的turtle--海龜繪圖,點擊進入,查看海龜繪圖的基本操作

小豬佩奇的畫圖思路

看了海龜畫圖的基本操作后,了解每個函數的基本參數設置就很簡單了

1、先畫豬鼻子

2、畫頭

python海龜庫、3、畫耳朵

4、畫眼睛

5、畫腮紅

6、畫嘴

7、畫身體

python海龜作圖,8、畫小手

9、畫腳丫

10、畫尾巴

畫豬鼻子

我們定義一個draw_nose()函數來畫豬鼻子,首先畫筆抬起,坐標移動到-100,100處,畫筆落下,設置方向,開始填充,設置一個循環畫橢圓形,停止填充,抬起畫筆等等等就不一一講解了:

Python海龜、def draw_nose():

''' 先畫鼻子'''

t.pu()

t.goto(-100, 100)

t.pd()

python創意游戲?t.seth(-30)

t.begin_fill()

a = 0.4

for i in range(120):

if 0 <= i < 30 or 60 <= i < 90:

python語言程序設計,a = a + 0.08

t.lt(3) # 向左轉3度

t.fd(a) # 向前走a的步長

else:

a = a - 0.08

python爬蟲教程?t.lt(3)

t.fd(a)

t.end_fill()

t.pu()

t.seth(90)

python編程。t.fd(25)

t.seth(0)

t.fd(10)

t.pd()

t.pencolor(255, 155, 192)

qpython?t.seth(10)

t.begin_fill()

t.circle(5)

t.color(160, 82, 45)

t.end_fill()

用python畫小豬佩奇、t.pu()

t.seth(0)

t.fd(20)

t.pd()

t.pencolor(255, 155, 192)

小豬佩奇python代碼?t.seth(10)

t.begin_fill()

t.circle(5)

t.color(160, 82, 45)

t.end_fill()

海龜程序如何在python中打開?畫豬頭

定義一個draw_head函數來畫佩奇的頭

def draw_head():

''' 畫頭'''

t.speed('normal')

小朱佩奇用什么語言編程的?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) # 向左轉3度

t.fd(a) # 向前走a的步長

else:

a = a - 0.08

t.lt(3)

t.fd(a)

t.end_fill()

畫豬耳朵

我們定義一個draw_ear()函數來畫豬耳朵:

def draw_ear():

'''畫耳朵'''

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()

畫豬眼睛

我們定義一個draw_eye()函數來畫豬眼睛:

def draw_eye():

'''畫眼睛'''

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()

畫臉上的腮紅

我們定義一個draw_face()函數來畫豬臉上的腮紅:

def draw_face():

''' 畫腮紅'''

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()

畫豬嘴

我們定義一個draw_mouth()函數來畫豬的嘴巴:

def draw_mouth():

'''畫嘴'''

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)

畫身體

我們定義一個draw_body()函數來畫佩奇的身體:

def draw_body():

'''畫身體'''

t.color("red", (218, 56, 247))

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), (218, 56, 247))

t.seth(-135)

t.circle(-80, 63)

t.circle(-150, 24)

t.end_fill()

畫佩奇的小手

我們定義一個draw_hand()函數來畫佩奇的小手:

def draw_hand():

'''畫小手'''

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)

畫腳丫

我們定義一個draw_foot()函數來畫佩奇的腳丫:

def draw_foot():

'''畫腳丫'''

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)

畫尾巴

我們定義一個draw_tail()函數來畫佩奇的尾巴:

def draw_tail():

'''畫尾巴'''

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)

t.circle(70, 30)

t.exitonclick()

主函數main()

我們先設置畫筆的大小,設置隱藏位置小海龜,設置顏色模式,設置像素大小,設置速度,然后就可以愉快的花花了。

def main():

"""主函數"""

t.pensize(4)

t.hideturtle()

t.colormode(255)

t.color((255, 155, 192), "pink")

t.setup(840, 500)

t.title('可愛的小豬佩奇')

t.speed(20)

draw_nose()

draw_head()

draw_ear()

draw_eye()

draw_face()

draw_mouth()

draw_body()

draw_hand()

draw_foot()

draw_tail()

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://808629.com/139130.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 86后生记录生活 Inc. 保留所有权利。

底部版权信息