国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Python海龜turtle基礎(chǔ)知識(shí)大全與畫(huà)圖集合

這篇具有很好參考價(jià)值的文章主要介紹了Python海龜turtle基礎(chǔ)知識(shí)大全與畫(huà)圖集合。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

Turtle圖形庫(kù)
Turtle 庫(kù)是 Python 內(nèi)置的圖形化模塊,屬于標(biāo)準(zhǔn)庫(kù)之一,位于 Python 安裝目錄的 lib 文件夾下,常用函數(shù)有以下幾種:

一.Turtle繪圖的基礎(chǔ)知識(shí)

畫(huà)布是turtle用于繪圖區(qū)域,我們可以設(shè)置它的大小和初始位置。

1.設(shè)置畫(huà)布大小

turtle.screensize(canvwidth=None, canvheight=None, bg=None),參數(shù)分別對(duì)應(yīng)畫(huà)布的寬(單位像素), 高, 背景顏色。

turtle.screensize(1000,800, "blue")

turtle.screensize() #返回默認(rèn)大小(500, 400)

turtle.setup(width=0.5, height=0.75, startx=None, starty=None)

width, height: 輸入寬和高為整數(shù)時(shí), 表示像素; 為小數(shù)時(shí), 表示占據(jù)電腦屏幕的比例,(startx, starty): 這一坐標(biāo)表示矩形窗口左上角頂點(diǎn)的位置, 如果為空,則窗口位于屏幕中心。

2.畫(huà)筆的狀態(tài)

在畫(huà)布上,默認(rèn)有一個(gè)坐標(biāo)原點(diǎn)為畫(huà)布中心的坐標(biāo)軸,坐標(biāo)原點(diǎn)上有一只面朝x軸正方向小烏龜。這里我們描述小烏龜時(shí)使用了兩個(gè)詞語(yǔ):坐標(biāo)原點(diǎn)(位置),面朝x軸正方向(方向), turtle繪圖中,就是使用位置方向描述小烏龜(畫(huà)筆)的狀態(tài)。

turtle.pensize() # 設(shè)置畫(huà)筆的寬度;

turtle.pencolor()# 沒(méi)有參數(shù)傳入,返回當(dāng)前畫(huà)筆顏色,傳入?yún)?shù)設(shè)置畫(huà)筆顏色,可以是字符串如"green", "red",也可以是RGB 3元組。

turtle.speed(speed)#設(shè)置畫(huà)筆移動(dòng)速度,畫(huà)筆繪制的速度范圍[0,10]整數(shù),數(shù)字越大越快。

3.使用turtle繪圖主要分為3種命令代碼,分別為運(yùn)動(dòng)命令、畫(huà)筆控制命令和全局控制命令。

畫(huà)筆運(yùn)動(dòng)命令代碼

turtle.forward(distance)—向當(dāng)前畫(huà)筆方向移動(dòng)distance像素長(zhǎng)度
turtle.backward(distance)—向當(dāng)前畫(huà)筆相反方向移動(dòng)distance像素長(zhǎng)度
turtle.right(degree)—順時(shí)針移動(dòng)degree° turtle.left(degree)—逆時(shí)針移動(dòng)degree°
turtle.pendown()—移動(dòng)時(shí)繪制圖形,缺省時(shí)也為繪制 turtle.goto(x,y)—將畫(huà)筆移動(dòng)到坐標(biāo)為x,y的位置
turtle.penup()—提起筆移動(dòng),不繪制圖形,用于另起一個(gè)地方繪制
turtle.circle()—畫(huà)圓,半徑為正(負(fù)),表示圓心在畫(huà)筆的左邊(右邊)畫(huà)圓 setx( )—將當(dāng)前x軸移動(dòng)到指定位置
sety( )—將當(dāng)前y軸移動(dòng)到指定位置 setheading(angle)—設(shè)置當(dāng)前朝向?yàn)閍ngle角度
home()—設(shè)置當(dāng)前畫(huà)筆位置為原點(diǎn),朝向東 dot?—繪制一個(gè)指定直徑和顏色的圓點(diǎn)
?

畫(huà)筆控制命令代碼

turtle.fillcolor(colorstring)—繪制圖形的填充顏色 turtle.color(color1,color2)—同時(shí)設(shè)置pencolor=color1, fillcolor=color2
turtle.filling()—返回當(dāng)前是否在填充狀態(tài) turtle.begin_fill()—準(zhǔn)備開(kāi)始填充圖形
turtle.end_fill()—填充完成 turtle.hideturtle()—隱藏畫(huà)筆的turtle形狀
turtle.showturtle()—顯示畫(huà)筆的turtle形狀
?

全局控制命令代碼

turtle.clear()—清空turtle窗口,但是turtle的位置和狀態(tài)不會(huì)改變
turtle.reset()—清空窗口,重置turtle狀態(tài)為起始狀態(tài) turtle.undo()—撤銷(xiāo)上一個(gè)turtle動(dòng)作
turtle.isvisible()—返回當(dāng)前turtle是否可見(jiàn) stamp()—復(fù)制當(dāng)前圖形
turtle.write(s[,font=(“fontname”,font_size,“font_type”)])—文本,s為文本內(nèi)容,font是字體的參數(shù),分別為字體名稱(chēng),大小和類(lèi)型;font為可選項(xiàng),font參數(shù)也是可選項(xiàng)
?

二.具體實(shí)例

0.櫻花樹(shù)

from turtle import *
from random import *
from math import *
def tree(n, l):
    pd ()  # 下筆
    # 陰影效果
    t = cos ( radians ( heading () + 45 ) ) / 8 + 0.25
    pencolor ( t, t, t )
    pensize ( n / 3 )
    forward ( l )  # 畫(huà)樹(shù)枝

    if n > 0:
        b = random () * 15 + 10  # 右分支偏轉(zhuǎn)角度
        c = random () * 15 + 10  # 左分支偏轉(zhuǎn)角度
        d = l * (random () * 0.25 + 0.7)  # 下一個(gè)分支的長(zhǎng)度
        # 右轉(zhuǎn)一定角度,畫(huà)右分支
        right ( b )
        tree ( n - 1, d )
        # 左轉(zhuǎn)一定角度,畫(huà)左分支
        left ( b + c )
        tree ( n - 1, d )
        # 轉(zhuǎn)回來(lái)
        right ( c )
    else:
        # 畫(huà)葉子
        right ( 90 )
        n = cos ( radians ( heading () - 45 ) ) / 4 + 0.5
        ran = random ()
        # 這里相比于原來(lái)隨機(jī)添加了填充的圓圈,讓櫻花葉子看起來(lái)更多一點(diǎn)
        if (ran > 0.7):
            begin_fill ()
            circle ( 3 )
            fillcolor ( 'pink' )
        # 把原來(lái)隨機(jī)生成的葉子換成了統(tǒng)一的粉色
        pencolor ( "pink" )
        circle ( 3 )
        if (ran > 0.7):
            end_fill ()
        left ( 90 )
        # 添加0.3倍的飄落葉子
        if (random () > 0.7):
            pu ()
            # 飄落
            t = heading ()
            an = -40 + random () * 40
            setheading ( an )
            dis = int ( 800 * random () * 0.5 + 400 * random () * 0.3 + 200 * random () * 0.2 )
            forward ( dis )
            setheading ( t )
            # 畫(huà)葉子
            pd ()
            right ( 90 )
            n = cos ( radians ( heading () - 45 ) ) / 4 + 0.5
            pencolor ( n * 0.5 + 0.5, 0.4 + n * 0.4, 0.4 + n * 0.4 )
            circle ( 2 )
            left ( 90 )
            pu ()
            # 返回
            t = heading ()
            setheading ( an )
            backward ( dis )
            setheading ( t )
    pu ()
    backward ( l )  # 退回


bgcolor ( 0.956, 0.9255, 0.9882 )  # 設(shè)置背景色(把灰色換成淡紫色)
ht ()  # 隱藏turtle
speed ( 0 )  # 速度 1-10漸進(jìn),0 最快
tracer ( 0, 0 )
pu ()  # 抬筆
backward ( 50 )
left ( 90 )  # 左轉(zhuǎn)90度
pu ()  # 抬筆
backward ( 300 )  # 后退300
tree ( 12, 100 )  # 遞歸7層
done ()

?python海龜編程代碼大全,python學(xué)習(xí),python,turtle,python繪圖,學(xué)習(xí),turtle繪圖

?參考:http://t.csdn.cn/WHTgS

?

1.彩色螺旋線(xiàn)

from turtle import *
import turtle
t = Turtle()
t.pensize(2)
turtle.bgcolor("black")
colors = ["red", "yellow", 'purple', 'blue']
t._tracer(False)
for x in range(400):
    for y in range(200):
        t.forward(x * y)
        t.color(colors[x % 4])
        t.left(91)
t._tracer(True)
done()

?

python海龜編程代碼大全,python學(xué)習(xí),python,turtle,python繪圖,學(xué)習(xí),turtle繪圖?

2.小蟒蛇?

import turtle
turtle.penup()
turtle.pencolor("blue")
turtle.forward(-200)
turtle.pendown()
turtle.pensize(10)
turtle.right(45)
for i in range(4):
    turtle.circle(40, 100)
    turtle.circle(-40, 60)
turtle.circle(40, 80 / 2)
turtle.fd(30)
turtle.circle(16, 150)
turtle.fd(100)
turtle.done()

python海龜編程代碼大全,python學(xué)習(xí),python,turtle,python繪圖,學(xué)習(xí),turtle繪圖?

?3.畫(huà)佩奇


import time
import turtle as t

t.pensize(4) # 設(shè)置畫(huà)筆的大小
t.colormode(255) # 設(shè)置GBK顏色范圍為0-255
t.color((255,155,192),"pink") # 設(shè)置畫(huà)筆顏色和填充顏色(pink)
t.setup(840,500) # 設(shè)置主窗口的大小為840*500
t.speed(10) # 設(shè)置畫(huà)筆速度為10
#鼻子
t.pu() # 提筆
t.goto(-100,100) # 畫(huà)筆前往F坐標(biāo)(-100,100)
t.pd() # 下筆
t.seth(-30) # 筆的角度為-30°
t.begin_fill() # 外形填充的開(kāi)始標(biāo)志
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的步長(zhǎng)
    else:
        a=a-0.08
        t.lt(3)
        t.fd(a)
t.end_fill() # 依據(jù)輪廓填充
t.pu() # 提筆
t.seth(90) # 筆的角度為90度
t.fd(25) # 向前移動(dòng)25
t.seth(0) # 轉(zhuǎn)換畫(huà)筆的角度為0
t.fd(10)
t.pd()
t.pencolor(255,155,192) # 設(shè)置畫(huà)筆顏色
t.seth(10)
t.begin_fill()
t.circle(5) # 畫(huà)一個(gè)半徑為5的圓
t.color(160,82,45) # 設(shè)置畫(huà)筆和填充顏色
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) # 順時(shí)針畫(huà)一個(gè)半徑為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的步長(zhǎng)
    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)
t.circle(70,30)

?python海龜編程代碼大全,python學(xué)習(xí),python,turtle,python繪圖,學(xué)習(xí),turtle繪圖

?參考:http://t.csdn.cn/fimSO

?

4.風(fēng)和日麗圖

# coding=utf-8
# code by me

# 引用海龜庫(kù)以及隨機(jī)庫(kù)
import turtle as t
import random
import time

light = t.Turtle(visible=False)
wind = t.Turtle(visible=False)


def canvas(size_x=1200, size_y=900):  # 設(shè)置畫(huà)布,有默認(rèn)值
    t.setup(size_x, size_y)


# 設(shè)置線(xiàn)的顏色以及size
def pencil(size=5, color="black"):
    t.pensize(size)
    t.pencolor(color)


def sun():  # 繪制太陽(yáng)
    light.pensize(5)
    light.pencolor("black")
    sec = int(time.time())
    t.penup()  # 畫(huà)紅色點(diǎn)
    t.goto(-530, 310)
    t.pendown()
    t.dot(100, "red")
    for i in range(1, 19):  # 陽(yáng)光效果
        light.penup()
        light.goto(-530, 310)
        light.seth(i * 20)
        light.forward(55)
        light.pendown()
        if (i + sec) % 2 == 1:
            light.forward(15)
        else:
            light.forward(7)


def plant():  # 繪制天空以及大地
    t.penup()  # 每個(gè)繪制函數(shù)開(kāi)頭都寫(xiě)了這個(gè),防止龜龜繪制另外的圖像移動(dòng)時(shí)留下痕跡
    length = 900 * 0.318  # 將畫(huà)布的縱向黃金分割
    t.home()
    t.goto(600, -450)

    t.fillcolor("#DAA520")  # 分割填充大地
    t.begin_fill()
    t.left(90)
    t.forward(length)
    t.left(90)
    t.forward(1200)
    t.left(90)
    t.forward(length)
    t.left(90)
    t.forward(1200)
    t.end_fill()

    t.home()  # 填充天空
    t.goto(600, length - 450)
    t.fillcolor("#B0C4DE")
    t.begin_fill()
    t.left(90)
    t.forward(900 - length)
    t.left(90)
    t.forward(1200)
    t.left(90)
    t.forward(900 - length)
    t.left(90)
    t.forward(1200)
    t.end_fill()


def butterfly(pos_x=0, pos_y=0):  # 繪制蝴蝶,這里會(huì)隨機(jī)生成位置以及蝴蝶大小、顏色
    light.penup()
    light.goto(pos_x, pos_y)
    light.pendown()
    light.pensize(2)
    light.seth(45)

    color = ["#FF00FF", "#87CEFA", "#0000EE", "#FF4500", "#00FF00", "#00E5EE", "#FFFAFA"]  # 一個(gè)顏色表,以及size表
    size = [6, 7, 8, 9, 10, 11, 12]
    tep_size = random.choice(size)
    light.fillcolor(random.choice(color))
    light.begin_fill()
    light.circle(tep_size, 270)  # 繪制翅膀
    light.right(135)

    light.pensize(3)
    light.forward(tep_size / 2)
    light.right(45)
    light.forward(tep_size / 2)
    light.back(tep_size / 2)
    light.left(70)
    light.forward(tep_size / 2)
    light.back(tep_size / 2)
    light.right(25)
    light.pensize(4)
    light.back(2.05 * tep_size)

    light.seth(-90)
    light.pensize(2)
    light.circle(tep_size, -180)
    light.pensize(4)
    light.left(90)
    light.forward(tep_size * 2)
    light.back(tep_size * 2.5)
    light.end_fill()


def botany(pos_x=0, pos_y=0, direction=0, flower=1, bend=10):  # 植物函數(shù),繪制向日葵,向日葵會(huì)迎風(fēng)倒,效果很到位
    light.pensize(3)
    light.pencolor("black")
    light.penup()
    light.goto(pos_x, pos_y)
    light.pendown()
    light.left(90)
    light.fillcolor("#00CD00")
    light.begin_fill()

    light.circle(50, 90)  # 繪制葉片
    light.left(90)
    light.circle(50, 90)

    light.penup()
    light.goto(pos_x, pos_y)
    light.pendown()

    light.seth(-90)
    light.pensize(6)
    light.forward(50)
    light.back(50)

    light.pensize(3)
    light.circle(50, -90)
    light.right(90)
    light.circle(50, -90)
    light.end_fill()
    if flower:  # 判斷是否有花,這里默認(rèn)有花
        light.penup()
        light.goto(pos_x, pos_y)
        light.pendown()
        light.pensize(4)
        if direction:
            light.seth(80)  # 繪制稈
            light.circle(130 - 5 * bend, 70 + 5 * bend, None)
        else:
            light.seth(-80)
            light.circle(130 - 5 * bend, -70 - 5 * bend, None)
            light.right(180)
        tep_x, tep_y = light.xcor(), light.ycor()
        light.forward(13)
        light.right(30)
        for i in range(6):  # 繪制花瓣
            light.fillcolor("#FFD700")
            light.begin_fill()
            light.circle(15, 300)
            light.left(120)
            light.end_fill()
        light.goto(tep_x, tep_y)
        light.dot(36, "#FFB90F")


def cloud(pos_x=0, pos_y=0, size=20):  # 繪制云
    pos = int(time.time())
    pos %= 50
    light.penup()  # 云沒(méi)有要邊框,所以沒(méi)有pendown
    light.goto(pos*8+pos_x, pos_y)

    light.fillcolor("#E6E6FA")
    light.begin_fill()
    light.seth(-80)
    light.circle(size, 110)
    for i in range(1, 6):  # 繪制下半部分
        light.right(100)
        light.circle(size, 110)
    light.left(120)
    for i in range(1, 7):  # 繪制上半部分,上邊進(jìn)行了六次循環(huán),但是之前就進(jìn)行了一次繪制,這里有七次循環(huán)
        light.right(100)
        light.circle(size, 110)
    light.end_fill()


# def draw(x, y):                               # 這里是之前調(diào)試用的拖拽函數(shù)響應(yīng)函數(shù),不需使用
#     t.goto(x, y)
#     print(t.xcor(), t.ycor())


# def person(pos_x=0, pos_y=0):                 # 繪制人的函數(shù),效果很拉跨,舍棄
#     t.penup()
#     t.goto(pos_x, pos_y)
#     t.pendown()
#
#     t.dot(44, "#FFDEAD")
#     t.right(90)
#     t.penup()
#     t.forward(25)
#     t.right(15)
#     t.pendown()
#     pencil(10)
#     t.forward(50)
#
#     t.right(35)
#     t.forward(50)
#     t.back(50)
#     t.left(90)
#     t.forward(27)
#     t.right(110)
#     t.forward(23)
#
#     t.penup()
#     t.goto(pos_x, pos_y)
#     t.seth(-90)
#     t.forward(25)
#     t.right(15)
#     t.forward(20)
#     t.right(60)
#     t.pendown()
#     t.forward(50)
#     tep_x1, tep_y1 = t.xcor(), t.ycor()
#     t.back(50)
#     t.right(160)
#     t.forward(30)
#     t.seth(90)
#     t.forward(20)
#
#     t.penup()
#     t.goto(tep_x1, tep_y1)
#     t.seth(-145)
#     pencil(6)
#     t.pendown()
#     t.forward(50)
#     t.right(90)
#     t.forward(20)
#     t.right(90)
#     t.forward(15)
#     t.right(90)
#     t.forward(20)
#     t.left(90)
#     t.forward(150)


def star(pos_x=0, pos_y=0, size=10):  # 繪制星星函數(shù)
    color = ["#FFFFE0", "#FFFF00"]
    light.penup()
    light.goto(pos_x, pos_y)
    angle = random.randint(0, 180)
    light.seth(angle)
    light.fillcolor(random.choice(color))
    light.begin_fill()
    for i in range(5):  # 這個(gè)144度是查的資料
        light.right(144)
        light.forward(size)
    light.end_fill()


def wind():  # 風(fēng)函數(shù),讓圖像看起來(lái)更有感覺(jué),就是一條直線(xiàn),加兩個(gè)圓
    pos = int(time.time())
    pos %= 5
    color = ["#D3D3D3", "#CDCDB4"]
    tep_color = random.choice(color)
    light.penup()
    light.goto(pos*80-1000, 50)
    light.seth(0)
    light.pendown()
    light.pensize(5)
    light.pencolor(tep_color)
    light.forward(500)
    light.pensize(4)
    light.pencolor(tep_color)
    light.left(45)
    light.circle(50, 180)
    light.pensize(3)
    light.pencolor(tep_color)
    light.circle(30, 90)

    tep_color = random.choice(color)
    light.penup()  # 畫(huà)圈圈
    light.goto(pos*140-1040, 80)
    light.seth(0)
    light.pendown()
    light.pensize(5)
    light.pencolor(tep_color)
    light.forward(400)
    light.pensize(4)
    light.pencolor(tep_color)
    light.left(45)
    light.circle(40, 180)
    light.pensize(3)
    light.pencolor(tep_color)
    light.circle(25, 90)


def lie():  # 這個(gè)函數(shù)是表達(dá)我對(duì)python的喜愛(ài)
    t.penup()
    t.goto(0, -360)
    pencil(0, "#FFA54F")
    t.write("節(jié)日快樂(lè)", align='center', font=('arial', 75, 'normal'))
    t.hideturtle()


def dynamic():
    light.clear()
    sun()
    star(200, 200)  # 右上角有星星注意觀察 0.0
    star(260, 230, 15)
    star(180, 300)
    star(300, 100, 15)
    star(500, 290)
    star(420, 310, 15)
    star(300, 200)
    star(260, 230, 15)
    star(350, 352)
    star(500, 180, 15)
    star(560, 352)
    cloud(-530, 280, 20)
    cloud(300, 250, 30)
    wind()

    bend = int(time.time())
    bend %= 5
    bend += 14
    light.seth(-100-bend)  # 初始向日葵葉片角度
    for i in range(14):  # 生成向日葵

        if i % 2 == 0:
            botany(-520 + i * 50, -132, 0, 1, bend - i)
            botany(-340 + i * 50, -132, 0, 1, bend - i)
        else:
            botany(-430 + i * 50, -142, 0, 1, bend - i)
            botany(-230 + i * 50, -142, 0, 1, bend - i)
    pos_x = [45, -96, -100, 410, 300, 580, 230, -50, -400, -320, -212]
    pos_y = [45, -96, -100, 0, 20, 30, 29, -50, -20, -43, 10]
    for i in range(6):  # 生成蝴蝶,這里便于觀察到結(jié)果,蝴蝶有點(diǎn)大
        butterfly(random.choice(pos_x), random.choice(pos_y))
    t.ontimer(dynamic, 1000)


def piant():  # 這里是將繪制全放在這個(gè)函數(shù)里,讓main看起來(lái)簡(jiǎn)潔
    t.tracer(False)
    t.delay(0)
    canvas()
    pencil()
    plant()
    lie()
    dynamic()


if __name__ == "__main__":
    piant()
    # t.ondrag(draw, btn=1, add=None)
    t.mainloop()

?

python海龜編程代碼大全,python學(xué)習(xí),python,turtle,python繪圖,學(xué)習(xí),turtle繪圖

參考:http://t.csdn.cn/A9nfn文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-824001.html

到了這里,關(guān)于Python海龜turtle基礎(chǔ)知識(shí)大全與畫(huà)圖集合的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶(hù)投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • python使用海龜turtle實(shí)現(xiàn)繪制漢字、中文

    python使用海龜turtle實(shí)現(xiàn)繪制漢字、中文

    ? ? ? ? 使用python中的turtle庫(kù)繪制指定漢字、中文 ? ? ? ? 1、要想實(shí)現(xiàn)漢字的繪制,首先需要知道漢字的筆畫(huà)坐標(biāo),漢字的筆畫(huà)坐標(biāo)在網(wǎng)上有,需要使用爬蟲(chóng)技術(shù)抓取到指定漢字的筆畫(huà)坐標(biāo)信息 ? 2、根據(jù)漢字的筆畫(huà)坐標(biāo)信息,使用turrle繪制出相應(yīng)的筆畫(huà),即可實(shí)現(xiàn)漢字的繪

    2024年02月10日
    瀏覽(92)
  • python-turtle(海龜繪圖)圣誕樹(shù)

    python-turtle(海龜繪圖)圣誕樹(shù)

    1.在開(kāi)始前需要引入turtle庫(kù),若沒(méi)有下載這個(gè)庫(kù)可以復(fù)制下面這條語(yǔ)句在PyCharm終端下載 ? 2.turtle庫(kù),它這個(gè)畫(huà)筆是在這個(gè)窗口橫軸x軸,縱軸y軸從原點(diǎn)(0,0)處開(kāi)始,以函數(shù)指令使其移動(dòng)繪圖。 ?最近今天持續(xù)發(fā)燒,沒(méi)來(lái)得急上傳,趕一波末班車(chē)嘻嘻

    2024年02月03日
    瀏覽(909)
  • Python中利用海龜繪圖(Turtle方法)畫(huà)個(gè)鐘表盤(pán)

    Python中利用海龜繪圖(Turtle方法)畫(huà)個(gè)鐘表盤(pán)

    目錄 前言 ????????一、海龜繪圖(Turtle)是什么? ????????二、Turtle 方法 ????????三、主要代碼和效果圖 ????????1.引入庫(kù) ??????????????????2.主要代碼 ??????????????????3.全部代碼 ???????????????????????????效果圖 總結(jié) 海

    2023年04月08日
    瀏覽(94)
  • Python---練習(xí):小海龜會(huì)畫(huà)畫(huà)---利用turtle(海龜)模塊

    Python---練習(xí):小海龜會(huì)畫(huà)畫(huà)---利用turtle(海龜)模塊

    在Python 3 版本中,新增加了一個(gè) 模塊叫做turtle(海龜) , 專(zhuān)門(mén)用于繪制圖形圖像 turtle? ? 英?/?t??t(?)l/? ? ?n. 海龜;海龜肉;美龜;淡水龜; (計(jì)算機(jī))龜標(biāo)? import 英?/??mp??t/ ?n. 進(jìn)口,進(jìn)口商品;輸入, 引進(jìn) ;重要性;意思,含意 v. 進(jìn)口,輸入,引進(jìn); 導(dǎo)入(

    2024年02月08日
    瀏覽(99)
  • Python常用基礎(chǔ)語(yǔ)法知識(shí)點(diǎn)大全合集,看完這一篇文章就夠了

    Python 是一門(mén)獨(dú)特的語(yǔ)言,快速瀏覽一下他的要點(diǎn): 面向?qū)ο螅好恳粋€(gè)變量都是一個(gè)類(lèi),有其自己的屬性(attribute)與方法(method)。 語(yǔ)法塊:用縮進(jìn)(四個(gè)空格)而不是分號(hào)、花括號(hào)等符號(hào)來(lái)標(biāo)記。因此,行首的空格不能隨意書(shū)寫(xiě)。 注釋?zhuān)盒袃?nèi)用“#”號(hào),行間注釋寫(xiě)在兩

    2023年04月22日
    瀏覽(32)
  • Python的海龜 turtle 庫(kù)使用詳細(xì)介紹(畫(huà)任意多邊形,全網(wǎng)最詳細(xì))

    Python的海龜 turtle 庫(kù)使用詳細(xì)介紹(畫(huà)任意多邊形,全網(wǎng)最詳細(xì))

    學(xué)Turtle庫(kù),其實(shí)就是學(xué)數(shù)學(xué),而且還能提高對(duì)數(shù)學(xué)和學(xué)習(xí)的興趣。Turtle庫(kù)還能夠幫助孩子更好地理解幾何學(xué)和數(shù)學(xué)概念,比如角度、比例、幾何圖形的性質(zhì)等等,是Python中一個(gè)很有趣的庫(kù)。 Turtle庫(kù)是Python中一個(gè)很有趣的庫(kù),可以用來(lái)繪制各種圖形,比如直線(xiàn)、圓、正方形等等

    2024年04月13日
    瀏覽(29)
  • 用Python海龜畫(huà)圖畫(huà)哆啦A夢(mèng)

    用Python海龜畫(huà)圖畫(huà)哆啦A夢(mèng)

    ? 前言 一、畫(huà)哆啦A夢(mèng)臉的外圈藍(lán)色 二、畫(huà)哆啦A夢(mèng)臉的內(nèi)圈白色 三、哆啦A夢(mèng)的鼻子 四、哆啦A夢(mèng)的鼻尖 五、哆啦A夢(mèng)的左眼 六、哆啦A夢(mèng)的右眼 七、哆啦A夢(mèng)的左眼內(nèi)部 八、哆啦A夢(mèng)的右眼內(nèi)部 九、?哆啦A夢(mèng)的右眼內(nèi)部白色圓點(diǎn) 十、?哆啦A夢(mèng)的鼻子下面的黑色豎線(xiàn) 十一、?哆

    2024年02月04日
    瀏覽(18)
  • 手機(jī)python怎么用海龜畫(huà)圖,python怎么在手機(jī)上編程

    手機(jī)python怎么用海龜畫(huà)圖,python怎么在手機(jī)上編程

    大家好,給大家分享一下手機(jī)python怎么用海龜畫(huà)圖,很多人還不知道這一點(diǎn)。下面詳細(xì)解釋一下。現(xiàn)在讓我們來(lái)看看! 如果您想在手機(jī)上使用Python來(lái)創(chuàng)建AI(人工智能)程序,您可以考慮以下幾種方式: 需要注意的是,雖然在手機(jī)上編寫(xiě)和運(yùn)行Python程序可能不如在PC或者服務(wù)

    2024年02月15日
    瀏覽(18)
  • SEO優(yōu)化基礎(chǔ)知識(shí)大全 SEO新手入門(mén)必備知識(shí)

    SEO優(yōu)化基礎(chǔ)知識(shí)大全 SEO新手入門(mén)必備知識(shí)

    網(wǎng)上關(guān)于SEO優(yōu)化的知識(shí)很多也很雜,很多新手都不知道如何選擇。本來(lái)耗子網(wǎng)站里每篇文章都有的詳細(xì)步驟的,考慮到很雜,于是耗子對(duì)各種SEO優(yōu)化基礎(chǔ)知識(shí)進(jìn)行了整理,但不是很詳細(xì),所以在每個(gè)步驟的后面都加上了相關(guān)文章鏈接,希望能幫助SEO新手更多的了解一下SEO基礎(chǔ)

    2024年02月10日
    瀏覽(37)
  • Python的畫(huà)圖模塊turtle使用詳解

    Python的畫(huà)圖模塊turtle使用詳解

    簡(jiǎn)介:Turtle是Python語(yǔ)言中一個(gè)很流行的簡(jiǎn)單的繪圖工具。你可以把它理解為一個(gè)小海龜,只聽(tīng)得懂有限的指令。它在一個(gè)橫軸為x、縱軸為y的坐標(biāo)系原點(diǎn),(0,0)位置開(kāi)始,它根據(jù)一組函數(shù)指令的控制,在這個(gè)平面坐標(biāo)系中移動(dòng),從而在它爬行的路徑上繪制了圖形。 turtle繪圖的

    2024年01月19日
    瀏覽(39)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包