Python源码示例:turtle.right()

示例1
def draw_tree(length, width=9):
    color = 'brown'
    if length < 1:
        return
    elif length < 3:
        color = 'green'

    if width < 1:
        width = 1

    turtle.color(color)
    turtle.width(width)
    turtle.forward(length)
    turtle.left(30)
    draw_tree(length / FACTOR, width - 1)
    turtle.right(60)
    draw_tree(length / FACTOR, width - 1)
    turtle.left(30)
    turtle.color(color)
    turtle.width(width)
    turtle.backward(length) 
示例2
def gear(count, width, height):

    angle = 90-(180/count)

    for _ in range(count):
        turtle.forward(width)
        turtle.left(angle)
        turtle.forward(height)
        turtle.right(90)
        turtle.forward(width)
        turtle.right(90)
        turtle.forward(height)
        turtle.left(angle)

# --- main ---

# clear everything 
示例3
def gear(count, width, height):

    angle = 90-(180/count)

    for _ in range(count):
        turtle.forward(width)
        turtle.left(angle)
        turtle.forward(height)
        turtle.right(90)
        turtle.forward(width)
        turtle.right(90)
        turtle.forward(height)
        turtle.left(angle)

# --- main ---

# clear everything 
示例4
def draw_pattern_rectangle(x, y, width, height, count, radius, color='red'):
    rotation = 360 / count

    turtle.goto(x, y)
    
    for _ in range(count):
        # move from center to circle
        turtle.pu()
        #turtle.color('black')
        turtle.forward(radius)
        turtle.right(90+rotation/2)
        
        draw_rectangle(width, height, color)

        # move from circle to center
        turtle.pu()
        #turtle.color('black')
        turtle.left(90+rotation/2)
        turtle.backward(radius)

        # rotate in circle
        turtle.right(rotation) 
示例5
def draw_pattern_circle(x, y, r, count, radius, color='red'):
    rotation = 360 / count

    turtle.goto(x, y)

    for _ in range(count):
        # move from center to circle
        #turtle.pu()
        turtle.color('black')
        turtle.forward(radius)
        turtle.right(90)

        draw_circle(r, color)

        # move from circle to center
        #turtle.pu()
        turtle.color('black')
        turtle.left(90)
        turtle.backward(radius)

        # rotate in circle
        turtle.right(rotation) 
示例6
def createClock(radius):
	turtle.reset()
	turtle.pensize(7)
	for i in range(60):
		move(radius)
		if i % 5 == 0:
			turtle.forward(20)
			move(-radius-20)
		else:
			turtle.dot(5)
			move(-radius)
		turtle.right(6) 
示例7
def startTick(second_hand, minute_hand, hour_hand, printer):
	today = datetime.datetime.today()
	second = today.second + today.microsecond * 1e-6
	minute = today.minute + second / 60.
	hour = (today.hour + minute / 60) % 12
	# 设置朝向
	second_hand.setheading(6 * second)
	minute_hand.setheading(6 * minute)
	hour_hand.setheading(12 * hour)
	turtle.tracer(False)
	printer.forward(65)
	printer.write(getWeekday(today), align='center', font=("Courier", 14, "bold"))
	printer.forward(120)
	printer.write('12', align='center', font=("Courier", 14, "bold"))
	printer.back(250)
	printer.write(getDate(today), align='center', font=("Courier", 14, "bold"))
	printer.back(145)
	printer.write('6', align='center', font=("Courier", 14, "bold"))
	printer.home()
	printer.right(92.5)
	printer.forward(200)
	printer.write('3', align='center', font=("Courier", 14, "bold"))
	printer.left(2.5)
	printer.back(400)
	printer.write('9', align='center', font=("Courier", 14, "bold"))
	printer.home()
	turtle.tracer(True)
	# 100ms调用一次
	turtle.ontimer(lambda: startTick(second_hand, minute_hand, hour_hand, printer), 100) 
示例8
def draw_branch(size):
    """ Draw an individual branch on a snowflake """
    side_branch_size = size / 3
    for _ in range(3):
        for i in range(3):
            turtle.forward(side_branch_size)
            turtle.backward(side_branch_size)
            turtle.right(45)
        turtle.left(90)
        turtle.backward(side_branch_size)
        turtle.left(45)
    turtle.right(90) 
示例9
def draw_square(size):
    """ Function to draw a square """
    turtle.forward(size)
    turtle.right(90)
    turtle.forward(size)
    turtle.right(90)
    turtle.forward(size)
    turtle.right(90)
    turtle.forward(size) 
示例10
def draw_square(size):
    """ Draw a square in the current direction """
    turtle.forward(size)
    turtle.right(90)
    turtle.forward(size)
    turtle.right(90)
    turtle.forward(size)
    turtle.right(90)
    turtle.forward(size) 
示例11
def draw_1(length, level):
    if level < 1:
        turtle.fd(length)
    else:
        length = length/3
        
        draw_1(length, level-1)
        turtle.left(90)
        draw_1(length, level-1)
        turtle.right(90)
        draw_1(length, level-1)
        turtle.right(90)
        draw_1(length, level-1)
        turtle.left(90)
        draw_1(length, level-1) 
示例12
def draw_2(length, level):
    if level < 1:
        turtle.fd(length)
    else:
        length = length/3
        
        draw_2(length, level-1)
        turtle.left(60)
        draw_2(length, level-1)
        turtle.right(180-60)
        draw_2(length, level-1)
        turtle.left(60)
        draw_2(length, level-1) 
示例13
def turn_right(width, step, draw):
    for _ in range(4):
        draw(width, step)
        turtle.right(90)

# --- main ---

# clear everything 
示例14
def draw_1(length, level):
    if level < 1:
        turtle.fd(length)
    else:
        length = length/3
        
        draw_1(length, level-1)
        turtle.left(90)
        draw_1(length, level-1)
        turtle.right(90)
        draw_1(length, level-1)
        turtle.right(90)
        draw_1(length, level-1)
        turtle.left(90)
        draw_1(length, level-1) 
示例15
def draw_2(length, level):
    if level < 1:
        turtle.fd(length)
    else:
        length = length/3
        
        draw_2(length, level-1)
        turtle.left(60)
        draw_2(length, level-1)
        turtle.right(180-60)
        draw_2(length, level-1)
        turtle.left(60)
        draw_2(length, level-1) 
示例16
def draw_1(length, level):
    if level < 1:
        turtle.fd(length)
    else:
        length = length/3
        
        draw_1(length, level-1)
        turtle.left(90)
        draw_1(length, level-1)
        turtle.right(90)
        draw_1(length, level-1)
        turtle.right(90)
        draw_1(length, level-1)
        turtle.left(90)
        draw_1(length, level-1) 
示例17
def draw_2(length, level):
    if level < 1:
        turtle.fd(length)
    else:
        length = length/3
        
        draw_2(length, level-1)
        turtle.left(60)
        draw_2(length, level-1)
        turtle.right(180-60)
        draw_2(length, level-1)
        turtle.left(60)
        draw_2(length, level-1) 
示例18
def turn_right(width, step, draw):
    for _ in range(4):
        draw(width, step)
        turtle.right(90)

# --- main ---

# clear everything 
示例19
def draw_1(length, level):
    if level < 1:
        turtle.fd(length)
    else:
        length = length/3
        
        draw_1(length, level-1)
        turtle.left(90)
        draw_1(length, level-1)
        turtle.right(90)
        draw_1(length, level-1)
        turtle.right(90)
        draw_1(length, level-1)
        turtle.left(90)
        draw_1(length, level-1) 
示例20
def draw_2(length, level):
    if level < 1:
        turtle.fd(length)
    else:
        length = length/3
        
        draw_2(length, level-1)
        turtle.left(60)
        draw_2(length, level-1)
        turtle.right(180-60)
        draw_2(length, level-1)
        turtle.left(60)
        draw_2(length, level-1) 
示例21
def draw_1(length, level):
    if level < 1:
        turtle.fd(length)
    else:
        length = length/3
        
        draw_1(length, level-1)
        turtle.left(90)
        draw_1(length, level-1)
        turtle.right(90)
        draw_1(length, level-1)
        turtle.right(90)
        draw_1(length, level-1)
        turtle.left(90)
        draw_1(length, level-1) 
示例22
def draw_2(length, level):
    if level < 1:
        turtle.fd(length)
    else:
        length = length/3
        
        draw_2(length, level-1)
        turtle.left(60)
        draw_2(length, level-1)
        turtle.right(180-60)
        draw_2(length, level-1)
        turtle.left(60)
        draw_2(length, level-1) 
示例23
def turn_right(width, step, draw):
    for _ in range(4):
        draw(width, step)
        turtle.right(90)

# --- main ---

# clear everything 
示例24
def draw_1(length, level):
    if level < 1:
        turtle.fd(length)
    else:
        length = length/3
        
        draw_1(length, level-1)
        turtle.left(90)
        draw_1(length, level-1)
        turtle.right(90)
        draw_1(length, level-1)
        turtle.right(90)
        draw_1(length, level-1)
        turtle.left(90)
        draw_1(length, level-1) 
示例25
def draw_2(length, level):
    if level < 1:
        turtle.fd(length)
    else:
        length = length/3
        
        draw_2(length, level-1)
        turtle.left(60)
        draw_2(length, level-1)
        turtle.right(180-60)
        draw_2(length, level-1)
        turtle.left(60)
        draw_2(length, level-1) 
示例26
def draw_1(length, level):
    if level < 1:
        turtle.fd(length)
    else:
        length = length/3
        
        draw_1(length, level-1)
        turtle.left(90)
        draw_1(length, level-1)
        turtle.right(90)
        draw_1(length, level-1)
        turtle.right(90)
        draw_1(length, level-1)
        turtle.left(90)
        draw_1(length, level-1) 
示例27
def draw_2(length, level):
    if level < 1:
        turtle.fd(length)
    else:
        length = length/3
        
        draw_2(length, level-1)
        turtle.left(60)
        draw_2(length, level-1)
        turtle.right(180-60)
        draw_2(length, level-1)
        turtle.left(60)
        draw_2(length, level-1) 
示例28
def turn_right(width, step, draw):
    for _ in range(4):
        draw(width, step)
        turtle.right(90)

# --- main ---

# clear everything 
示例29
def draw_1(length, level):
    if level < 1:
        turtle.fd(length)
    else:
        length = length/3
        
        draw_1(length, level-1)
        turtle.left(90)
        draw_1(length, level-1)
        turtle.right(90)
        draw_1(length, level-1)
        turtle.right(90)
        draw_1(length, level-1)
        turtle.left(90)
        draw_1(length, level-1) 
示例30
def draw_2(length, level):
    if level < 1:
        turtle.fd(length)
    else:
        length = length/3
        
        draw_2(length, level-1)
        turtle.left(60)
        draw_2(length, level-1)
        turtle.right(180-60)
        draw_2(length, level-1)
        turtle.left(60)
        draw_2(length, level-1)