- Python編程與幾何圖形
- 王振世
- 184字
- 2020-05-15 16:42:28
1.5 程序設計
在Python的文件編輯器里,新建一個dotsrandom.py文件,完成隨機生成點的程序設計,程序代碼如圖1-17所示。在導入turtle庫的時候,給該庫對象起一個別名pic;在導入random庫的時候,給該庫對象起一個別名r。使用for循環,循環100次,生成100個點。在每次循環中,使用隨機函數randint()隨機生成點的坐標(x,y)和點的直徑d。然后抬筆penup(),移動畫筆goto(x,y),落筆pendown(),畫點dot()。

圖1-17 隨機生成點的程序代碼
推薦閱讀
- Getting Started with Citrix XenApp? 7.6
- 編寫整潔的Python代碼(第2版)
- Learning Python Design Patterns(Second Edition)
- Mastering Ext JS
- Mastering Apache Maven 3
- 快人一步:系統性能提高之道
- Getting Started with Laravel 4
- 動手學數據結構與算法
- Getting Started with Nano Server
- CRYENGINE Game Development Blueprints
- Vue.js應用測試
- Principles of Strategic Data Science
- Clojure High Performance Programming(Second Edition)
- SFML Game Development
- C++標準庫(第2版)