当前位置: 首页>>代码示例>>Python>>正文


Python turtle.color方法代码示例

本文整理汇总了Python中turtle.color方法的典型用法代码示例。如果您正苦于以下问题:Python turtle.color方法的具体用法?Python turtle.color怎么用?Python turtle.color使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在turtle的用法示例。


在下文中一共展示了turtle.color方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: draw_tree

# 需要导入模块: import turtle [as 别名]
# 或者: from turtle import color [as 别名]
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) 
开发者ID:johnehunt,项目名称:advancedpython3,代码行数:23,代码来源:fractal_trees.py

示例2: body

# 需要导入模块: import turtle [as 别名]
# 或者: from turtle import color [as 别名]
def body():
    '''
    身体
    '''
    t.color("red", (255, 99, 71))
    t.pu()
    t.seth(90)
    t.fd(-20)
    t.seth(0)
    t.fd(-78)
    t.pd()
    t.begin_fill()
    t.seth(-130)
    t.circle(100, 10)
    t.circle(300, 30)
    t.seth(0)
    t.fd(230)
    t.seth(90)
    t.circle(300, 30)
    t.circle(100, 3)
    t.color((255, 155, 192), (255, 100, 100))
    t.seth(-135)
    t.circle(-80, 63)
    t.circle(-150, 24)
    t.end_fill() 
开发者ID:MiracleYoung,项目名称:You-are-Pythonista,代码行数:27,代码来源:xzpq.py

示例3: get_pixel_color

# 需要导入模块: import turtle [as 别名]
# 或者: from turtle import color [as 别名]
def get_pixel_color(x, y):

    # canvas use different coordinates than turtle
    y = -y

    # get access to tkinter.Canvas
    canvas = turtle.getcanvas()
    
    # find IDs of all objects in rectangle (x, y, x, y)
    ids = canvas.find_overlapping(x, y, x, y)

    # if found objects
    if ids: 
        # get ID of last object (top most)
        index = ids[-1]
        
        # get its color
        color = canvas.itemcget(index, "fill")
        
        # if it has color then return it
        if color:
            return color

    # if there was no object then return "white" - background color in turtle
    return "white" # default color 
开发者ID:furas,项目名称:python-examples,代码行数:27,代码来源:main.py

示例4: tail

# 需要导入模块: import turtle [as 别名]
# 或者: from turtle import color [as 别名]
def tail():
    '''
    尾巴
    '''
    t.pensize(4)
    t.color((255, 155, 192))
    t.pu()
    t.seth(90)
    t.fd(70)
    t.seth(0)
    t.fd(95)
    t.pd()
    t.seth(0)
    t.circle(70, 20)
    t.circle(10, 330)
    t.circle(70, 30) 
开发者ID:MiracleYoung,项目名称:You-are-Pythonista,代码行数:18,代码来源:xzpq.py

示例5: square

# 需要导入模块: import turtle [as 别名]
# 或者: from turtle import color [as 别名]
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() 
开发者ID:PacktPublishing,项目名称:Learning-Python-by-building-games,代码行数:20,代码来源:base.py

示例6: draw_pattern_rectangle

# 需要导入模块: import turtle [as 别名]
# 或者: from turtle import color [as 别名]
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) 
开发者ID:furas,项目名称:python-examples,代码行数:24,代码来源:main.py

示例7: item

# 需要导入模块: import turtle [as 别名]
# 或者: from turtle import color [as 别名]
def item(lenght, level, color):
    if level <= 0:
        return
    
    for _ in range(5):    # 5
        turtle.color(colors[color])
        turtle.forward(lenght)
        
        item(lenght/4, level-1, color+1)
        
        turtle.penup() # there is no need to draw again the same line  (and it can use differnt color)
        turtle.backward(lenght)
        turtle.pendown()
        
        turtle.right(360/8) # 8
    
    turtle.right(360/8 * 3) # 3 = 8 - 5 
开发者ID:furas,项目名称:python-examples,代码行数:19,代码来源:main-colors-asymmetrical.py

示例8: writetext

# 需要导入模块: import turtle [as 别名]
# 或者: from turtle import color [as 别名]
def writetext(text,color,x,y):
   for i in range(1,10):
      turtle.penup()
      turtle.setx(x)
      turtle.sety(y)
      turtle.pendown
   
   turtle.pencolor(color)
   turtle.write(text,move=True, font=("Arial",16,"normal")) 
开发者ID:remon,项目名称:pythonCodes,代码行数:11,代码来源:Palestine_en.py

示例9: run_instruction

# 需要导入模块: import turtle [as 别名]
# 或者: from turtle import color [as 别名]
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) 
开发者ID:lark-parser,项目名称:lark,代码行数:28,代码来源:turtle_dsl.py

示例10: draw_snowflake

# 需要导入模块: import turtle [as 别名]
# 或者: from turtle import color [as 别名]
def draw_snowflake(size):
    """ Draw a picture of a snowflake """
    turtle.penup()
    turtle.forward(10 * size)
    turtle.left(45)
    turtle.pendown()
    turtle.color(generate_random_colour())

    # draw branch 8 times to make a snowflake
    for _ in range(8):
        draw_branch(size)
        turtle.forward(size)
        turtle.left(45)

    turtle.penup() 
开发者ID:johnehunt,项目名称:advancedpython3,代码行数:17,代码来源:snowflake.py

示例11: draw_circle

# 需要导入模块: import turtle [as 别名]
# 或者: from turtle import color [as 别名]
def draw_circle(x, y, radius, red=50, green=255, blue=10, width=7):
    """ Draw a circle at a specific x, y location.
    Then draw four smaller circles recursively"""
    colour = (red, green, blue)

    # Recursively drawn smaller circles
    if radius > 50:
        # Calculate colours and line width for smaller circles
        if red < 216:
            red = red + 33
            green = green - 42
            blue = blue + 10
            width -= 1
        else:
            red = 0
            green = 255
        # Calculate the radius for the smaller circles
        new_radius = int(radius / 1.3)
        # Drawn four circles
        draw_circle(int(x + new_radius), y, new_radius, red, green, blue, width)
        draw_circle(x - new_radius, y, new_radius, red, green, blue, width)
        draw_circle(x, int(y + new_radius), new_radius, red, green, blue, width)
        draw_circle(x, int(y - new_radius), new_radius, red, green, blue, width)

    # Draw the original circle
    turtle.goto(x, y)
    turtle.color(colour)
    turtle.width(width)
    turtle.pendown()
    turtle.circle(radius)
    turtle.penup()


# Run the program 
开发者ID:johnehunt,项目名称:advancedpython3,代码行数:36,代码来源:circles-picture.py

示例12: init_pen

# 需要导入模块: import turtle [as 别名]
# 或者: from turtle import color [as 别名]
def init_pen():
    '''
    初始化画笔的一些属性
    '''
    t.pensize(4)  # 设置画笔的大小
    t.colormode(255)  # 设置GBK颜色范围为0-255
    t.color((255, 155, 192), "pink")  # 设置画笔颜色和填充颜色(pink)
    t.setup(900, 500)  # 设置主窗口的大小为900*500
    t.speed(10)  # 设置画笔速度为10 
开发者ID:MiracleYoung,项目名称:You-are-Pythonista,代码行数:11,代码来源:xzpq.py

示例13: head

# 需要导入模块: import turtle [as 别名]
# 或者: from turtle import color [as 别名]
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() 
开发者ID:MiracleYoung,项目名称:You-are-Pythonista,代码行数:37,代码来源:xzpq.py

示例14: ear

# 需要导入模块: import turtle [as 别名]
# 或者: from turtle import color [as 别名]
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() 
开发者ID:MiracleYoung,项目名称:You-are-Pythonista,代码行数:31,代码来源:xzpq.py

示例15: mouth

# 需要导入模块: import turtle [as 别名]
# 或者: from turtle import color [as 别名]
def mouth():
    '''
    嘴
    '''
    t.color(239, 69, 19)
    t.pu()
    t.seth(90)
    t.fd(15)
    t.seth(0)
    t.fd(-100)
    t.pd()
    t.seth(-80)
    t.circle(30, 40)
    t.circle(40, 80) 
开发者ID:MiracleYoung,项目名称:You-are-Pythonista,代码行数:16,代码来源:xzpq.py


注:本文中的turtle.color方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。