日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
python的海龜庫(kù)

Python海龜庫(kù)(turtle)是一個(gè)用于繪制圖形的圖形庫(kù),它提供了一系列的函數(shù)和方法來控制一個(gè)虛擬的“海龜”,通過編程來繪制各種圖形,下面將詳細(xì)介紹海龜庫(kù)的一些常用函數(shù)及其用法。

1、導(dǎo)入海龜庫(kù)

import turtle

2、創(chuàng)建畫布和海龜對(duì)象

創(chuàng)建一個(gè)畫布窗口
window = turtle.Screen()
創(chuàng)建一個(gè)海龜對(duì)象
t = turtle.Turtle()

3、基本繪圖函數(shù)

前進(jìn):forward(distance)

t.forward(100)

后退:backward(distance)

t.backward(100)

左轉(zhuǎn):left(angle)

t.left(90)

右轉(zhuǎn):right(angle)

t.right(90)

以角度為單位設(shè)置方向:setheading(angle)

t.setheading(0)

4、畫筆控制函數(shù)

提筆:penup()

t.penup()

落筆:pendown()

t.pendown()

設(shè)置畫筆顏色:pencolor(color)

t.pencolor("red")

設(shè)置填充顏色:fillcolor(color)

t.fillcolor("blue")

開始填充:begin_fill()

t.begin_fill()

結(jié)束填充:end_fill()

t.end_fill()

5、畫筆速度和位置控制函數(shù)

設(shè)置畫筆速度:speed(speedlevel),其中speedlevel的范圍是0(最慢)到10(最快)

t.speed(1)

獲取當(dāng)前畫筆位置:position()

x, y = t.position()

設(shè)置畫筆位置:setposition(x, y)

t.setposition(100, 100)

設(shè)置畫筆形狀:shape(shapename),其中shapename可以是"arrow"、"turtle"、"circle"、"square"、"triangle"、"classic"之一

t.shape("turtle")

設(shè)置畫筆寬度:width(width)

t.width(5)

6、畫布控制函數(shù)

設(shè)置畫布大小:setup(width, height)

turtle.setup(800, 600)

設(shè)置畫布背景顏色:bgcolor(color)

turtle.bgcolor("white")

設(shè)置畫布模式:mode(mode),其中mode可以是"standard"、"logo"、"world"之一

turtle.mode("world")

重置畫布:reset()

turtle.reset()

關(guān)閉畫布窗口:bye()

turtle.bye()

以上就是Python海龜庫(kù)的一些常用函數(shù)及其用法,通過這些函數(shù),我們可以實(shí)現(xiàn)各種圖形的繪制,希望對(duì)你有所幫助!


網(wǎng)頁(yè)名稱:python的海龜庫(kù)
文章路徑:http://m.5511xx.com/article/cdships.html