def paint(self, widget, event): """Nuestro metodo de pintado propio""" #Se crea un widget de cairo que despues se usara para desplegar #todo en la ventana cr = widget.window.cairo_create() #Le decimos a cairo que pinte su widget por primera vez. cr.set_source_rgb(0,0,0) cr.paint() #pintar a los agentes #display_lines(cr, self.annealedCells) display_simulation(cr,vir,self.annealedCells) self.hud.display(cr, vir+self.annealedCells) cr.move_to(5,15) text="Temperature = %f" % self.currentTemp cr.show_text(text) cr.move_to(5,30) text="Best Energy = %f" % self.bestEnergy cr.show_text(text) cr.move_to(5,45) text="Current Energy = %f" % self.currentEnergy cr.show_text(text) #pintar efecto de selección sobre un agente if self.objetoSeleccionado: cr.set_line_width(2) cr.set_source_rgba(random.random(), 1, random.random(), 0.3) cr.rectangle(self.objetoSeleccionado.posX-20,self.objetoSeleccionado.posY-20, self.objetoSeleccionado.width+40, self.objetoSeleccionado.height+40) cr.stroke()
def paint(self, widget, event): """Nuestro metodo de pintado propio""" #Se crea un widget de cairo que despues se usara para desplegar #todo en la ventana cr = widget.window.cairo_create() #Le decimos a cairo que pinte su widget por primera vez. cr.set_source_rgb(0,0,0) cr.paint() #paint game info cr.set_source_rgb(1,1,1) cr.save() cr.move_to(15,15) text="To next cell: %d" % (self.ticksToNextCell) cr.show_text(text) cr.restore() cr.set_source_rgb(1,1,1) cr.move_to(100, 15) cr.line_to(100,WINDOW_SIZE-15) cr.set_line_width(0.6) cr.stroke() #pintar a los agentes cr.set_line_width(1) if self.currentState=="Training": for i in xrange(len(self.classificationList)): text=str(self.classificationList[i]) if i==0: posXText=(self.divisionPoints[i])/2-(len(text)/2)*5 else: posXText=(self.divisionPoints[i-1]+self.divisionPoints[i])/2-(len(text)/2)*5 posYText=15 cr.save() cr.move_to(posXText,posYText) cr.set_source_rgba(1,1,1,0.7) cr.show_text(text) cr.restore() display_simulation(cr,[],self.cells) self.hud.display_cells(cr,self.cells) self.hud.display_viruses(cr, []) if self.currentState=="Running": for (cell,type) in self.trainingSet: cell.paint(cr) display_simulation(cr,self.virus,self.cells) self.hud.display_cells(cr,self.cells) self.hud.display_viruses(cr, self.virus) #pintar efecto de selección sobre un agente if self.objetoSeleccionado: cr.set_line_width(2) cr.set_source_rgba(random.random(), 1, random.random(), 0.3) cr.rectangle(self.objetoSeleccionado.posX-20,self.objetoSeleccionado.posY-20, self.objetoSeleccionado.width+40, self.objetoSeleccionado.height+40) cr.stroke() #paint score container cr.set_line_width(2) cr.set_source_rgba(1, 1, 1, 0.5) cr.rectangle(100+15,15,570, 5) cr.stroke() score1=self.virus[0].score+0.00000001 score2=self.virus[1].score+0.00000001 total=score1+score2 #paint first gauge cr.save() width1=score1*570/total cr.set_source_rgba(0, 1, 1, 1) cr.rectangle(100+15,15,width1, 5) cr.fill() cr.move_to(100+15,35) text="Fuzzy" cr.show_text(text) #paint second gauge width2=570-width1 cr.set_source_rgba(1, 0.4, 0, 1) cr.rectangle(100+15+width1,15,width2, 5) cr.fill() cr.move_to(670-25,35) text="Random" cr.show_text(text) cr.restore()
def paint(self, widget, event): """Nuestro metodo de pintado propio""" #Se crea un widget de cairo que despues se usara para desplegar #todo en la ventana cr = widget.window.cairo_create() #Le decimos a cairo que pinte su widget por primera vez. cr.set_source_rgb(0,0,0) cr.paint() #paint game info cr.set_source_rgb(1,1,1) cr.save() cr.move_to(15,15) text="To next cell: %d" % (self.ticksToNextCell) cr.show_text(text) cr.restore() #pintar a los agentes if self.currentState=="Training": for point in self.divisionPoints: cr.set_source_rgb(1,1,1) cr.move_to(point, 15) cr.line_to(point,WINDOW_SIZE-15) cr.set_line_width(0.6) cr.stroke() for i in xrange(len(self.classificationList)): text=str(self.classificationList[i]) if i==0: posXText=(self.divisionPoints[i])/2-(len(text)/2)*5 else: posXText=(self.divisionPoints[i-1]+self.divisionPoints[i])/2-(len(text)/2)*5 posYText=15 cr.save() cr.move_to(posXText,posYText) cr.set_source_rgba(1,1,1,0.7) cr.show_text(text) cr.restore() display_simulation(cr,[],self.cells) self.hud.display_cells(cr,self.cells) self.hud.display_viruses(cr, []) if self.currentState=="Running": cr.set_source_rgb(1,1,1) cr.move_to(15, WINDOW_SIZE-100) cr.line_to(WINDOW_SIZE-15,WINDOW_SIZE-100) cr.set_line_width(0.6) cr.stroke() for point in self.divisionPoints: cr.set_source_rgb(1,1,1) cr.move_to(point, WINDOW_SIZE-85) cr.line_to(point,WINDOW_SIZE-15) cr.set_line_width(0.6) cr.stroke() for i in xrange(len(self.classificationList)): text=str(self.classificationList[i]) if i==0: posXText=(self.divisionPoints[i])/2-(len(text)/2)*5 else: posXText=(self.divisionPoints[i-1]+self.divisionPoints[i])/2-(len(text)/2)*5 posYText=TRAINING_ZONE_LIMIT+15 cr.save() cr.move_to(posXText,posYText) cr.set_source_rgba(1,1,1,0.7) cr.show_text(text) cr.restore() for (cell,type) in self.trainingSet: cell.paint(cr) display_simulation(cr,self.virus,self.cells) self.hud.display_cells(cr,self.cells) self.hud.display_viruses(cr, self.virus) #pintar efecto de selección sobre un agente if self.objetoSeleccionado: cr.set_line_width(2) cr.set_source_rgba(random.random(), 1, random.random(), 0.3) cr.rectangle(self.objetoSeleccionado.posX-20,self.objetoSeleccionado.posY-20, self.objetoSeleccionado.width+40, self.objetoSeleccionado.height+40) cr.stroke() #coso if self.currentState == "Running": if self.virus[0].status == "Defending": cr.set_line_width(2) cr.set_source_rgba(1, random.random(), random.random(), 0.7) cr.arc(self.virus[0].posX+25,self.virus[0].posY+25, random.randint(40, 60),0, 360) cr.stroke()