当前位置: 首页>>代码示例>>Python>>正文


Python Turtle.mvBackward方法代码示例

本文整理汇总了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
开发者ID:dominoanty,项目名称:Logo-Interpreter,代码行数:104,代码来源:main.py


注:本文中的turtle.Turtle.mvBackward方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。