本文整理汇总了Python中turtle.Turtle.draw方法的典型用法代码示例。如果您正苦于以下问题:Python Turtle.draw方法的具体用法?Python Turtle.draw怎么用?Python Turtle.draw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类turtle.Turtle
的用法示例。
在下文中一共展示了Turtle.draw方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import draw [as 别名]
class Parser:
def __init__(self, source):
self.T = Tokenizer(source)
self.tokenList = []
self.createTokenList()
self.dispTokenList()
self.index = -1
self.history = []
def reInit(self, source):
self.T = Tokenizer(source)
self.tokenList = []
self.createTokenList()
self.dispTokenList()
self.index = -1
self.history = []
def createTokenList(self):
#print "TOKENIZER STEP"
while True:
token = self.T.getToken()
if token is not None:
token.display()
self.tokenList.append(token)
if token.type == EOF:
break
#raw_input()
def dispTokenList(self):
for token in self.tokenList:
token.display()
def lookNextToken(self):
try:
return self.tokenList[self.index + 1]
except IndexError as e:
return None
def currToken(self):
return self.tokenList[self.index]
def getNextToken(self):
self.index += 1
return self.tokenList[self.index]
def graphInit(self):
#graphics part
pygame.init()
self.white = 255, 255 , 255
self.screen = pygame.display.set_mode((WINDOWX,WINDOWY))
self.Turtle = Turtle(WINDOWX,WINDOWY)
self.Turtle.setImage(pygame.image.load("logo2.png"))
self.screen.fill(self.white)
self.Turtle.draw(self.screen)
pygame.display.flip()
pygame.display.set_icon(pygame.image.load("logo2.png"))
pygame.display.set_caption(" Turtle")
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':
#.........这里部分代码省略.........