def Tick():
# ?????????
t = datetime.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)
turtle.ontimer(Tick, 100) # 100ms?????tick
python类forward()的实例源码
def draw_world(curvature_step=0):
if curvature_step > 0:
villages = 360 // 4 // curvature_step
else:
villages = 5
for i in range(villages):
prepare_drawing()
draw_house()
finish_drawing()
turtle.right(curvature_step)
turtle.forward(LENGTH * 11)
for j in range(3):
prepare_drawing()
draw_tree(3 + j % 2 * 2)
finish_drawing()
turtle.right(curvature_step)
turtle.forward(LENGTH * 3)
turtle.forward(LENGTH)
def draw(self):
"draws the lsystem on the screen"
stack = []
tt.penup()
tt.setpos(0, -200)
tt.seth(90)
tt.pendown()
print "Drawing the lsystem ..."
for i, codebit in enumerate(self.generation[-1]):
if codebit in ['F', 'A', 'B']:
tt.forward(self.length)
print '[ FRWD ] ', codebit
elif codebit == '+':
tt.right(self.angle)
print '[ RGHT ] ', codebit
elif codebit == '-':
tt.left(self.angle)
print '[ LEFT ] ', codebit
elif codebit == '[':
stack.append((tt.pos(), tt.heading()))
print '[ PUSH ] ', (tt.pos(), tt.heading())
elif codebit == ']':
position,heading = stack.pop()
print '[ POP ] ', (position, heading)
tt.penup()
tt.goto(position)
tt.seth(heading)
tt.pendown()
else:
print '[ NOP ] ', codebit
if self.save_every_frame:
self.save(frame=i)
print "Done drawing"
print "Saving file as %s.jpg" % self.name,
self.save()
print "Done"
def Skip(step):
turtle.penup()
turtle.forward(step)
turtle.pendown()
def mkHand(name, length):
# ??Turtle???????Turtle
turtle.reset()
Skip(-length * 0.1)
turtle.begin_poly()
turtle.forward(length * 1.1)
turtle.end_poly()
handForm = turtle.get_poly()
turtle.register_shape(name, handForm)
def SetupClock(radius):
# ??????
turtle.reset()
turtle.pensize(7)
for i in range(60):
Skip(radius)
if i % 5 == 0:
turtle.forward(20)
Skip(-radius - 20)
else:
turtle.dot(5)
Skip(-radius)
turtle.right(6)
def zweig(laenge = 10, winkel=30, divisor=2):
if laenge < 2:
return
turtle.forward(laenge)
turtle.left(winkel)
zweig(laenge//divisor, winkel, divisor)
turtle.right(winkel*2)
zweig(laenge//divisor, winkel, divisor)
turtle.left(winkel)
turtle.penup()
turtle.forward(-laenge)
turtle.pendown()
def moveTurtles(turtleList,dist,angle):
for turtle in turtleList: # Make every turtle on the list do the same actions.
turtle.forward(dist)
turtle.right(angle)
def draw_star(x, y, side):
star_angle = 360.0/6
left_angle = star_angle * 2
tu.penup()
tu.goto(x, y)
tu.pendown()
for i in range(6):
tu.forward(side)
tu.right(star_angle)
tu.forward(side)
tu.left(left_angle)
def tscheme_forward(n):
"""Move the turtle forward a distance N units on the current heading."""
_check_nums(n)
_tscheme_prep()
turtle.forward(n)
return okay
def tscheme_forward(n):
"""Move the turtle forward a distance N units on the current heading."""
_check_nums(n)
_tscheme_prep()
turtle.forward(n)
return okay
def draw_tree(h):
if h == 0:
return
turtle.forward(LENGTH * h)
turtle.left(ANGLE)
draw_tree(h - 1)
turtle.right(2 * ANGLE)
draw_tree(h - 1)
turtle.left(ANGLE)
turtle.backward(LENGTH * h)
def draw_house():
height = 5
width = 7
roofside = (width ** 2 / 2) ** (1 / 2)
turtle.forward(LENGTH * height) # left wall
turtle.right(45) # roof
turtle.forward(LENGTH * roofside)
turtle.right(90)
turtle.forward(LENGTH * roofside)
turtle.right(45)
turtle.forward(LENGTH * height) # right wall
turtle.right(90)
turtle.forward(LENGTH * width) # bottom line
turtle.right(90)
def draw_square(length, turtle):
for side in range(4):
turtle.forward(length)
turtle.left(90)
def tscheme_forward(n):
"""Move the turtle forward a distance N units on the current heading."""
_check_nums(n)
_tscheme_prep()
turtle.forward(n)
return okay
def printPolygon(sides, sideLength):
for steps in range(sides):
turtle.forward(sideLength)
turtle.right(360 / sides)
return
def main():
length = 128
sides = 3
while length != 1:
printPolygon(sides, length)
turtle.forward(length / 4)
sides += 1
length /= 2
return
# main()