首先來看實現效果,如下圖:
#具體實作程式碼請看:
(推薦學習:python影片教學)
# -*- coding:utf-8 -*- # __author__ :kusy # __content__:文件说明 # __date__:2018/8/21 13:08 import turtle import time import math as m class Sheep(object): def __init__(self,xsize): self.t = turtle.Turtle() self.xsize = xsize t = self.t # 画笔设置 t.screen.screensize(canvwidth=1000,canvheight=500,bg='white') t.pensize(2) t.speed(10) # t.hideturtle() #初始化画笔位置 t.penup() t.setpos(self.xsize,0) t.pendown() # 设置画笔坐标 def setxy(self,x,y): t = self.t t.penup() pos_x = t.position()[0] pos_y = t.position()[1] t.setpos(pos_x + x,pos_y + y) t.pendown() def create_sheep(self): t = self.t # 羊头 self.setxy(-200,0) t.fillcolor('black') t.begin_fill() t.circle(100) t.end_fill() # 眼睛 # 眼白 print(t.position()) self.setxy(-20,120) t.fillcolor('white') t.begin_fill() t.seth(45) t.circle(18,-280) t.seth(45) t.circle(-20,292) t.end_fill() # 眼珠 self.setxy(3,12) t.fillcolor('black') t.begin_fill() t.seth(85) t.circle(10) t.seth(85) t.circle(-10) t.end_fill() # 眼心 t.fillcolor('white') t.begin_fill() t.seth(85) t.circle(3) t.seth(85) t.circle(-3) t.end_fill() # 嘴 self.setxy(0,-100) t.color('red') t.seth(300) t.forward(8) self.setxy(-1, 3) t.seth(0) t.circle(80,60) self.setxy(2, -2) t.seth(145) t.forward(8) t.color('black') # 耳朵 self.setxy(-145,120) p1 = t.position() t.fillcolor('black') t.begin_fill() t.seth(0) t.circle(-120,20) p2 = t.position() t.setpos(p1) t.seth(60) t.circle(-30,120) t.goto(p2) t.end_fill() # 身体 self.setxy(41,12) t.seth(45) t.circle(-150,100) t.pensize(5) t.seth(0) t.circle(-120,30) t.seth(60) t.circle(-15,320) t.seth(330) t.circle(-80,180) t.seth(210) t.circle(-80,90) #4条腿 t.pensize(2) for leg in range(4): self.setxy(8+15*leg,0) t.seth(270) t.forward(80) t.seth(0) t.forward(8) t.seth(90) t.forward(80) #草 self.setxy(-200,-80) p3 = t.position() t.color('green') t.fillcolor('green') t.begin_fill() t.seth(120) t.forward(30) t.seth(330) t.forward(30) t.seth(60) t.forward(40) t.seth(260) t.forward(45) t.setpos(p3) t.end_fill() if __name__ == '__main__': for x in (0,350): sheep = Sheep(x) sheep.create_sheep() time.sleep(5)
相關文章教學推薦:python教學
以上是如何用python畫簡單的動物的詳細內容。更多資訊請關注PHP中文網其他相關文章!

要在有限的時間內最大化學習Python的效率,可以使用Python的datetime、time和schedule模塊。 1.datetime模塊用於記錄和規劃學習時間。 2.time模塊幫助設置學習和休息時間。 3.schedule模塊自動化安排每週學習任務。

Python在遊戲和GUI開發中表現出色。 1)遊戲開發使用Pygame,提供繪圖、音頻等功能,適合創建2D遊戲。 2)GUI開發可選擇Tkinter或PyQt,Tkinter簡單易用,PyQt功能豐富,適合專業開發。

Python适合数据科学、Web开发和自动化任务,而C 适用于系统编程、游戏开发和嵌入式系统。Python以简洁和强大的生态系统著称,C 则以高性能和底层控制能力闻名。

2小時內可以學會Python的基本編程概念和技能。 1.學習變量和數據類型,2.掌握控制流(條件語句和循環),3.理解函數的定義和使用,4.通過簡單示例和代碼片段快速上手Python編程。

Python在web開發、數據科學、機器學習、自動化和腳本編寫等領域有廣泛應用。 1)在web開發中,Django和Flask框架簡化了開發過程。 2)數據科學和機器學習領域,NumPy、Pandas、Scikit-learn和TensorFlow庫提供了強大支持。 3)自動化和腳本編寫方面,Python適用於自動化測試和系統管理等任務。

兩小時內可以學到Python的基礎知識。 1.學習變量和數據類型,2.掌握控制結構如if語句和循環,3.了解函數的定義和使用。這些將幫助你開始編寫簡單的Python程序。

如何在10小時內教計算機小白編程基礎?如果你只有10個小時來教計算機小白一些編程知識,你會選擇教些什麼�...

使用FiddlerEverywhere進行中間人讀取時如何避免被檢測到當你使用FiddlerEverywhere...


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境

Atom編輯器mac版下載
最受歡迎的的開源編輯器

PhpStorm Mac 版本
最新(2018.2.1 )專業的PHP整合開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)