Python源码示例:turtle.begin_fill()

示例1
def run_instruction(t):
    if t.data == 'change_color':
        turtle.color(*t.children)   # We just pass the color names as-is

    elif t.data == 'movement':
        name, number = t.children
        { 'f': turtle.fd,
          'b': turtle.bk,
          'l': turtle.lt,
          'r': turtle.rt, }[name](int(number))

    elif t.data == 'repeat':
        count, block = t.children
        for i in range(int(count)):
            run_instruction(block)

    elif t.data == 'fill':
        turtle.begin_fill()
        run_instruction(t.children[0])
        turtle.end_fill()

    elif t.data == 'code_block':
        for cmd in t.children:
            run_instruction(cmd)
    else:
        raise SyntaxError('Unknown instruction: %s' % t.data) 
示例2
def draw_leaf(turtle):
    turtle.fillcolor("greenyellow")
    turtle.begin_fill()
    
    base = turtle.pos()
    turtle.circle(100,75)
    turtle.goto(base)
    turtle.circle(-100,75)
    turtle.goto(base)
    turtle.end_fill() 
示例3
def head():
    '''
    头
    '''
    t.color((255, 155, 192), "pink")
    t.pu()
    t.seth(90)
    t.fd(41)
    t.seth(0)
    t.fd(0)
    t.pd()
    t.begin_fill()
    t.seth(180)
    t.circle(300, -30)  # 顺时针画一个半径为300,圆心角为30°的园
    t.circle(100, -60)
    t.circle(80, -100)
    t.circle(150, -20)
    t.circle(60, -95)
    t.seth(161)
    t.circle(-300, 15)
    t.pu()
    t.goto(-100, 100)
    t.pd()
    t.seth(-30)
    a = 0.4
    for i in range(60):
        if 0 <= i < 30 or 60 <= i < 90:
            a = a + 0.08
            t.lt(3)  # 向左转3度
            t.fd(a)  # 向前走a的步长
        else:
            a = a - 0.08
            t.lt(3)
            t.fd(a)
    t.end_fill() 
示例4
def ear():
    '''
    耳朵
    '''
    t.color((255, 155, 192), "pink")
    t.pu()
    t.seth(90)
    t.fd(-7)
    t.seth(0)
    t.fd(70)
    t.pd()
    t.begin_fill()
    t.seth(100)
    t.circle(-50, 50)
    t.circle(-10, 120)
    t.circle(-50, 54)
    t.end_fill()
    t.pu()
    t.seth(90)
    t.fd(-12)
    t.seth(0)
    t.fd(30)
    t.pd()
    t.begin_fill()
    t.seth(100)
    t.circle(-50, 50)
    t.circle(-10, 120)
    t.circle(-50, 56)
    t.end_fill() 
示例5
def blusher():
    '''
    腮
    '''
    t.color((255, 155, 192))
    t.pu()
    t.seth(90)
    t.fd(-95)
    t.seth(0)
    t.fd(65)
    t.pd()
    t.begin_fill()
    t.circle(30)
    t.end_fill() 
示例6
def square(x, y, size, name):
    """Draw square at `(x, y)` with side length `size` and fill color `name`.

    The square is oriented so the bottom left corner is at (x, y).

    """
    import turtle
    turtle.up()
    turtle.goto(x, y)
    turtle.down()
    turtle.color(name)
    turtle.begin_fill()

    for count in range(4):
        turtle.forward(size)
        turtle.left(90)

    turtle.end_fill() 
示例7
def s(n, l):

    if n == 0: # stop conditions

        # draw filled rectangle

        turtle.color('black')
        turtle.begin_fill()
        for _ in range (4):
            turtle.forward(l)
            turtle.left(90)
        turtle.end_fill()

    else: # recursion

        # around center point create 8 smalles rectangles.
        # create two rectangles on every side 
        # so you have to repeat it four times

        for _ in range(4):
            # first rectangle
            s(n-1, l/3)    
            turtle.forward(l/3)

            # second rectangle
            s(n-1, l/3)    
            turtle.forward(l/3)

            # go to next corner
            turtle.forward(l/3)
            turtle.left(90)
            
        # update screen
        turtle.update()

# --- main ---    

# stop updating screen (to make it faster) 
示例8
def hexagone(point, longueur,c):
   l = longueur

   x, y = point

   turtle.up()
   turtle.goto(point)
   turtle.color(c[0]) #black
   turtle.down()
   turtle.begin_fill() 
   turtle.goto(l * cos(4 / 3 * pi )+x, l * sin(4 / 3 * pi)+y)
   turtle.goto(l * cos(5 / 3 * pi)+x, l * sin(5 / 3 * pi)+y)
   turtle.goto(l * cos(0)+x, l * sin(0)+y) 
   turtle.goto(point) 
   turtle.end_fill()

   turtle.color(c[1])  #blue
   turtle.begin_fill()
   turtle.goto(l * cos(0)+x, l * sin(0)+y) 
   turtle.goto(l * cos(pi / 3)+x, l * sin(pi / 3)+y)
   turtle.goto(l * cos(pi * 2 / 3)+x, l * sin(pi * 2 / 3)+y)
   turtle.goto(point)  
   turtle.end_fill()

   turtle.color(c[2]) #red
   turtle.begin_fill()
   turtle.goto(l * cos(pi * 2 / 3)+x, l * sin(pi * 2 / 3)+y)
   turtle.goto(-l+x, 0+y)
   turtle.goto(l * cos(4 / 3 * pi)+x, l * sin(4 / 3 * pi)+y)
   turtle.goto(point)
   turtle.end_fill()
   turtle.up()

   return True 
示例9
def norse():
    '''
    鼻子
    '''
    t.pu()  # 提笔
    t.goto(-100, 100)  # 画笔前往坐标(-100,100)
    t.pd()  # 下笔
    t.seth(-30)  # 笔的角度为-30°
    t.begin_fill()  # 外形填充的开始标志
    a = 0.4
    for i in range(120):
        if 0 <= i < 30 or 60 <= i < 90:
            a = a + 0.08
            t.lt(3)  # 向左转3度
            t.fd(a)  # 向前走a的步长
        else:
            a = a - 0.08
            t.lt(3)
            t.fd(a)
    t.end_fill()  # 依据轮廓填充
    t.pu()  # 提笔
    t.seth(90)  # 笔的角度为90度
    t.fd(25)  # 向前移动25
    t.seth(0)  # 转换画笔的角度为0
    t.fd(10)
    t.pd()
    t.pencolor(255, 155, 192)  # 设置画笔颜色
    t.seth(10)
    t.begin_fill()
    t.circle(5)  # 画一个半径为5的圆
    t.color(160, 82, 45)  # 设置画笔和填充颜色
    t.end_fill()
    t.pu()
    t.seth(0)
    t.fd(20)
    t.pd()
    t.pencolor(255, 155, 192)
    t.seth(10)
    t.begin_fill()
    t.circle(5)
    t.color(160, 82, 45)
    t.end_fill() 
示例10
def eye():
    '''
    眼睛
    '''
    t.color((255, 155, 192), "white")
    t.pu()
    t.seth(90)
    t.fd(-20)
    t.seth(0)
    t.fd(-95)
    t.pd()
    t.begin_fill()
    t.circle(15)
    t.end_fill()
    t.color("black")
    t.pu()
    t.seth(90)
    t.fd(12)
    t.seth(0)
    t.fd(-3)
    t.pd()
    t.begin_fill()
    t.circle(3)
    t.end_fill()
    t.color((255, 155, 192), "white")
    t.pu()
    t.seth(90)
    t.fd(-25)
    t.seth(0)
    t.fd(40)
    t.pd()
    t.begin_fill()
    t.circle(15)
    t.end_fill()
    t.color("black")
    t.pu()
    t.seth(90)
    t.fd(12)
    t.seth(0)
    t.fd(-3)
    t.pd()
    t.begin_fill()
    t.circle(3)
    t.end_fill()