本文整理汇总了Python中turtle.color方法的典型用法代码示例。如果您正苦于以下问题:Python turtle.color方法的具体用法?Python turtle.color怎么用?Python turtle.color使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块turtle的用法示例。
在下文中一共展示了turtle.color方法的29个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: draw_tree
点赞 7
# 需要导入模块: 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,
示例2: body
点赞 7
# 需要导入模块: 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,
示例3: tail
点赞 6
# 需要导入模块: 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,
示例4: square
点赞 6
# 需要导入模块: 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,
示例5: draw_pattern_rectangle
点赞 6
# 需要导入模块: 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,
示例6: item
点赞 6
# 需要导入模块: 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,
示例7: get_pixel_color
点赞 6
# 需要导入模块: 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,
示例8: writetext
点赞 5
# 需要导入模块: 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,
示例9: run_instruction
点赞 5
# 需要导入模块: 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,
示例10: draw_snowflake
点赞 5
# 需要导入模块: 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,
示例11: draw_circle
点赞 5
# 需要导入模块: 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,
示例12: init_pen
点赞 5
# 需要导入模块: 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,
示例13: head
点赞 5
# 需要导入模块: 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,
示例14: ear
点赞 5
# 需要导入模块: 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,
示例15: mouth
点赞 5
# 需要导入模块: 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,
示例16: hand
点赞 5
# 需要导入模块: import turtle [as 别名]
# 或者: from turtle import color [as 别名]
def hand():
'''
手
'''
t.color((255, 155, 192))
t.pu()
t.seth(90)
t.fd(-40)
t.seth(0)
t.fd(-27)
t.pd()
t.seth(-160)
t.circle(300, 15)
t.pu()
t.seth(90)
t.fd(15)
t.seth(0)
t.fd(0)
t.pd()
t.seth(-10)
t.circle(-20, 90)
t.pu()
t.seth(90)
t.fd(30)
t.seth(0)
t.fd(237)
t.pd()
t.seth(-20)
t.circle(-300, 15)
t.pu()
t.seth(90)
t.fd(20)
t.seth(0)
t.fd(0)
t.pd()
t.seth(-170)
t.circle(20, 90)
开发者ID:MiracleYoung,项目名称:You-are-Pythonista,代码行数:39,
示例17: foot
点赞 5
# 需要导入模块: import turtle [as 别名]
# 或者: from turtle import color [as 别名]
def foot():
'''
脚
'''
t.pensize(10)
t.color((240, 128, 128))
t.pu()
t.seth(90)
t.fd(-75)
t.seth(0)
t.fd(-180)
t.pd()
t.seth(-90)
t.fd(40)
t.seth(-180)
t.color("black")
t.pensize(15)
t.fd(20)
t.pensize(10)
t.color((240, 128, 128))
t.pu()
t.seth(90)
t.fd(40)
t.seth(0)
t.fd(90)
t.pd()
t.seth(-90)
t.fd(40)
t.seth(-180)
t.color("black")
t.pensize(15)
t.fd(20)
开发者ID:MiracleYoung,项目名称:You-are-Pythonista,代码行数:34,
示例18: show_particles
点赞 5
# 需要导入模块: import turtle [as 别名]
# 或者: from turtle import color [as 别名]
def show_particles(self, particles, show_frequency = 10):
turtle.shape('tri')
for i, particle in enumerate(particles):
if i % show_frequency == 0:
turtle.setposition((particle.x, particle.y))
turtle.setheading(90 - particle.heading)
turtle.color(self.weight_to_color(particle.weight))
turtle.stamp()
turtle.update()
开发者ID:leimao,项目名称:Particle_Filter,代码行数:14,
示例19: show_estimated_location
点赞 5
# 需要导入模块: import turtle [as 别名]
# 或者: from turtle import color [as 别名]
def show_estimated_location(self, particles):
'''
Show average weighted mean location of the particles.
'''
x_accum = 0
y_accum = 0
heading_accum = 0
weight_accum = 0
num_particles = len(particles)
for particle in particles:
weight_accum += particle.weight
x_accum += particle.x * particle.weight
y_accum += particle.y * particle.weight
heading_accum += particle.heading * particle.weight
if weight_accum == 0:
return False
x_estimate = x_accum / weight_accum
y_estimate = y_accum / weight_accum
heading_estimate = heading_accum / weight_accum
turtle.color('orange')
turtle.setposition(x_estimate, y_estimate)
turtle.setheading(90 - heading_estimate)
turtle.shape('turtle')
turtle.stamp()
turtle.update()
开发者ID:leimao,项目名称:Particle_Filter,代码行数:35,
示例20: show_robot
点赞 5
# 需要导入模块: import turtle [as 别名]
# 或者: from turtle import color [as 别名]
def show_robot(self, robot):
turtle.color('green')
turtle.shape('turtle')
turtle.shapesize(0.7, 0.7)
turtle.setposition((robot.x, robot.y))
turtle.setheading(90 - robot.heading)
turtle.stamp()
turtle.update()
开发者ID:leimao,项目名称:Particle_Filter,代码行数:11,
示例21: s
点赞 5
# 需要导入模块: import turtle [as 别名]
# 或者: from turtle import color [as 别名]
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)
开发者ID:furas,项目名称:python-examples,代码行数:40,
示例22: dragon
点赞 5
# 需要导入模块: import turtle [as 别名]
# 或者: from turtle import color [as 别名]
def dragon(level=1, remove_plus_minus=False, width=5):
a = 'FX'
rule = {
'X': 'X+YF+',
'Y': '-FX-Y',
'-': '-',
'+': '+',
'F': 'F',
}
for _ in range(level):
a = ''.join(rule[x] for x in a)
print('len:', len(a))
a = a.replace('X', '').replace('Y','')
print('len without X, Y:', len(a))
if remove_plus_minus:
a = a.replace('+-', '').replace('-+', '')
print('len without -+, +-:', len(a))
for x in a:
if x == 'F':
turtle.forward(width)
elif x == '+':
turtle.right(90)
turtle.color('red')
elif x == '-':
turtle.left(90)
turtle.color('green')
print('OK')
# --- main ---
# clear everything
开发者ID:furas,项目名称:python-examples,代码行数:41,
示例23: draw_rectangle
点赞 5
# 需要导入模块: import turtle [as 别名]
# 或者: from turtle import color [as 别名]
def draw_rectangle(width, height, color='red'):
turtle.pd()
turtle.color(color)
for _ in range(2):
turtle.forward(width)
turtle.left(90)
turtle.forward(height)
turtle.left(90)
开发者ID:furas,项目名称:python-examples,代码行数:11,
示例24: draw_circle
点赞 5
# 需要导入模块: import turtle [as 别名]
# 或者: from turtle import color [as 别名]
def draw_circle(radius, color='red'):
turtle.pd()
turtle.color(color)
turtle.circle(radius)
开发者ID:furas,项目名称:python-examples,代码行数:6,
示例25: item
点赞 5
# 需要导入模块: import turtle [as 别名]
# 或者: from turtle import color [as 别名]
def item(lenght, level, color):
if level <= 0:
return
for _ in range(8):
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)
开发者ID:furas,项目名称:python-examples,代码行数:17,
示例26: draw_rect
点赞 5
# 需要导入模块: import turtle [as 别名]
# 或者: from turtle import color [as 别名]
def draw_rect(x1, y1, width, height, color):
# canvas use different coordinates than turtle
y1 = -y1
# get access to tkinter.Canvas
canvas = turtle.getcanvas()
# draw using tkinter.Canvas
canvas.create_rectangle((x1, y1, x1+width, y1+height), fill=color, width=0)
开发者ID:furas,项目名称:python-examples,代码行数:9,
示例27: hexagone
点赞 5
# 需要导入模块: import turtle [as 别名]
# 或者: from turtle import color [as 别名]
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
开发者ID:furas,项目名称:python-examples,代码行数:36,
示例28: norse
点赞 4
# 需要导入模块: import turtle [as 别名]
# 或者: from turtle import color [as 别名]
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()
开发者ID:MiracleYoung,项目名称:You-are-Pythonista,代码行数:44,
示例29: eye
点赞 4
# 需要导入模块: import turtle [as 别名]
# 或者: from turtle import color [as 别名]
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()
开发者ID:MiracleYoung,项目名称:You-are-Pythonista,代码行数:46,
注:本文中的turtle.color方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。