資源簡介
用Python做一個鐘表
代碼片段和文件信息
from?turtle?import?*
from?datetime?import?*
def?Skip(step):
????penup()
????forward(step)
????pendown()
def?mkHand(name?length):
????#注冊Turtle形狀,建立表針Turtle
????reset()
????Skip(-length*0.1)
????begin_poly()
????forward(length*1.1)
????end_poly()
????handForm?=?get_poly()
????#注冊Turtle形狀命令register_shape(nameshape=None)
????register_shape(name?handForm)
def?Init():
????global?secHand?minHand?hurHand?printer
????mode(“logo“)#?重置Turtle指向北
????#建立三個表針Turtle并初始化
????#第二個參數為長度
????mkHand(“secHand“?115)
????mkHand(“minHand“??95)
????mkHand(“hurHand“?80)
????secHand?=?Turtle()
????secHand.shape(“secHand“)
????minHand?=?Turtle()
????minHand.shape(“minHand“)
????hurHand?=?Turtle()
????hurHand.shape(“hurHand“)
????for?hand?in?secHand?minHand?hurHand:
???
評論
共有 條評論