Python turtle庫的畫筆控制說明
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)動控制函數(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ǔ)充知識:Python turtle繪圖庫調(diào)用、基本命令簡介-----以蟒蛇繪制為例
下面的代碼為 python 蟒蛇繪制舉例,其中的注釋行對 turtle 繪圖庫的調(diào)用和其中的基本命令進(jìn)行了簡介
import turtle ## 引入一個繪圖庫 # 方法一# import <庫名># 使用:庫名.函數(shù)名(函數(shù)參數(shù)) # 方法二# from <庫名> import <函數(shù)名># from <庫名> import *# 使用:<函數(shù)名>(函數(shù)參數(shù))# 可能會重復(fù) # 方法三# import <庫名> as <庫別名># 使用:庫別名.函數(shù)名(函數(shù)參數(shù)) ## 設(shè)置turtle畫布參數(shù)turtle.setup(650,350,200,200) ##(寬,高,x,y)## 讓海龜不畫圖飛到某一個位置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)向,不行動 ##### 絕對角度的轉(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庫的畫筆控制說明就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. 讓chatgpt將html中的圖片轉(zhuǎn)為base64方法示例2. 《CSS3實(shí)戰(zhàn)》筆記--漸變設(shè)計(一)3. CSS3實(shí)現(xiàn)動態(tài)翻牌效果 仿百度貼吧3D翻牌一次動畫特效4. ASP.NET MVC把數(shù)據(jù)庫中枚舉項(xiàng)的數(shù)字轉(zhuǎn)換成文字5. 移動端HTML5實(shí)現(xiàn)拍照功能的兩種方法6. ASP.NET Core自定義中間件的方式詳解7. 測試模式 - XSL教程 - 58. html5手機(jī)觸屏touch事件介紹9. 用xslt+css讓RSS顯示的跟網(wǎng)頁一樣漂亮10. 教你JS更簡單的獲取表單中數(shù)據(jù)(formdata)
