網站首頁 編程語言 正文
turtle.write方法使用說明
關于turtle可參見 Python的turtle模塊:https://www.jb51.net/article/238830.htm
turtle.write()方法
在當前烏龜位置寫入文本。如:
turtle.write("你好啊", align="center",font=("宋體",10,"normal"))
其中
你好啊 寫入Turtle繪畫屏幕的文字,是字符串格式,要有引號。
move(可選):在默認情況下,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方法將文字顯示為一個圓圈?
可近似地將畫筆的運動軌跡看為一個正多邊形。
根據多邊形內角和公式:度數=(邊數-2)*180,
那么,每次旋轉的度數為:180-度數/角數=180-(邊數-2)*180/邊數。
易知,邊數=角數=文字數
所以每次旋轉的度數為:180-(文字數-2)*180/文字數=360/文字數。
例如
#將文字顯示為一個圓圈 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()
運行效果如下:
總結
原文鏈接:https://blog.csdn.net/cnds123/article/details/113915180
相關推薦
- 2023-01-28 Flutter項目手勢運用及單獨指針消歧問題解決方案_Android
- 2023-02-17 docker快速部署zabbix的方法_docker
- 2022-02-21 小程序數據延遲時,可使用userInfoReadyCallback解決
- 2023-04-18 Python中selenium獲取token的方法_python
- 2022-11-14 mq消息積壓怎么對應
- 2023-08-30 Git忽略已經提交過一次文件Git忽略文件
- 2023-04-02 攔截信號Golang應用優雅關閉的操作方法_Golang
- 2022-09-15 React組件三大屬性之state,props,refs_React
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支