本文整理汇总了Python中turtle.Turtle.mvBackward方法的典型用法代码示例。如果您正苦于以下问题:Python Turtle.mvBackward方法的具体用法?Python Turtle.mvBackward怎么用?Python Turtle.mvBackward使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类turtle.Turtle
的用法示例。
在下文中一共展示了Turtle.mvBackward方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import mvBackward [as 别名]
#.........这里部分代码省略.........
def parse(self):
self.parseSentence()
while True:
tokenAhead = self.lookNextToken()
if tokenAhead == None:
break
elif tokenAhead.type == EOF:
break
elif tokenAhead.type == KEYWORD:
self.parseSentence()
else:
break
def parseSentence(self):
#parsing
nextToken = self.lookNextToken()
if nextToken.value not in keywords:
print "Invalid input"
return
if nextToken.value in ['fd', 'bk', 'rt', 'lt']:
self.Match()
if(self.Match(NUMERIC) == -1):
return
# graphics
if nextToken.value == 'fd':
self.Turtle.mvForward(int(self.currToken().value), self.screen)
if nextToken.value == 'bk':
self.Turtle.mvBackward(int(self.currToken().value), self.screen)
if nextToken.value == 'lt':
self.Turtle.rotate(int(self.currToken().value))
if nextToken.value == 'rt':
self.Turtle.rotate(int(-1 * int(self.currToken().value)))
self.history.append((nextToken.value,self.currToken().value))
if nextToken.value in ['pu', 'pd', 'ht', 'st', 'penerase']:
self.Match()
if nextToken.value == 'pu':
self.Turtle.penUp()
if nextToken.value == 'pd':
self.Turtle.penDown()
if nextToken.value == 'st':
self.Turtle.showTurtle()
if nextToken.value == 'ht':
self.Turtle.hideTurtle()
self.history.append(nextToken.value)
if nextToken.value in ['setcolor']:
self.Match()
try:
self.Match(NUMERIC)
red = int(self.currToken().value)
self.Match(NUMERIC)
green = int(self.currToken().value)
self.Match(NUMERIC)
blue = int(self.currToken().value)
self.Turtle.setPenColor(red, green, blue)
self.history.append((nextToken.value, red, green, blue))
except ValueError as e:
print e
if nextToken.value in ['repeat']:
self.Match()
self.Match(NUMERIC)
timesToLoop = int(self.currToken().value)
self.Match('[')
savedIndex = self.index
for i in range(0, timesToLoop):
self.parse()
if i != timesToLoop -1:
self.index = savedIndex
self.Match(']')
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
self.screen.fill(self.white)
self.Turtle.draw(self.screen)
pygame.display.flip()
#raw_input()
def Match(self, expectedTokenType = None):
token = self.getNextToken()
if(expectedTokenType == None):
return
if(token.type != expectedTokenType):
print "Expected token type " + expectedTokenType + " but got " + token.type
return -1