本文整理汇总了Python中turtle.Turtle.dot方法的典型用法代码示例。如果您正苦于以下问题:Python Turtle.dot方法的具体用法?Python Turtle.dot怎么用?Python Turtle.dot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类turtle.Turtle
的用法示例。
在下文中一共展示了Turtle.dot方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ParsonTurtle
# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import dot [as 别名]
class ParsonTurtle(Turtle):
def __init__(self):
self._turtle = Turtle()
self._turtle.shape('turtle')
self._commands = []
def forward(self, dist, log=True):
self._turtle.forward(dist)
if log:
self._commands.append("fwd" + str(dist))
def fd(self, dist, log=True):
return self.forward(dist, log=log)
def backward(self, dist, log=True):
self._turtle.backward(dist)
if log:
self._commands.append("bwd" + str(dist))
def back(self, dist, log=True):
return self.backward(dist, log=log)
def bk(self, dist, log=True):
return self.backward(dist, log=log)
def left(self, angle, log=True):
self._turtle.left(angle)
if log:
self._commands.append("lt" + str(angle))
def lt(self, angle, log=True):
return self.left(angle, log=log)
def right(self, angle, log=True):
self._turtle.right(angle)
if log:
self._commands.append("rt" + str(angle))
def rt(self, angle, log=True):
return self.right(angle, log=log)
def goto(self, nx, ny, log=True):
self._turtle.goto(nx, ny)
if log:
self._commands.append("gt" + str(nx) + "-" + str(ny))
def setposition(self, nx, ny, log=True):
self._turtle.setposition(nx, ny)
if log:
self._commands.append("setpos" + str(nx) + "-" + str(ny))
def setpos(self, nx, ny, log=True):
return self.setposition(nx, ny, log=log)
def setx(self, nx, log=True):
self._turtle.setx(nx)
if log:
self._commands.append("setx" + str(nx))
def sety(self, ny, log=True):
self._turtle.sety(ny)
if log:
self._commands.append("sety" + str(ny))
def dot(self, size, color, log=True):
self._turtle.dot(size, color)
if log:
self._commands.append("dot" + str(size) + "-" + str(color))
def circle(self, radius, extent, log=True):
self._turtle.circle(radius, extent)
if log:
self._commands.append("circle" + str(radius) + "-" + str(extent))
def up(self, log=True):
self._turtle.up()
if log:
self._commands.append("up")
def penup(self, log=True):
return self.up(log=log)
def pu(self, log=True):
return self.up(log=log)
def down(self, log=True):
self._turtle.down()
if log:
self._commands.append("down")
def pendown(self, log=True):
return self.down(log=log)
def pd(self, log=True):
return self.down(log=log)
def speed(self, spd):
self._turtle.speed(spd)
def _logColorChange(self, command, color, green, blue):
if blue is not None:
self._commands.append("%s(%d, %d, %d)"%(command, color, green, blue))
else:
self._commands.append("%s(%s)"%(command, color))
def pencolor(self, color, green=None, blue=None, log=True):
if blue is not None:
self._turtle.pencolor(color, green, blue)
else:
#.........这里部分代码省略.........
示例2: __init__
# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import dot [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()
示例3: MazeGraphics
# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import dot [as 别名]
class MazeGraphics(object):
def __init__(self, config):
self.width = config.getValueAsInt("maze", "maze_size")
self.height = config.getValueAsInt("maze", "maze_size")
self.bg_color = config.getValue("maze", "bg_color")
self.line_color = config.getValue("maze", "line_color")
self.line_centroid_color = config.getValue("maze", "line_centroid_color")
self.forward_centroid_color = config.getValue("maze", "forward_centroid_color")
self.reverse_centroid_color = config.getValue("maze", "reverse_centroid_color")
self.path_color = config.getValue("maze", "path_color")
self.screen = Screen()
self.setupTurtle(self.width, self.height)
def setupTurtle(self, width, height):
self.screen.tracer(False)
self.screen.screensize(width, height)
# some basic turtle settings
self.screen.setworldcoordinates(-1, -1, width + 1, height + 1)
self.screen.title("Random Turtle Maze")
self.screen.bgcolor(self.bg_color)
self.screen.delay(None)
self.designer = Turtle(visible=False)
def drawGrid(self):
for i in xrange(0, self.width + 1):
self.drawXLines(i, self.width, self.line_color)
for i in xrange(0, self.height + 1):
self.drawYLines(i, self.width, self.line_color)
self.screen.update()
def drawXLines(self, position, width, color):
self.drawLines(position, 0, width, color, 90)
def drawYLines(self, position, width, color):
self.drawLines(0, position, width, color, 0)
def drawLines(self, xPosition, yPosition, width, color, heading):
self.designer.up()
self.designer.setposition(xPosition, yPosition)
self.designer.color(color)
self.designer.down()
self.designer.setheading(heading)
self.designer.forward(width)
self.designer.up()
def drawCentroid(self, cell, color):
"""
Draw a centroid for animation purposes but then overwrite it.
"""
self.designer.setposition(cell.centroid)
self.designer.dot(5, color)
self.screen.update()
self.designer.dot(5, self.bg_color)
def removeWall(self, posx, posy, heading, color):
"""
We tear down walls to build the maze
"""
self.designer.up()
self.designer.setposition(posx, posy)
self.designer.down()
self.designer.color(color)
self.designer.setheading(heading)
self.designer.forward(1)
self.designer.up()
self.screen.update()
def drawPath(self, cell1, cell2):
"""
This draws a line for the solution as it's worked out.
"""
self.designer.setposition(cell1.centroid)
self.designer.color(self.path_color)
direction = self.getDirection(cell1, cell2)
if direction == "N":
self.designer.setheading(90)
self.designer.down()
self.designer.forward(1)
self.designer.up()
elif direction == "S":
self.designer.setheading(270)
self.designer.down()
self.designer.forward(1)
self.designer.up()
elif direction == "W":
self.designer.setheading(0)
self.designer.down()
self.designer.forward(1)
self.designer.up()
elif direction == "E":
self.designer.setheading(0)
self.designer.down()
self.designer.backward(1)
self.designer.up()
self.drawCentroid(cell2, self.line_centroid_color)
self.screen.update()
def getDirection(self, currCell, nextCell):
direction = None
if nextCell.x < currCell.x:
#.........这里部分代码省略.........
示例4: draw_line
# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import dot [as 别名]
#Vykreslí posunutou šedou a pak bílou, 3d efekt
for (start, end) in maze:
offset = 0.5,0.5
draw_line(t, add_point(start,offset),
add_point(end,offset),
color="black", size=DISTANCE//2)
for (start, end) in maze:
draw_line(t, start, end,
color="gray", size=DISTANCE//2)
#Označí začátek a start
for point in (start_point, end_point):
t.up()
t.goto(*point)
t.down()
t.dot("red")
# A pokud se nám chce, najdeme si cestu.
g = create_graph_of_maze(maze)
p = find_path(start_point, end_point, graph=g)
for start,end in zip(p[:-1], p[1:]):
draw_line(t, start, end, color="red", size=3)
# Ukončení vykreslení želvy, pokud řádek chybí
# bůhví proč nevykreslí poslední hranu cesty.
# Nejspíš souvisí s nastavením traceru
t.up()
# t.goto(0,0)
示例5: __init__
# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import dot [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)
#.........这里部分代码省略.........