網(wǎng)站首頁(yè) 編程語(yǔ)言 正文
環(huán)境配置
系統(tǒng):Windows10
版本:python 3.8
Turtle掃盲
1.繪圖窗體的設(shè)置
turtle.setup(width, height, startx, starty)
startx , starty 缺省在屏幕中心。
2.畫筆控制函數(shù)
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))
3.形狀繪制函數(shù)
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)
Turtle畫任意圖
1.經(jīng)典案例
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() # 保持界面顯示,后面的語(yǔ)句失效
2.畫任意圖片
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() # 保持界面顯示
原文鏈接:https://www.cnblogs.com/mosu/p/16085184.html
相關(guān)推薦
- 2023-06-16 Visual?Studio?如何創(chuàng)建C/C++項(xiàng)目問(wèn)題_C 語(yǔ)言
- 2022-07-13 Win系統(tǒng)服務(wù)器管理器打開方式
- 2022-04-20 C++中的函數(shù)你真的理解了嗎_C 語(yǔ)言
- 2022-03-14 Response to preflight request doesn't pass access
- 2022-10-22 PostgreSql生產(chǎn)級(jí)別數(shù)據(jù)庫(kù)安裝要注意事項(xiàng)_PostgreSQL
- 2022-08-03 GoFrame?glist?基礎(chǔ)使用和自定義遍歷_Golang
- 2022-10-09 C#使用Enum.TryParse()實(shí)現(xiàn)枚舉安全轉(zhuǎn)換_C#教程
- 2023-03-23 Golang學(xué)習(xí)之內(nèi)存逃逸分析_Golang
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過(guò)濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡(jiǎn)單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支