Пример #1
0
        def start(self):
                try:
                    self.im = Image.fromarray(np.uint8(cm.gist_yarg(self.blocks)*255))

                    if self.start_point[0] < self.blocks.shape[1]-1:
                        self.start_point = (self.start_point[0]+1, self.start_point[1])

                    path = self.astar.get_path(self.start_point[0],
                                      self.start_point[1],
                                      self.end_point[0],
                                      self.end_point[1])

                    self.im.putpixel(self.start_point,(0,255,0))
                    for x in path:
                        self.im.putpixel((x[0], x[1]),(255,0,0))
                    self.im.putpixel(self.end_point,(0,0,255))

                    newy, newx = self.blocks.shape
                    scale = 8
                    self.im = self.im.resize((newx*scale, newy*scale))

                    self.photo = ImageTk.PhotoImage(image=self.im)
                    self.canvas.create_image(0,0,image=self.photo,anchor=Tkinter.NW)
                    self.root.update()
                    self.times+=1
                    if self.times%33==0:
                            print "%.02f FPS"%(self.times/(time.clock()-self.timestart))
                    self.root.after(2000,self.start)
                except Exception as e:

                    print e
                    self.root.after(10,self.start)
Пример #2
0
        def start(self):
                
                try:
                    gamedata = pickle.load(open(gameplayDataFilepath, 'rb'))
                    blocks = gamedata['blockHeights']
                    
                    #normalize block heights
                    for a,x in enumerate(blocks):
                        for b,y in enumerate(x):
                            if blocks[a][b] > 1.0:
                                blocks[a][b] = 1.0
                            elif blocks[a][b] == 1.0:
                                blocks[a][b] = 0.5
                    
                    blocks = np.array(blocks)
                    blocks = blocks.transpose()
                    #self.im = Image.fromarray(np.uint8(cm.gist_yarg(blocks)*255))
                    
                    mapWidth = len(blocks)
                    mapHeight = len(blocks[0])
                    probOccMap = gamedata['probOccMap']



                    probOccMap = np.array(probOccMap).reshape(mapWidth, mapHeight)
                    probOccMap += 0.2 * blocks
                     

                    #probOccMap[11,7] = 0.3


                    self.im = Image.fromarray(np.uint8(cm.gist_yarg(probOccMap)*255))

                    #print mapWidth, mapHeight
                    #print probOccMap
                    #print probOccMap.shape


                    #Set bot positions
                    for pos in gamedata['bot_positions']:
                        self.im.putpixel(pos,(0,0,255))

                    newy, newx = blocks.shape
                    scale = 8
                    self.im = self.im.resize((newx*scale, newy*scale))
                    
                    self.photo = ImageTk.PhotoImage(image=self.im)
                    self.canvas.create_image(0,0,image=self.photo,anchor=Tkinter.NW)
                    self.root.update()
                    self.times+=1
                    if self.times%33==0:
                            print "%.02f FPS"%(self.times/(time.clock()-self.timestart))
                    self.root.after(10,self.start)
                except Exception as e:
                    
                    print e
                    self.root.after(10,self.start)