網站首頁 編程語言 正文
繪制正方形
程序如下
import turtle as t
t.setup(650,350,200,200) #窗口大小650*350,窗口原點位于屏幕坐標系(200,200)
t.pencolor("red") #海龜顏色為紅色
t.pensize(2.5) #海龜寬度為2.5
t.fd(200)
t.seth(90)
t.fd(200)
t.seth(180)
t.fd(200)
t.seth(270)
t.fd(200)
t.seth(360)
t.done
運行結果
繪制四條邊四種顏色的正方形
程序如下
import turtle as t
t.setup(600,600)
t.pensize(2.5)
t.pencolor("red")
t.fd(120)
t.left(90)
t.pencolor("green")
t.fd(120)
t.left(90)
t.pencolor("blue")
t.fd(120)
t.left(90)
t.pencolor("yellow")
t.fd(120)
t.done()
運行結果
turtle繪制無角正方形
1.找出其共性
2.(不畫+畫+不畫)*4
3.不畫對應penup()
4.畫對應pendown()
import turtle #引入turtle庫
for i in range(4): ?#利用遍歷循環來實現重復步驟
? ? turtle.penup() ?#筆抬起
? ? turtle.fd(50) ? #向前50,用來實現沒有角
? ? turtle.pendown() ?#筆落下,開始繪制邊
? ? turtle.fd(50) ? #向前50,繪制邊
? ? turtle.penup()
? ? turtle.fd(50)
? ? turtle.pendown()
? ? turtle.left(90) ?#實現筆轉向,向左90度
turtle.hideturtle() ? #隱藏小海龜
輸出如下:
原文鏈接:https://blog.csdn.net/qq_40253803/article/details/104728680
相關推薦
- 2022-11-14 Windows進程的創建與結束
- 2022-07-26 論網頁檢查preview和response一個是漢字一個是亂碼怎么解決
- 2022-10-02 Go底層channel實現原理及示例詳解_Golang
- 2022-06-24 淺談React?中的淺比較是如何工作的_React
- 2022-03-30 C#算法之回文數_C#教程
- 2022-12-27 Qt實現UDP通信的示例代碼_C 語言
- 2022-04-12 C語言三分鐘精通時間復雜度與空間復雜度_C 語言
- 2022-07-21 Hadoop-HDFS分布式文件系統基礎
- 最近更新
-
- 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同步修改后的遠程分支