網(wǎng)站首頁 編程語言 正文
turtle.write方法使用說明
關(guān)于turtle可參見 Python的turtle模塊:https://www.jb51.net/article/238830.htm
turtle.write()方法
在當(dāng)前烏龜位置寫入文本。如:
turtle.write("你好啊", align="center",font=("宋體",10,"normal"))
其中
你好啊 寫入Turtle繪畫屏幕的文字,是字符串格式,要有引號。
move(可選):在默認(rèn)情況下,move為false。如果move為true,則筆將移動到右下角。
align(可選):可取值是left即左、center即中、right即右之一,是字符串格式。
font(可選):字體三元組(fontname、fontsize、fonttype),fontname即字體名稱,fontsize即字體大小,fonttype即字體類型如:normal、bold、italic。。
例子
import turtle info = "你輸入的文字" turtle.penup() turtle.fd(-300) turtle.pencolor('red') for i in info: turtle.write(i, font=('宋體',40,'normal')) turtle.fd(60) turtle.hideturtle()
運行效果如下:
繪制一朵小花的例子
import turtle as t t.penup() t.fd(-200) t.write("一朵小花\n", align="right", font=("楷體", 16, "bold")) def draw_leaf(): for i in range(2): for j in range(15): t.forward(5) t.right(6) t.right(90) t.goto(0,-150) t.left(90) t.down() t.forward(50) t.fillcolor("green") t.begin_fill() draw_leaf() t.end_fill() t.forward(50) t.right(270) t.fillcolor("green") t.begin_fill() draw_leaf() t.end_fill() t.right(90) t.forward(130) t.fillcolor("red") t.begin_fill() for i in range(6): draw_leaf() t.right(60) t.end_fill() t.done()
運行效果如下:
如何使用turtle.write方法將文字顯示為一個圓圈?
可近似地將畫筆的運動軌跡看為一個正多邊形。
根據(jù)多邊形內(nèi)角和公式:度數(shù)=(邊數(shù)-2)*180,
那么,每次旋轉(zhuǎn)的度數(shù)為:180-度數(shù)/角數(shù)=180-(邊數(shù)-2)*180/邊數(shù)。
易知,邊數(shù)=角數(shù)=文字?jǐn)?shù)
所以每次旋轉(zhuǎn)的度數(shù)為:180-(文字?jǐn)?shù)-2)*180/文字?jǐn)?shù)=360/文字?jǐn)?shù)。
例如
#將文字顯示為一個圓圈 import turtle text="你要顯示的文字" turtle.pu() x=len(text) for i in text: turtle.write(i,font='consolas') turtle.rt(360/x) turtle.pu() turtle.fd(30) turtle.hideturtle()
運行效果如下:
總結(jié)
原文鏈接:https://blog.csdn.net/cnds123/article/details/113915180
相關(guān)推薦
- 2022-11-23 python?Multiprocessing.Pool進程池模塊詳解_python
- 2022-09-08 pytorch?tensor內(nèi)所有元素相乘實例_python
- 2023-01-18 解決CentOS下ImportError:?No?module?named?'_sqlite3'的問
- 2022-09-07 Golang必知必會之Go?Mod命令詳解_Golang
- 2022-10-05 C#?獲取文件夾里所有文件名的詳細(xì)代碼_C#教程
- 2022-12-04 C++?Boost.Range與Adapters庫使用詳解_C 語言
- 2022-05-11 解決Spring Boot報錯Mapped Statements collection alread
- 2022-05-12 Nginx反向代理 對響應(yīng)網(wǎng)頁中的字符串進行替換設(shè)置
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支