您好,登錄后才能下訂單哦!
這篇文章主要介紹“Python使用turtle庫畫任意圖的方法”,在日常操作中,相信很多人在Python使用turtle庫畫任意圖的方法問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對(duì)大家解答”Python使用turtle庫畫任意圖的方法”的疑惑有所幫助!接下來,請(qǐng)跟著小編一起來學(xué)習(xí)吧!
系統(tǒng):Windows10
版本:python 3.8
turtle.setup(width, height, startx, starty)
startx , starty 缺省在屏幕中心。
turtle.penup() #別名 turtle.pu(),抬起畫筆 turtle.pendown() #別名 turtle.pd(),落下畫筆 turtle.pensize(width) #別名 turtle.width(width),畫筆寬度 turtle.pencolor(color) #color為顏色字符串或r,g,b值,畫筆顏色
注:
顏色字符串 : turtle.pencolor("purple")
RGB的小數(shù)值: turtle.pencolor(0.63, 0.13, 0.94)
RGB的元組值: turtle.pencolor((0.63,0.13,0.94))
turtle.forward(d) #別名 turtle.fd(d),直線前進(jìn)d(可為負(fù)數(shù))個(gè)像素 turtle.circle(r, extent=None) #根據(jù)半徑r繪制extent角度的弧形 turtle.setheading(angle) #別名 turtle.seth(angle),angle: 行進(jìn)方向的絕對(duì)角度 turtle.left(angle) #海龜向左轉(zhuǎn),angle: 在海龜當(dāng)前行進(jìn)方向上旋轉(zhuǎn)的角度 turtle.right(angle) #海龜向右轉(zhuǎn) turtle.goto(x, y) # 絕對(duì)坐標(biāo)
import turtle as t t.setup(650,650,200,200) t.speed(10) # 畫筆的速度,1到10遞增 t.penup() t.fd(-250) t.pendown() t.pensize(25) t.pencolor("purple") t.seth(-40) for i in range(4): t.circle(40, 80) t.circle(-40, 80) t.circle(40, 80/2) t.fd(40) t.circle(16, 180) t.fd(40 * 2/3) t.mainloop() # 保持界面顯示,后面的語句失效
import turtle as t import cv2 t.getscreen().colormode(255) img1 = cv2.imread('2.jpg')[0: -2: 2] #填入你的圖片絕對(duì)路徑,建議100kb以下。 width = len(img1[0]) height = len(img1) t.setup(width=width / 2 + 100, height=height + 100) t.speed(8) t.pu() t.goto(-width / 4 + 10, height / 2 - 10) t.pd() t.tracer(2000) for k1, i in enumerate(img1): for j in i[::2]: t.pencolor((j[0], j[1], j[2])) t.fd(1) t.pu() t.goto(-width / 4 + 10, height / 2 - 10 - k1 - 1) t.pd() t.done() # 保持界面顯示
到此,關(guān)于“Python使用turtle庫畫任意圖的方法”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注億速云網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)砀鄬?shí)用的文章!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。