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

python?教程實(shí)現(xiàn)?turtle海龜繪圖

 更新時(shí)間:2022年05月04日 13:49:03   作者:autofelix  
這篇文章主要介紹了python?教程實(shí)現(xiàn)?turtle繪制海龜繪圖,文章基于python的相關(guān)資料展開turtle繪制海龜繪圖的詳細(xì)內(nèi)容,需要的小伙伴可以參考一下

一、安裝

  • 寫出許多有趣的可視化東西
  • 也可以畫出很多奇妙的圖案
pip install turtule

二、畫布

  • 畫布就是turtle為我們展開用于繪圖區(qū)域
  • 我們可以設(shè)置它的大小和初始位置
import turtle
# 返回默認(rèn)大小(400, 300)
turtle.screensize()
# 設(shè)置畫布方法一,設(shè)置寬、高、背景色
turtle.screensize(800, 600, "green")
# 設(shè)置畫布方法二, 寬高為小數(shù)時(shí)候?yàn)檎紦?jù)電腦屏幕比例, 寬高為整數(shù)時(shí)候?yàn)橄袼?
turtle.setup(width=0.6, height=0.6)
# startx,starty表示矩形窗口左上角頂點(diǎn)的位置, 如果為空, 則窗口位于屏幕中心
turtle.setup(width=800, height=800, startx=100, starty=100)

三、畫筆

  • 可以設(shè)置畫筆的屬性,顏色、畫線的寬度等
import turtle
# 設(shè)置畫筆的寬度
turtle.pensize()
# 沒(méi)有參數(shù)傳入,返回當(dāng)前畫筆顏色,傳入?yún)?shù)設(shè)置畫筆顏色
turtle.pencolor()
# 設(shè)置畫筆移動(dòng)速度,畫筆繪制的速度范圍[0,10]整數(shù),數(shù)字越大越快
turtle.speed(speed)

四、繪圖命令

import turtle
# 向當(dāng)前畫筆方向移動(dòng)distance像素長(zhǎng)
turtle.forward(distance)
# 向當(dāng)前畫筆相反方向移動(dòng)distance像素長(zhǎng)度
turtle.backward(distance)
# 順時(shí)針移動(dòng)degree°
turtle.right(degree)
# 逆時(shí)針移動(dòng)degree°
turtle.left(degree)
# 移動(dòng)時(shí)繪制圖形,缺省時(shí)也為繪制
turtle.pendown()
# 將畫筆移動(dòng)到坐標(biāo)為x,y的位置
turtle.goto(x,y)
# 移動(dòng)時(shí)不繪制圖形,提起筆,用于另起一個(gè)地方繪制時(shí)用
turtle.penup()
# 畫筆繪制的速度范圍[0,10]整數(shù)
turtle.speed(speed)
# 畫圓,半徑為正(負(fù)),表示圓心在畫筆的左邊(右邊)畫圓
turtle.circle()

五、畫筆控制命令

import turtle
# 繪制圖形時(shí)的寬度
turtle.pensize(width)
# 畫筆顏色
turtle.pencolor()
# 繪制圖形的填充顏色
turtle.fillcolor(colorstring)
# 同時(shí)設(shè)置pencolor=color1, fillcolor=color2
turtle.color(color1, color2)
# 返回當(dāng)前是否在填充狀態(tài)
turtle.filling()
# 準(zhǔn)備開始填充圖形
turtle.begin_fill()
# 填充完成
turtle.end_fill()
# 隱藏箭頭顯示
turtle.hideturtle()
# 與hideturtle()函數(shù)對(duì)應(yīng)
turtle.showturtle()

六、全局控制命令

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

七、繪制方形螺旋

from turtle import *
for i in range(500):
forward(i)
left(91)

python 包之 turtle 海龜繪圖教程_turtle

八、繪制彩色螺旋

from turtle import *
colors = ['red', 'purple', 'blue', 'green', 'yellow', 'orange']
for x in range(360):
pencolor(colors[x % 6])
width(x / 100 + 1)
forward(x)
left(59)

python 包之 turtle 海龜繪圖教程_繪制圖形_02

九、繪制太陽(yáng)花

import turtle as t
import time
t.color("red", "yellow")
t.speed(10)
t.begin_fill()
for _ in range(50):
t.forward(200)
t.left(170)
end_fill()
time.sleep(1)

python 包之 turtle 海龜繪圖教程_python_03

十、繪制小蟒蛇

import turtle
def drawSnake(rad, angle, len, neckrad):
for _ in range(len):
turtle.circle(rad, angle)
turtle.circle(-rad, angle)
turtle.circle(rad, angle/2)
turtle.forward(rad/2) # 直線前進(jìn)
turtle.circle(neckrad, 180)
turtle.forward(rad/4)
if __name__ == "__main__":
turtle.setup(1500, 1400, 0, 0)
turtle.pensize(30) # 畫筆尺寸
turtle.pencolor("green")
turtle.seth(-40) # 前進(jìn)的方向
drawSnake(70, 80, 2, 15)

python 包之 turtle 海龜繪圖教程_turtle_04

十一、繪制五角星

import turtle
import time
turtle.pensize(5)
turtle.pencolor("yellow")
turtle.fillcolor("red")
turtle.begin_fill()
for _ in range(5):
turtle.forward(200)
turtle.right(144)
turtle.end_fill()
time.sleep(2)

turtle.penup()
turtle.goto(-150,-120)
turtle.color("violet")
turtle.write("Done", font=('Arial', 40, 'normal'))
time.sleep(1)

python 包之 turtle 海龜繪圖教程_turtle_05

十二、繪制小豬佩奇

from turtle import*
# 繪制鼻子
def nose(x,y):
pu()
goto(x,y)
pd()
seth(-30)
begin_fill()
a=0.4
for i in range(120):
if 0<=i<30 or 60<=i<90:
a=a+0.08
lt(3) #向左轉(zhuǎn)3度
fd(a) #向前走a的步長(zhǎng)
else:
a=a-0.08
lt(3)
fd(a)
end_fill()
pu()
seth(90)
fd(25)
seth(0)
fd(10)
pd()
pencolor(255,155,192)
seth(10)
begin_fill()
circle(5)
color(160,82,45)
end_fill()
pu()
seth(0)
fd(20)
pd()
pencolor(255,155,192)
seth(10)
begin_fill()
circle(5)
color(160,82,45)
end_fill()
# 繪制頭部
def head(x,y):
color((255,155,192),"pink")
pu()
goto(x,y)
seth(0)
pd()
begin_fill()
seth(180)
circle(300,-30)
circle(100,-60)
circle(80,-100)
circle(150,-20)
circle(60,-95)
seth(161)
circle(-300,15)
pu()
goto(-100,100)
pd()
seth(-30)
a=0.4
for i in range(60):
if 0<=i<30 or 60<=i<90:
a=a+0.08
lt(3) #向左轉(zhuǎn)3度
fd(a) #向前走a的步長(zhǎng)
else:
a=a-0.08
lt(3)
fd(a)
end_fill()
# 繪制耳朵
def ears(x,y):
color((255,155,192),"pink")
pu()
goto(x,y)
pd()
begin_fill()
seth(100)
circle(-50,50)
circle(-10,120)
circle(-50,54)
end_fill()
pu()
seth(90)
fd(-12)
seth(0)
fd(30)
pd()
begin_fill()
seth(100)
circle(-50,50)
circle(-10,120)
circle(-50,56)
end_fill()
# 繪制眼睛
def eyes(x,y):
color((255,155,192),"white")
pu()
seth(90)
fd(-20)
seth(0)
fd(-95)
pd()
begin_fill()
circle(15)
end_fill()
color("black")
pu()
seth(90)
fd(12)
seth(0)
fd(-3)
pd()
begin_fill()
circle(3)
end_fill()
color((255,155,192),"white")
pu()
seth(90)
fd(-25)
seth(0)
fd(40)
pd()
begin_fill()
circle(15)
end_fill()
color("black")
pu()
seth(90)
fd(12)
seth(0)
fd(-3)
pd()
begin_fill()
circle(3)
end_fill()
# 繪制腮
def cheek(x,y):
color((255,155,192))
pu()
goto(x,y)
pd()
seth(0)
begin_fill()
circle(30)
end_fill()
# 繪制嘴巴
def mouth(x,y):
color(239,69,19)
pu()
goto(x,y)
pd()
seth(-80)
circle(30,40)
circle(40,80)

# 繪制身體
def body(x,y):
color("red",(255,99,71))
pu()
goto(x,y)
pd()
begin_fill()
seth(-130)
circle(100,10)
circle(300,30)
seth(0)
fd(230)
seth(90)
circle(300,30)
circle(100,3)
color((255,155,192),(255,100,100))
seth(-135)
circle(-80,63)
circle(-150,24)
end_fill()
# 繪制手
def hands(x,y):
color((255,155,192))
pu()
goto(x,y)
pd()
seth(-160)
circle(300,15)
pu()
seth(90)
fd(15)
seth(0)
fd(0)
pd()
seth(-10)
circle(-20,90)
pu()
seth(90)
fd(30)
seth(0)
fd(237)
pd()
seth(-20)
circle(-300,15)
pu()
seth(90)
fd(20)
seth(0)
fd(0)
pd()
seth(-170)
circle(20,90)
# 繪制腳
def foot(x,y):
pensize(10)
color((240,128,128))
pu()
goto(x,y)
pd()
seth(-90)
fd(40)
seth(-180)
color("black")
pensize(15)
fd(20)
pensize(10)
color((240,128,128))
pu()
seth(90)
fd(40)
seth(0)
fd(90)
pd()
seth(-90)
fd(40)
seth(-180)
color("black")
pensize(15)
fd(20)

# 繪制尾巴
def tail(x,y):
pensize(4)
color((255,155,192))
pu()
goto(x,y)
pd()
seth(0)
circle(70,20)
circle(10,330)
circle(70,30)
# 參數(shù)設(shè)置
def setting():
pensize(4)
hideturtle()
colormode(255)
color((255,155,192),"pink")
setup(840,500)
speed(10)
if __name__ == "__main__":
setting() #畫布、畫筆設(shè)置
nose(-100,100) #鼻子
head(-69,167) #頭
ears(0,160) #耳朵
eyes(0,140) #眼睛
cheek(80,10) #腮
mouth(-20,30) #嘴
body(-32,-8) #身體
hands(-56,-45) #手
foot(2,-177) #腳
tail(148,-155) #尾巴
done() #結(jié)束

到此這篇關(guān)于python 教程實(shí)現(xiàn) turtle繪制海龜繪圖的文章就介紹到這了,更多相關(guān)python turtle繪制內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Python微信庫(kù):itchat的用法詳解

    Python微信庫(kù):itchat的用法詳解

    本篇文章主要介紹了Python微信庫(kù):itchat的用法詳解,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-08-08
  • Python實(shí)現(xiàn)的遠(yuǎn)程文件自動(dòng)打包并下載功能示例

    Python實(shí)現(xiàn)的遠(yuǎn)程文件自動(dòng)打包并下載功能示例

    這篇文章主要介紹了Python實(shí)現(xiàn)的遠(yuǎn)程文件自動(dòng)打包并下載功能,結(jié)合實(shí)例形式分析了Python使用spawn()方法執(zhí)行ssh、scp 命令實(shí)現(xiàn)遠(yuǎn)程文件的相關(guān)操作技巧,需要的朋友可以參考下
    2019-07-07
  • Python使用CuPy模塊實(shí)現(xiàn)高效數(shù)值計(jì)算

    Python使用CuPy模塊實(shí)現(xiàn)高效數(shù)值計(jì)算

    CuPy是一個(gè)基于Python的GPU加速計(jì)算庫(kù),它提供了與NumPy相似的接口,可以在GPU上進(jìn)行高效的數(shù)值計(jì)算,本文主要介紹一下CuPy的應(yīng)用場(chǎng)景,并給出一些Python代碼案例,需要的可以參考下
    2024-02-02
  • python中l(wèi)ist列表復(fù)制的幾種方法(賦值、切片、copy(),deepcopy())

    python中l(wèi)ist列表復(fù)制的幾種方法(賦值、切片、copy(),deepcopy())

    本文主要介紹了python中l(wèi)ist列表復(fù)制的幾種方法(賦值、切片、copy(),deepcopy()),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2022-08-08
  • Python基礎(chǔ)詳解之列表復(fù)制

    Python基礎(chǔ)詳解之列表復(fù)制

    這篇文章主要介紹了Python基礎(chǔ)詳解之列表復(fù)制,文中有非常詳細(xì)的代碼示例,對(duì)正在學(xué)習(xí)python基礎(chǔ)的小伙伴們有很好的幫助,需要的朋友可以參考下
    2021-04-04
  • 淺析form標(biāo)簽中的GET和POST提交方式區(qū)別

    淺析form標(biāo)簽中的GET和POST提交方式區(qū)別

    在HTML中,form表單的作用是收集標(biāo)簽中的內(nèi)容<form>...</form> 中間可以由訪問(wèn)者添加類似于文本,選擇,或者一些控制模塊等等.然后這些內(nèi)容將會(huì)被送到服務(wù)端
    2021-09-09
  • Python圖像處理之顏色的定義與使用分析

    Python圖像處理之顏色的定義與使用分析

    這篇文章主要介紹了Python圖像處理之顏色的定義與使用,結(jié)合實(shí)例形式分析了matplotlib模塊中顏色值的相關(guān)使用操作技巧,需要的朋友可以參考下
    2019-01-01
  • Python書單 不將就

    Python書單 不將就

    對(duì)于學(xué)習(xí)Python語(yǔ)言,如何選擇合適的Python書單,是不是已經(jīng)眼花繚亂,不知道該選擇哪本好了呢?今天我來(lái)為大家分享幾本不可錯(cuò)過(guò)的Python好書
    2017-07-07
  • 使用Python腳本實(shí)現(xiàn)批量網(wǎng)站存活檢測(cè)遇到問(wèn)題及解決方法

    使用Python腳本實(shí)現(xiàn)批量網(wǎng)站存活檢測(cè)遇到問(wèn)題及解決方法

    本文是小編自己編寫的一個(gè)使用python實(shí)現(xiàn)批量網(wǎng)站存活檢測(cè)。在項(xiàng)目測(cè)試中非常有用。本文給大家分享了遇到的問(wèn)題及解決方案,非常不錯(cuò),具有參考借鑒價(jià)值,感興趣的朋友一起看看吧
    2016-10-10
  • Django框架cookie和session方法及參數(shù)設(shè)置

    Django框架cookie和session方法及參數(shù)設(shè)置

    這篇文章主要為大家介紹了Django框架cookie和session參數(shù)設(shè)置及介紹,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-03-03

最新評(píng)論

贵溪市| 杂多县| 湖南省| 中牟县| 德令哈市| 青浦区| 吉林省| 吉安市| 辰溪县| 丰城市| 新河县| 红河县| 岳阳县| 呼和浩特市| 高台县| 平昌县| 东丽区| 新化县| 涞水县| 渑池县| 亚东县| 吉首市| 靖远县| 全椒县| 盐亭县| 岐山县| 天气| 广昌县| 营山县| 景洪市| 阳曲县| 新沂市| 和田县| 九江市| 宝清县| 潢川县| 清流县| 昌乐县| 闵行区| 安平县| 江安县|