Python turtle庫(kù)的畫筆控制說明
turtle.penup() 別名 turtle.pu() :抬起畫筆海龜在飛行
turtle.pendown() 別名 turtle.pd():畫筆落下,海龜在爬行
turtle.pensize(width) 別名 turtle.width(width) :設(shè)置畫筆的寬度,海龜?shù)难鼑?/p>
turtle.pencolor(color) color為顏色字符串或r,g,b值 :
顏色字符串:turtle.pencolor('red')
RGB的小數(shù)值:turtle.pencolor(0.63,0.13,0.94)
RGB的元組值:turtle.pencolor((0.63,0.13,0.94))
運(yùn)動(dòng)控制函數(shù):
turtle.forward(d) 別名: turtle.fd(d)
向前直行,海龜走直線 d:行進(jìn)距離可以為負(fù)數(shù)
turtle.circle(r,extent=None)
根據(jù)半徑 r 繪制 extent角度的弧形
r:默認(rèn)圓心在海龜左側(cè)r距離的位置
extent:繪制角度,默認(rèn)是360度整圓
turtle.seth(angle)
控制海龜?shù)牡姆较?/p>
補(bǔ)充知識(shí):Python turtle繪圖庫(kù)調(diào)用、基本命令簡(jiǎn)介-----以蟒蛇繪制為例
下面的代碼為 python 蟒蛇繪制舉例,其中的注釋行對(duì) turtle 繪圖庫(kù)的調(diào)用和其中的基本命令進(jìn)行了簡(jiǎn)介
import turtle ## 引入一個(gè)繪圖庫(kù) # 方法一# import <庫(kù)名># 使用:庫(kù)名.函數(shù)名(函數(shù)參數(shù)) # 方法二# from <庫(kù)名> import <函數(shù)名># from <庫(kù)名> import *# 使用:<函數(shù)名>(函數(shù)參數(shù))# 可能會(huì)重復(fù) # 方法三# import <庫(kù)名> as <庫(kù)別名># 使用:庫(kù)別名.函數(shù)名(函數(shù)參數(shù)) ## 設(shè)置turtle畫布參數(shù)turtle.setup(650,350,200,200) ##(寬,高,x,y)## 讓海龜不畫圖飛到某一個(gè)位置turtle.penup()turtle.fd(-250)turtle.pendown()## 設(shè)置畫筆粗細(xì)和顏色turtle.pensize(25) #turtle.width(25)turtle.pencolor(’purple’)### 轉(zhuǎn)型函數(shù)控制轉(zhuǎn)向,海龜只轉(zhuǎn)向,不行動(dòng) ##### 絕對(duì)角度的轉(zhuǎn)向turtle.seth(-40) # turtle.setheading(angle) ## 海龜角度的轉(zhuǎn)向# turtle.left(angle)# turtle.right(angle)for i in range(4): turtle.circle(40,80) turtle.circle(-40,80)turtle.circle(40,80/2) #turtle.circle(r,entent = None) 根據(jù)半徑r繪制entent角度的弧形,圓心默認(rèn)在海龜左邊r的位置上turtle.fd(40) #turtle.forward(40)turtle.circle(16,180)turtle.fd(40*2/3)turtle.done() #結(jié)束畫圖,但不關(guān)閉窗口
以上這篇Python turtle庫(kù)的畫筆控制說明就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. 基于 Python 實(shí)踐感知器分類算法2. Python如何批量生成和調(diào)用變量3. ASP.NET MVC實(shí)現(xiàn)橫向展示購(gòu)物車4. 通過CSS數(shù)學(xué)函數(shù)實(shí)現(xiàn)動(dòng)畫特效5. ASP.Net Core對(duì)USB攝像頭進(jìn)行截圖6. python利用opencv實(shí)現(xiàn)顏色檢測(cè)7. ASP.Net Core(C#)創(chuàng)建Web站點(diǎn)的實(shí)現(xiàn)8. Python 中如何使用 virtualenv 管理虛擬環(huán)境9. Python獲取B站粉絲數(shù)的示例代碼10. windows服務(wù)器使用IIS時(shí)thinkphp搜索中文無效問題
