本文整理汇总了Python中turtle.Turtle.begin_fill方法的典型用法代码示例。如果您正苦于以下问题:Python Turtle.begin_fill方法的具体用法?Python Turtle.begin_fill怎么用?Python Turtle.begin_fill使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类turtle.Turtle
的用法示例。
在下文中一共展示了Turtle.begin_fill方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: draw_table
# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import begin_fill [as 别名]
def draw_table(dimension: int, side: int, turtle: Turtle, x_coord: int, y_coord: int) -> None:
fill = False
for i in range(dimension ** 2):
if i % dimension == 0:
y_coord -= side
turtle.penup()
turtle.setpos(x_coord, y_coord)
turtle.pendown()
fill = fill != (dimension % 2 == 0)
if fill:
turtle.begin_fill()
for _ in range(4):
turtle.forward(side)
turtle.right(90)
if turtle.filling():
turtle.end_fill()
turtle.forward(side)
fill = not fill
done()
示例2: draw_chess_board
# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import begin_fill [as 别名]
def draw_chess_board(t: turtle.Turtle):
side = 40
for k in range(4):
for j in range(2):
for i in range(8):
if i % 2 == 0:
t.begin_fill()
t.forward(side)
t.left(90)
t.forward(side)
t.left(90)
t.forward(side)
t.left(90)
t.forward(side)
t.left(90)
t.end_fill()
t.forward(side)
side = -side
if k != 3:
t.right(90)
t.forward(2 * side)
t.left(90)
turtle.exitonclick()
示例3: Turtle
# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import begin_fill [as 别名]
from turtle import Turtle
p = Turtle()
p.speed(3)
p.pensize(5)
p.color("black", 'yellow')
p.begin_fill()
for i in range(5):
p.forward(200)
p.right(144)
p.end_fill()
示例4: Screen
# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import begin_fill [as 别名]
bot.color("green");
bot.speed("slowest");
#bot.setpos(x, y)
#bot.st()
bot.circle(50);
bot.clear()
window = Screen();
window.bgcolor("yellow");
#draw_triangle(3, 100, 100)
#draw_square(4, 200, 200)
#draw_circle(300, 300)
# 1. don't show trutle shape.
# 2. we need to draw multiple squres (360/10 = 36 squares)
# 3. each squre we should start with different angle (10 degrees).
# 4. for each square, createa turtle and call square function.
bot = Turtle()
#bot.ht()
bot.color("blue", "green");
bot.speed("fast");
bot.begin_fill()
for i in range(0, 36):
print (" square " + str(i * 10))
draw_triangle(bot, 10)
bot.end_fill()
window.exitonclick()
示例5: __init__
# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import begin_fill [as 别名]
class KeysMouseEvents:
def __init__(self):
super().__init__()
self.reinit()
def reinit(self):
self.T=Turtle()
self.screen=self.T.getscreen()
self.screen.onclick(self.drawcir)
self.screen.onkey(self.clear,"c")
self.T.pensize(5)
self.screen.listen()
self.count=0
self.firstx=0
self.firsty=0
self.secondx=0
self.secondy=0
self.T.hideturtle()
self.T.up()
def clear(self):
self.T.screen.clear()
self.reinit()
def drawcir(self,x,y):
self.count = (self.count + 1)
if self.count == 1:
self.T.color("black")
self.firstx=x
self.firsty=y
self.T.goto(x,y)
self.T.down()
self.T.dot()
self.T.up()
return
if self.count == 2:
self.secondx=x
self.secondy=y
X = self.secondx - self.firstx
Y = self.secondy - self.firsty
d = X * X + Y * Y
self.T.color("black")
radious = math.sqrt (d);
self.T.goto(self.firstx, self.firsty-radious)
self.T.down()
self.T.circle(radious)
self.T.up()
c = random.randint(1, 4)
if c == 1:
self.T.color("red")
if c == 2:
self.T.color("green")
if c == 3:
self.T.color("blue")
if c == 4:
self.T.color("yellow")
self.T.begin_fill()
radious=radious-4
self.T.goto(self.firstx, self.firsty-radious)
self.T.down()
self.T.circle(radious)
self.T.end_fill()
self.T.up()
self.T.color("black")
self.T.goto(self.firstx,self.firsty)
self.T.down()
self.T.dot()
self.T.up()
self.count=0
def main(self):
mainloop()
示例6: Zelva
# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import begin_fill [as 别名]
from turtle import Turtle as Zelva
BARVY = {1: "red", 2: "blue", 3: "white"}
POZICE = {1: (0, 0), 2: (120, 0), 3: (120, 60), 4: (0, 60)} # Levý spodní # Pravý spodní # Pravý horní # Levý hodní
if __name__ == "__main__":
# Nakreslíme červenou vlajku
vlajky = {}
vlajka = (1, 2, 3, 4, 1)
vlajky[vlajka] = "Bílá země"
z = Zelva()
z.speed(1)
barva = vlajka[-1]
z.fillcolor(BARVY[barva]) # Poslední prvek je číslo barvy
z.color = "black"
z.hideturtle()
z.begin_fill()
for bod in vlajka[:-1]:
z.setpos(*POZICE[bod])
z.setpos(0, 0)
z.end_fill()
示例7: __init__
# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import begin_fill [as 别名]
class KeysMouseEvents:
def __init__(self):
super().__init__()
self.reinit()
def reinit(self):
self.T=Turtle()
self.screen=self.T.getscreen()
self.screen.onclick(self.drawcir)
self.screen.onkey(self.clear,"c")
self.T.pensize(5)
self.screen.listen()
self.count=0
self.firstx=0
self.firsty=0
self.secondx=0
self.secondy=0
self.T.hideturtle()
self.T.up()
def clear(self):
self.T.screen.clear()
self.reinit()
def drawcir(self,x,y):
self.count = (self.count + 1)
if self.count == 1:
self.T.color("black")
self.firstx=x
self.firsty=y
self.T.goto(x,y)
self.T.down()
self.T.dot()
self.T.up()
return
if self.count == 2:
self.secondx=x
self.secondy=y
X = self.secondx - self.firstx
Y = self.secondy - self.firsty
d = X * X + Y * Y
self.T.color("black")
radius = math.sqrt (d);
len = math.sqrt (2*radius*radius)
a = len/2
b = math.sqrt((radius*radius)-(a*a))
self.T.goto(self.firstx-radius, self.firsty+radius)
self.T.down()
width = 2*radius
height = 2*radius
self.T.speed(0)
self.T.forward(width)
self.T.right(90)
self.T.forward(height)
self.T.right(90)
self.T.forward(width)
self.T.right(90)
self.T.forward(height)
self.T.right(90)
self.T.up()
x = random.randint(1, 7)
c = x
if c == 1:
self.T.color("red")
if c == 2:
self.T.color("green")
if c == 3:
self.T.color("blue")
if c == 4:
self.T.color("yellow")
if c == 5:
self.T.color("white")
if c == 6:
self.T.color("pink")
if c == 7:
self.T.color("brown")
if c == 8:
self.T.color("purple")
if c == 9:
self.T.color("gray")
if c == 10:
self.T.color("orange")
self.T.begin_fill()
radius1=radius-4
self.T.goto(self.firstx-radius1, self.firsty+radius1)
self.T.down()
width = 2*radius1
height = 2*radius1
self.T.speed(0)
self.T.forward(width)
self.T.right(90)
self.T.forward(height)
self.T.right(90)
self.T.forward(width)
self.T.right(90)
self.T.forward(height)
self.T.right(90)
#.........这里部分代码省略.........