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)
python类right()的实例源码
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 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_right(n):
"""Rotate the turtle's heading N degrees clockwise."""
_check_nums(n)
_tscheme_prep()
turtle.right(n)
return okay
def tscheme_circle(r, extent=None):
"""Draw a circle with center R units to the left of the turtle (i.e.,
right if N is negative. If EXTENT is not None, then draw EXTENT degrees
of the circle only. Draws in the clockwise direction if R is negative,
and otherwise counterclockwise, leaving the turtle facing along the
arc at its end."""
if extent is None:
_check_nums(r)
else:
_check_nums(r, extent)
_tscheme_prep()
turtle.circle(r, extent and extent)
return okay
def tscheme_right(n):
"""Rotate the turtle's heading N degrees clockwise."""
_check_nums(n)
_tscheme_prep()
turtle.right(n)
return okay
def tscheme_circle(r, extent = None):
"""Draw a circle with center R units to the left of the turtle (i.e.,
right if N is negative. If EXTENT is not None, then draw EXTENT degrees
of the circle only. Draws in the clockwise direction if R is negative,
and otherwise counterclockwise, leaving the turtle facing along the
arc at its end."""
if extent is None:
_check_nums(r)
else:
_check_nums(r, extent)
_tscheme_prep()
turtle.circle(r, extent and extent)
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 finish_drawing():
turtle.right(90)
turtle.up()
def tscheme_right(n):
"""Rotate the turtle's heading N degrees clockwise."""
_check_nums(n)
_tscheme_prep()
turtle.right(n)
return okay
def tscheme_circle(r, extent = None):
"""Draw a circle with center R units to the left of the turtle (i.e.,
right if N is negative. If EXTENT is not None, then draw EXTENT degrees
of the circle only. Draws in the clockwise direction if R is negative,
and otherwise counterclockwise, leaving the turtle facing along the
arc at its end."""
if extent is None:
_check_nums(r)
else:
_check_nums(r, extent)
_tscheme_prep()
turtle.circle(r, extent and extent)
return okay
def printPolygon(sides, sideLength):
for steps in range(sides):
turtle.forward(sideLength)
turtle.right(360 / sides)
return