本文整理汇总了Python中turtle.setheading函数的典型用法代码示例。如果您正苦于以下问题:Python setheading函数的具体用法?Python setheading怎么用?Python setheading使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setheading函数的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: show_sharks
def show_sharks(self, sharks):
self.update_cnt += 1
if UPDATE_EVERY > 0 and self.update_cnt % UPDATE_EVERY != 1:
return
turtle.clearstamps()
draw_cnt = 0
px = {}
for shark in sharks:
draw_cnt += 1
shark_shape = 'classic' if shark.tracked else 'classic'
if DRAW_EVERY == 0 or draw_cnt % DRAW_EVERY == 0:
# Keep track of which positions already have something
# drawn to speed up display rendering
scaled_x = int(shark.x * self.one_px)
scaled_y = int(shark.y * self.one_px)
scaled_xy = scaled_x * 10000 + scaled_y
turtle.color(shark.color)
turtle.shape(shark_shape)
turtle.resizemode("user")
turtle.shapesize(1.5,1.5,1)
if not scaled_xy in px:
px[scaled_xy] = 1
turtle.setposition(*shark.xy)
turtle.setheading(math.degrees(shark.h))
turtle.stamp()
示例3: show_robot
def show_robot(self, robot):
turtle.color("blue")
turtle.shape('square')
turtle.setposition(*robot.xy)
turtle.setheading(math.degrees(robot.h))
turtle.stamp()
turtle.update()
示例4: show_robot
def show_robot(self, robot):
turtle.color("green")
turtle.shape('turtle')
turtle.setposition(*robot.xy)
turtle.setheading(robot.h)
turtle.stamp()
turtle.update()
示例5: initBannerCanvas
def initBannerCanvas( numChars , numLines, scale ):
"""
Set up the drawing canvas to draw a banner numChars wide and numLines high.
The coordinate system used assumes all characters are 20x20 and there
are 10-point spaces between them.
Precondition: The initial canvas is default size, then input by the first
two user inputs, every input after that defines each letter's scale, probably between
1 and 3 for the scale values to have the window visible on the screen.
Postcondition: The turtle's starting position is at the bottom left
corner of where the first character should be displayed, the letters are printed.
"""
scale = int(input("scale, integer please"))
# This setup function uses pixels for dimensions.
# It creates the visible size of the canvas.
canvas_height = 80 * numLines *scale
canvas_width = 80 * numChars *scale
turtle.setup( canvas_width *scale, canvas_height *scale)
# This setup function establishes the coordinate system the
# program perceives. It is set to match the planned number
# of characters.
height = 30 *scale
width = 30 * numChars *scale
margin = 5 # Add a bit to remove the problem with window decorations.
turtle.setworldcoordinates(
-margin+1 * scale, -margin+1 * scale, width + margin* scale, numLines*height + margin * scale)
turtle.reset()
turtle.up()
turtle.setheading( 90 )
turtle.forward( ( numLines - 1 ) * 30 )
turtle.right( 90 )
turtle.pensize( 1 *scale)
示例6: main
def main():
'''Creates lsystem from filename and then creates an arrangement'''
# creates object from lsystem
l = ls.Lsystem('lsystemextension2.txt')
#number of iterations
# for growth effect in task 3, made iters a parameter
num_iter = 4
# creates buildstring function
s = l.buildString(num_iter)
#specific angle
angle = 30
#creates an object from TI class
ti = it.TurtleInterpreter()
# sets the colors of the tracer and calls the drawstring function
turtle.pencolor('ForestGreen')
'''tree with stem color of forestgreen'''
turtle.up()
turtle.setposition(0,0)
turtle.setheading(90)
turtle.down()
ti.drawString(s, 50 ,angle)
ti.hold()
示例7: entrance
def entrance(pointOne):
turtle.goto(pointOne[0], pointOne[1] + 36)
turtle.setheading(270)
turtle.pendown()
turtle.forward(15)
turtle.penup()
drawArrows()
示例8: drawP
def drawP(size):
turtle.setheading(90)
turtle.penup()
turtle.forward(size*1.5);
turtle.pendown()
turtle.forward(size*0.5);
drawSemi(size, direction="right", degrees=336, colour="black")
示例9: drawFins
def drawFins(size):
turtle.fillcolor("red")
turtle.setheading(90)
turtle.begin_fill()
turtle.forward(0.2*size)
turtle.left(120)
turtle.forward(0.6*size)
turtle.right(120)
turtle.forward(0.3*size)
turtle.right(40)
turtle.forward(0.8*size)
turtle.end_fill()
turtle.setheading(0)
turtle.begin_fill()
turtle.penup()
turtle.forward(size)
turtle.pendown()
turtle.begin_fill()
turtle.right(50)
turtle.forward(0.8*size)
turtle.right(40)
turtle.forward(0.3*size)
turtle.right(120)
turtle.forward(0.6*size)
turtle.end_fill()
示例10: draw_circle
def draw_circle(x,y,r,t):
t.pu()
t.goto(x+r,y)
t.setheading(90)
t.pd()
t.circle(r)
t.pu()
示例11: makeTree
def makeTree(h, l, b, d, ad):
Base(b)
turtle.color("brown")
if h > 0:
if h == 1:
turtle.color("green")
if h== 4:
Apple(b)
if d == 0:
makeTree(h-1 , l*.75, drawLimb(l, d*ad), d+1,ad)
else:
y = turtle.heading()
makeTree(h-1 , l*.75, drawLimb(l*.75, d*ad/2.00), d,ad)
Base(b)
d = d*-1
turtle.setheading(y)
makeTree(h-1 , l*.75, drawLimb(l*.75, d*ad/2.00), d,ad)
else:
Base(b)
示例12: draw_l
def draw_l(word):
turtle.up()
turtle.clear()
turtle.setposition(0, 0)
turtle.setheading(0)
turtle.bk(INITIAL_POS[0])
turtle.down()
turtle.st()
stack = []
for char in word:
if char == '0':
turtle.fd(SIZE[0])
if char == '1':
turtle.fd(SIZE[0])
if char == '[':
stack.append((turtle.position(), turtle.heading()))
turtle.lt(45)
if char == ']':
position, heading = stack.pop()
turtle.up()
turtle.setposition(position)
turtle.setheading(heading)
turtle.rt(45)
turtle.down()
turtle.ht()
示例13: move_to_start
def move_to_start(x_start, y_start): # в качестве параметром принимает координаты
x = x_start
y = y_start
turtle.penup() # отключаем рисование
turtle.setpos(x, y) # перемещаем turtle
turtle.setheading(DIRECT_DOWN) # разворачиваем на юг
turtle.pendown() # включаем рисование
示例14: circle
def circle(a,b):
turtle.color("green")
turtle.pu()
turtle.goto(a,b)
turtle.pd()
turtle.setheading(90)
turtle.circle(40)
示例15: h
def h(fill=False):
'''draws a capital H.
This is a DOCstring, which is a special comment that DOCuments our code. When you type help() in python it
displays these strings. Don't take my word for it... try it yourself!'''
turtle.setheading(0)
if fill: bf()
fd(10)
lt(90)
fd(50)
rt(90)
fd(20)
rt(90) # These things after the .'s are functions we can use, just like this h function!
fd(50)
lt(90)
fd(10)
lt(90)
fd(110)
lt(90)
fd(10)
lt(90)
fd(50)
rt(90)
fd(20)
rt(90)
fd(50)
lt(90)
fd(10)
lt(90)
fd(110)
lt(90)
if fill: ef() # single statement 'if' can be put on the same line
pu()
fd(50)
pd()