本文整理汇总了Python中turtle.setpos函数的典型用法代码示例。如果您正苦于以下问题:Python setpos函数的具体用法?Python setpos怎么用?Python setpos使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setpos函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: draw_state
def draw_state(self):
"""
the core of the class
Interprete character:
F: move forward
+: turn right
-: turn left
[: push (position, heading)
]: pop (position, heading)
"""
import turtle
state = self.lsystem().state()
for c in state:
if c == 'F':
turtle.forward(self.length)
if c == '+':
turtle.right(self.angle)
if c == '-':
turtle.left(self.angle)
if c == '[':
self.stack.append((turtle.position(), turtle.heading()))
if c == ']':
if len(self.stack) == 0:
raise ValueError('inconsistant state: using to much `]`')
pos, head = self.stack.pop()
turtle.penup()
turtle.setpos(pos)
turtle.setheading(head)
turtle.pendown()
return self
示例2: forGlory
def forGlory(sideLength=50):
turtle.left(150)
turtle.penup()
turtle.setpos(-25,75)
turtle.color("blue")
turtle.pendown()
hexagon(sideLength)
示例3: doDraw
def doDraw(self, turtle):
turtle.pu()
turtle.setpos(self.x1, self.y1)
turtle.pd()
turtle.goto(self.x2, self.y2)
turtle.pu()
return
示例4: draw
def draw():
size = randint(40, 300)
angles = (144, 150, 157.5, 160, 165)
angle = sample(angles, 1)[0]
colors = [
('#922B21', '#E6B0AA'), ('#76448A', '#D2B4DE'), ('#1F618D', '#AED6F1'), ('#515A5A', '#EAEDED'),
('#148F77', '#D1F2EB'), ('#B7950B', '#F7DC6F'), ('#F39C12', '#FDEBD0'), ('#BA4A00', '#F6DDCC')]
color = sample(colors, 1)[0]
tt.color(color[0], color[1])
x_pos = randint(-200,200)
y_pos = randint(-200,200)
tt.pu()
tt.setpos(x_pos, y_pos)
start_position = tt.pos()
tt.pd()
tt.begin_fill()
while True:
tt.forward(size)
tt.left(angle)
if abs(tt.pos() - start_position) < 1:
break
tt.end_fill()
示例5: ex_good
def ex_good():
return 9, "bull"
# using turtle these coordinates draw a bull
import turtle
first = [146,399,163,403,170,393,169,391,166,386,170,381,170,371,170,355,169,346,167,335,170,329,170,320,170,
310,171,301,173,290,178,289,182,287,188,286,190,286,192,291,194,296,195,305,194,307,191,312,190,316,
190,321,192,331,193,338,196,341,197,346,199,352,198,360,197,366,197,373,196,380,197,383,196,387,192,
389,191,392,190,396,189,400,194,401,201,402,208,403,213,402,216,401,219,397,219,393,216,390,215,385,
215,379,213,373,213,365,212,360,210,353,210,347,212,338,213,329,214,319,215,311,215,306,216,296,218,
290,221,283,225,282,233,284,238,287,243,290,250,291,255,294,261,293,265,291,271,291,273,289,278,287,
279,285,281,280,284,278,284,276,287,277,289,283,291,286,294,291,296,295,299,300,301,304,304,320,305,
327,306,332,307,341,306,349,303,354,301,364,301,371,297,375,292,384,291,386,302,393,324,391,333,387,
328,375,329,367,329,353,330,341,331,328,336,319,338,310,341,304,341,285,341,278,343,269,344,262,346,
259,346,251,349,259,349,264,349,273,349,280,349,288,349,295,349,298,354,293,356,286,354,279,352,268,
352,257,351,249,350,234,351,211,352,197,354,185,353,171,351,154,348,147,342,137,339,132,330,122,327,
120,314,116,304,117,293,118,284,118,281,122,275,128,265,129,257,131,244,133,239,134,228,136,221,137,
214,138,209,135,201,132,192,130,184,131,175,129,170,131,159,134,157,134,160,130,170,125,176,114,176,
102,173,103,172,108,171,111,163,115,156,116,149,117,142,116,136,115,129,115,124,115,120,115,115,117,
113,120,109,122,102,122,100,121,95,121,89,115,87,110,82,109,84,118,89,123,93,129,100,130,108,132,110,
133,110,136,107,138,105,140,95,138,86,141,79,149,77,155,81,162,90,165,97,167,99,171,109,171,107,161,
111,156,113,170,115,185,118,208,117,223,121,239,128,251,133,259,136,266,139,276,143,290,148,310,151,
332,155,348,156,353,153,366,149,379,147,394,146,399]
second = [156,141,165,135,169,131,176,130,187,134,191,140,191,146,186,150,179,155,175,157,168,157,163,157,159,
157,158,164,159,175,159,181,157,191,154,197,153,205,153,210,152,212,147,215,146,218,143,220,132,220,
125,217,119,209,116,196,115,185,114,172,114,167,112,161,109,165,107,170,99,171,97,167,89,164,81,162,
77,155,81,148,87,140,96,138,105,141,110,136,111,126,113,129,118,117,128,114,137,115,146,114,155,115,
158,121,157,128,156,134,157,136,156,136]
def pairify(l):
return zip(l[::2], l[1::2])
pairs = pairify(first) + pairify(second)
for pair in pairs:
turtle.setpos(pair)
turtle.dot()
示例6: triangleDrawer
def triangleDrawer(startx, starty, length, head='top'):
coordsList = []
descrTriangle = {}
if head == 'top':
head = 120
t.color("black","black")
elif head == 'bottom':
head = 240
t.color("white","white")
t.setheading(0)
t.penup()
t.begin_fill()
t.setpos(startx, starty)
t.pendown()
coordsList.append(t.pos())
t.forward(length)
coordsList.append(t.pos())
t.setheading(head)
t.forward(length)
coordsList.append(t.pos())
if head == 120:
t.left(120)
else:
t.right(120)
t.forward(length)
t.end_fill()
descrTriangle['length'] = length
descrTriangle['coord'] = coordsList
return descrTriangle
示例7: turmandel
def turmandel(step, zoom, xres, yres, xthresh, ythresh):
turtle.setheading(0)
for y in range(yres):
turtle.pu()
turtle.setpos(0, y)
turtle.pd()
for x in range(xres):
x = float(x)
y = float(y)
u = float(x)/float((xres/zoom))-xthresh
v = float(y)/float((yres/zoom))-ythresh
x0 = float(u)
y0 = float(v)
a = 0.0
b = 0.0
i = step
while ((i>0) and (a+b<=4.0)):
a = float(x0*x0)
b = float(y0*y0)
y0 = float(2.0*x0*y0+v)
x0 = float(a-b+u)
i = i - 1
color = i % 255
turtle.pencolor((color, color, color))
if i < 1:
turtle.pencolor((0,0,0))
turtle.fd(1)
示例8: draw_arrow
def draw_arrow(turtle, cell_size, rotation=0):
pos = turtle.pos()
turtle.left(rotation)
turtle.back(cell_size*.2)
turtle.down()
turtle.left(90)
turtle.begin_fill()
turtle.forward(cell_size*.05)
turtle.right(90)
turtle.forward(cell_size*.3)
turtle.left(90)
turtle.forward(cell_size*.1)
turtle.right(120)
turtle.forward(cell_size*.3)
turtle.right(120)
turtle.forward(cell_size*.3)
turtle.right(120)
turtle.forward(cell_size*.1)
turtle.left(90)
turtle.forward(cell_size*.3)
turtle.right(90)
turtle.forward(cell_size*.05)
turtle.right(90)
turtle.forward(cell_size*.2)
turtle.end_fill()
turtle.up()
turtle.setpos(pos)
turtle.right(rotation)
示例9: draw_move
def draw_move(turtle, cell_size, offset, domino, dx, dy, move_num, step_count):
shade = (move_num-1) * 1.0/step_count
rgb = (0, 1-shade, shade)
turtle.forward((domino.head.x-offset[0]) * cell_size)
turtle.left(90)
turtle.forward((domino.head.y-offset[1]) * cell_size)
turtle.right(90)
turtle.setheading(domino.degrees)
turtle.forward(cell_size*.5)
turtle.setheading(math.atan2(dy, dx) * 180/math.pi)
pen = turtle.pen()
turtle.pencolor(rgb)
circle_pos = turtle.pos()
turtle.width(4)
turtle.forward(cell_size*0.05)
turtle.down()
turtle.forward(cell_size*0.4)
turtle.up()
turtle.pen(pen)
turtle.setpos(circle_pos)
turtle.forward(8)
turtle.setheading(270)
turtle.forward(8)
turtle.left(90)
turtle.down()
turtle.pencolor(rgb)
turtle.fillcolor('white')
turtle.begin_fill()
turtle.circle(8)
turtle.end_fill()
turtle.pen(pen)
turtle.write(move_num, align='center')
turtle.up()
示例10: drawname
def drawname(length):
"""
Draw name.
:pre: (relative) pos (200,0), heading (east), up
:post: (relative) pos (200 + 11*length + 9*length/5 + length/2 ,0), heading (east), up
:return: None
"""
turtle.up()
turtle.setpos(-320,0)
turtle.down()
drawM(length)
space(length/5)
drawA(length)
space(length/5)
drawY(length)
space(length/5)
drawA(length)
space(length/5)
drawN(length)
space(length/5)
drawK(length)
space(length/2)
drawJ(length)
space(length/5)
drawA(length)
space(length/5)
drawI(length)
space(length/5)
drawN(length)
space(length/5)
drawS(length)
示例11: draw_starrows
def draw_starrows(row):
color2 = 1
color = get_color(color2)
x = -160
y = 150
## This for loop draws 10 stars for each row above (5 total x 10 = 50).
for z in range(10):
x += 15
turtle.up()
turtle.color(color)
turtle.speed(100)
turtle.setpos(x,row)
turtle.begin_fill()
turtle.down()
turtle.forward(6.154)
turtle.left(144)
turtle.forward(6.154)
turtle.left(144)
turtle.forward(6.154)
turtle.left(144)
turtle.forward(6.154)
turtle.left(144)
turtle.forward(6.154)
turtle.left(144)
turtle.end_fill()
示例12: pop_right
def pop_right():
x,y,h = pos_stack.pop()
turtle.up()
turtle.setpos(x,y)
turtle.seth(h)
turtle.right(45)
turtle.down()
示例13: drawSootSprite
def drawSootSprite(N, R):
# reset direction
turtle.reset()
# draw star
drawStar(N, R)
# draw body
turtle.dot(0.8*2*R)
# draw right eyeball
turtle.fd(0.2*R)
turtle.dot(0.3*R, 'white')
# draw right pupil
turtle.pu()
turtle.bk(0.1*R)
turtle.pd()
turtle.dot(0.05*R)
turtle.pu()
# centre
turtle.setpos(0, 0)
# draw left eyeball
turtle.bk(0.2*R)
turtle.pd()
turtle.dot(0.3*R, 'white')
# draw left pupil
turtle.pu()
turtle.fd(0.1*R)
turtle.pd()
turtle.dot(0.05*R)
turtle.hideturtle()
示例14: drawCircle
def drawCircle(x, y, r):
turtle.up()
turtle.setpos(x+r,y)
turtle.down()
for i in range(0, DEGREES_IN_CIRCLE):
a = math.radians(i+1)
turtle.setpos(x+r*math.cos(a), y+r*math.sin(a))
示例15: triangle_drawer
def triangle_drawer(leftCornerCoord, sideSize, deep=5):
cornersCoord = []
initAngle = 60
# если достигли дна, т.е. deep=0, то закрашиваем треугольник черным
if deep > 1:
color = 'white'
else:
color = 'black'
turtle.color('black', color)
turtle.begin_fill()
turtle.penup()
turtle.setpos(leftCornerCoord[0],leftCornerCoord[1])
turtle.pendown()
turtle.setheading(initAngle)
cornersCoord.append(leftCornerCoord)
turtle.forward(sideSize)
turtle.right(initAngle*2)
cornersCoord.append(turtle.pos())
turtle.forward(sideSize)
turtle.right(initAngle*2)
cornersCoord.append(turtle.pos())
turtle.forward(sideSize)
turtle.end_fill()
return cornersCoord