0
点赞
收藏
分享

微信扫一扫

python海龟画图turtle,多图共存,非多线程

开源分享 2022-01-14 阅读 74

# 穿越火线_单机
# coding=utf-8
import turtle 
from datetime import *

def Skip(step):
    turtle.penup()
    turtle.forward(step)
    turtle.pendown()
 
def mkHand(name, length):
    # Turtle,Turtle
    turtle.reset()
    Skip(-length * 0.1)
    # dfhgjhdfshjk
    turtle.begin_poly()
    turtle.forward(length * 1.1)
    # fjgjjfggjhgshdfg
    turtle.end_poly()
    # dgjhjjg
    handForm = turtle.get_poly()
    turtle.register_shape(name, handForm)
 
def Init():
    global secHand, minHand, hurHand, printer
    # Turtle
    turtle.mode("logo")
    # Turtle
    mkHand("secHand", 135)
    mkHand("minHand", 125)
    mkHand("hurHand", 90)
    secHand = turtle.Turtle()
    secHand.shape("secHand")
    minHand = turtle.Turtle()
    minHand.shape("minHand")
    hurHand = turtle.Turtle()
    hurHand.shape("hurHand")
   
    for hand in secHand, minHand, hurHand:
        hand.shapesize(1, 1, 3)
        hand.speed(0)
   
    # Turtle
    printer = turtle.Turtle()
    # turtle
    printer.hideturtle()
    printer.penup()
    
def SetupClock(radius):
    # hjyubu
    turtle.reset()
    turtle.pensize(7)
    for i in range(60):
        Skip(radius)
        if i % 5 == 0:
            turtle.forward(20)
            Skip(-radius - 20)
           
            Skip(radius + 20)
            if i == 0:
                turtle.write(int(12), align="center", font=("Courier", 14, "bold"))
            elif i == 30:
                Skip(25)
                turtle.write(int(i/5), align="center", font=("Courier", 14, "bold"))
                Skip(-25)
            elif (i == 25 or i == 35):
                Skip(20)
                turtle.write(int(i/5), align="center", font=("Courier", 14, "bold"))
                Skip(-20)
            else:
                turtle.write(int(i/5), align="center", font=("Courier", 14, "bold"))
            Skip(-radius - 20)
        else:
            turtle.dot(5)
            Skip(-radius)
        turtle.right(6)
        
def Week(t):   
    week = ["星期一", "星期二", "星期三",
            "星期四", "星期五", "星期六", "星期日"]
    return week[t.weekday()]
 
def Date(t):
    y = t.year
    m = t.month
    d = t.day
    return "%s %d%d" % (y, m, d)
 
def Tick():
    # erwretr
    t = datetime.today()
    second = t.second + t.microsecond * 0.000001
    minute = t.minute + second / 60.0
    hour = t.hour + minute / 60.0
    secHand.setheading(6 * second)
    minHand.setheading(6 * minute)
    hurHand.setheading(30 * hour)
    
    turtle.tracer(False) 
    printer.forward(65)
    printer.write(Week(t), align="center",
                  font=("Courier", 14, "bold"))
    printer.back(130)
    printer.write(Date(t), align="center",
                  font=("Courier", 14, "bold"))
    printer.home()
    turtle.tracer(True)
 
    # 100ms,tick
    turtle.ontimer(Tick, 100)
 
def main():
    # dfdshg
    turtle.tracer(False)
    Init()
    SetupClock(160)
    turtle.tracer(True)
    Tick()
    turtle.mainloop()

turtle.screensize(1440,900,"red")
turtle.setup(1440,900)
#turtle.setup(1.0,1.0)
turtle.showturtle()
turtle.color("violet")
turtle.write("穿越火线加载中,请稍后", font=('Arial', 28, 'normal'))
#turtle.write("穿越火线加载中,请稍后",font=("Arial",28,"yellow"))

#turtle.penup()
#turtle.goto(-500,0)
#turtle.pendown()
#home()

turtle.width(10)
turtle.color("blue")
turtle.goto(30,-30)

turtle.penup()
turtle.goto(0,-40)
turtle.pendown()
turtle.goto(30,-70)

turtle.penup()
turtle.goto(0,-130)
turtle.pendown()
turtle.goto(30,-100)

turtle.penup()
turtle.goto(50,-10)
turtle.pendown()
turtle.goto(160,-10)

turtle.penup()
turtle.goto(105,-10)
turtle.pendown()
turtle.goto(105,-120)

turtle.penup()
turtle.goto(50,-120)
turtle.pendown()
turtle.goto(160,-120)
#gotopenup
turtle.color("yellow")
turtle.penup()
turtle.goto(230,0)
turtle.pendown()
turtle.goto(190,-40)

turtle.penup()
turtle.goto(210,-20)
turtle.pendown()
turtle.goto(210,-130)

turtle.penup()
turtle.goto(240,-15)
turtle.pendown()
turtle.goto(320,-15)

turtle.penup()
turtle.goto(240,-30)
turtle.pendown()
turtle.goto(320,-30)

turtle.penup()
turtle.goto(240,-45)
turtle.pendown()
turtle.goto(320,-45)

turtle.penup()
turtle.goto(280,0)
turtle.pendown()
turtle.goto(280,-45)

turtle.penup()
turtle.goto(240,-60)
turtle.pendown()
turtle.goto(240,-130)

turtle.penup()
turtle.goto(240,-60)
turtle.pendown()
turtle.goto(320,-60)
turtle.left(270)
turtle.forward(70)
turtle.left(225)
turtle.forward(20)

turtle.penup()
turtle.goto(240,-80)
turtle.pendown()
turtle.goto(320,-80)

turtle.penup()
turtle.goto(240,-100)
turtle.pendown()
turtle.goto(320,-100)
#gotopenup
turtle.color("green")
turtle.penup()
turtle.goto(390,0)
turtle.pendown()
turtle.goto(350,-40)

turtle.penup()
turtle.goto(370,-20)
turtle.pendown()
turtle.goto(370,-130)

turtle.penup()
turtle.goto(400,-15)
turtle.pendown()
turtle.goto(480,-15)

turtle.penup()
turtle.goto(400,-30)
turtle.pendown()
turtle.goto(480,-30)

turtle.penup()
turtle.goto(400,-45)
turtle.pendown()
turtle.goto(480,-45)
turtle.left(135)
turtle.forward(70)
turtle.left(225)
turtle.forward(20)

turtle.penup()
turtle.goto(440,0)
turtle.pendown()
turtle.goto(440,-130)

# gotopenup

turtle.width(1)
turtle.color("white")
turtle.penup()
turtle.goto(-335,0)
turtle.pendown()
t=turtle.pen()
for x in range(90):
    turtle.forward(x)
    turtle.left(59)

turtle.penup()
turtle.goto(-500,0)
turtle.pendown()
#home()
if __name__ == "__main__":
    main()
#turtle.done()

举报

相关推荐

Python —— turtle画图

0 条评论