def render(self, color=None): ''' Draw the triangle agent with color''' # draw the ship egi.set_pen_color(name=self.color) pts = self.world.transform_points(self.vehicle_shape, self.pos, self.heading, self.side, self.scale) # draw it! egi.closed_shape(pts) # draw the border egi.blue_pen() egi.closed_shape(self.walls, False) egi.red_pen() egi.line_with_arrow(self.pos, self.pos + self.vel * 0.5, 5) #feeler1 # add some handy debug drawing info lines - force and velocity if self.show_info: s = 0.5 # <-- scaling factor # force egi.red_pen() egi.line_with_arrow(self.pos, self.pos + self.force * s, 5) # velocity egi.grey_pen() egi.line_with_arrow(self.pos, self.pos + self.vel * s, 5) # net (desired) change egi.white_pen() egi.line_with_arrow(self.pos+self.vel * s, self.pos+ (self.force+self.vel) * s, 5) egi.line_with_arrow(self.pos, self.pos+ (self.force+self.vel) * s, 5)
def render(self, color=None): ''' Draw the triangle agent with color''' # draw the ship egi.set_pen_color(name=self.color) pts = self.world.transform_points(self.vehicle_shape, self.pos, self.heading, self.side, self.scale) # draw it! egi.closed_shape(pts) #draw hiding spots egi.blue_pen() egi.circle(self.obstacles[0], 25) egi.circle(self.obstacles[1], 50) egi.circle(self.obstacles[2], 75) #draw detection box egi.blue_pen() length = 1.0 * (self.speed() / self.max_speed) * 3.0 #db length dbox = [ Point2D(-1.0, 0.6), Point2D(length, 0.6), #new Point2D(length, 0.0), #new Point2D(length, -0.6), #new Point2D(-1.0, -0.6) ] pts = self.world.transform_points(dbox, self.pos, self.heading, self.side, self.scale) egi.closed_shape(pts, False)
def render(self, color=None): ''' Draw the triangle agent with color''' # draw the ship egi.set_pen_color(name=self.color) pts = self.world.transform_points(self.vehicle_shape, self.pos, self.heading, self.side, self.scale) # draw it! egi.closed_shape(pts) # draw the border egi.blue_pen() egi.closed_shape(self.walls, False) egi.red_pen() egi.line_with_arrow(self.pos, self.pos + self.vel * 0.5, 5) #feeler1 # add some handy debug drawing info lines - force and velocity if self.show_info: s = 0.5 # <-- scaling factor # force egi.red_pen() egi.line_with_arrow(self.pos, self.pos + self.force * s, 5) # velocity egi.grey_pen() egi.line_with_arrow(self.pos, self.pos + self.vel * s, 5) # net (desired) change egi.white_pen() egi.line_with_arrow(self.pos + self.vel * s, self.pos + (self.force + self.vel) * s, 5) egi.line_with_arrow(self.pos, self.pos + (self.force + self.vel) * s, 5)
def draw(self): if self.mode == "Agent": if self.fsm: self.fsm.update() self.fsm.draw() egi.blue_pen() else: egi.red_pen() egi.set_stroke(4) egi.circle(Point2D(self.my_x, self.my_y), 10)
def update(self, delta): if not self.paused: for agent in self.agents: agent.update(delta) for hidingSpot in self.hidingSpots: egi.blue_pen() if self.bestHidingSpot: if self.bestHidingSpot == hidingSpot: egi.green_pen() egi.cross(hidingSpot, 10)
def render(self, color=None): egi.blue_pen() egi.cross(self.predictedtarget, 5) ''' Draw the triangle agent with color''' # draw the path if it exists and the mode is follow if self.mode == 'follow_path': ## ... self.path.render() pass if self.is_hit: self.visible = False # draw the ship egi.set_pen_color(name=self.color) pts = self.world.transform_points(self.vehicle_shape, self.pos, self.heading, self.side, self.scale) # draw it! egi.closed_shape(pts) self.is_hit = False # draw wander info? if self.mode == 'wander': wnd_pos = Vector2D(self.wander_dist, 0) wld_pos = self.world.transform_point(wnd_pos, self.pos, self.heading, self.side) # draw the wander circle egi.green_pen() egi.circle(wld_pos, self.wander_radius) # draw the wander target (little circle on the big circle) egi.red_pen() wnd_pos = (self.wander_target + Vector2D(self.wander_dist, 0)) wld_pos = self.world.transform_point(wnd_pos, self.pos, self.heading, self.side) egi.circle(wld_pos, 3) ## ... pass # add some handy debug drawing info lines - force and velocity if self.show_info: s = 0.5 # <-- scaling factor # force egi.red_pen() egi.line_with_arrow(self.pos, self.pos + self.force * s, 5) # velocity egi.grey_pen() egi.line_with_arrow(self.pos, self.pos + self.vel * s, 5) # net (desired) change egi.white_pen() egi.line_with_arrow(self.pos + self.vel * s, self.pos + (self.force + self.vel) * s, 5) egi.line_with_arrow(self.pos, self.pos + (self.force + self.vel) * s, 5)
def render(self): ''' Draw the path, open or closed, using the current pen colour. ''' # draw base line egi.blue_pen() if self.looped: egi.closed_shape(self._pts) else: egi.polyline(self._pts) # draw current waypoint egi.orange_pen() wp = self.current_pt() egi.circle(pos=wp, radius=5, slices=32)
def patrolSteer(self, delta): wanderForce = self.wander(delta) * self.state.wanderInfluence netForce = wanderForce if (self.chosenOne and self.world.drawDebug): egi.blue_pen() egi.line_by_pos(self.pos, self.pos + wanderForce * 5) egi.orange_pen() egi.line_by_pos(self.pos, self.pos + netForce * 5) return netForce
def patrolSteer(self, delta): wanderForce = self.wander(delta) * self.state.wanderInfluence netForce = wanderForce if(self.chosenOne and self.world.drawDebug): egi.blue_pen() egi.line_by_pos(self.pos, self.pos + wanderForce * 5) egi.orange_pen() egi.line_by_pos(self.pos, self.pos + netForce * 5) return netForce
def idleSteer(self, delta): wanderForce = self.wander(delta) * self.state['wanderInfluence'] flockForce = self.flock(delta) * self.flockingInfluence # obstaclesForce = self.obstacleAvoidance(self.world.solids) percentFromCenterX = (self.pos.x - self.world.center.x) / self.world.width percentFromCenterY = (self.pos.y - self.world.center.y) / self.world.height # Square the falloff valueX = -Util.sign(percentFromCenterX)*(self.maxCenterForce * percentFromCenterX**2) valueY = -Util.sign(percentFromCenterY)*(self.maxCenterForce * percentFromCenterY**2) centerForce = Vector2D(valueX, valueY) survivalSteer = self.survivalSteer(delta) foodForce = self.foodSteer(delta) * (1 + self.sickness / 10) self.maxSpeed = self.stat('speed') - (self.sickness / 2) netForce = wanderForce + flockForce + centerForce + survivalSteer + foodForce # print 'self.flockingInfluence', self.flockingInfluence if(self.chosenOne and self.world.drawDebug): egi.blue_pen() egi.line_by_pos(self.pos, self.pos + wanderForce * 5) egi.green_pen() egi.line_by_pos(self.pos, self.pos + flockForce * 5) egi.orange_pen() egi.line_by_pos(self.pos, self.pos + netForce * 5) egi.set_pen_color(name='BROWN') egi.line_by_pos(self.pos, self.pos + centerForce * 5) return netForce
def render(self, color=None): ''' Draw the triangle agent with color''' # draw the path if it exists and the mode is follow if self.mode == 'follow_path': ## ... self.path.render() pass if self.ishit: egi.red_pen() else: egi.blue_pen() # draw the ship egi.circle(self.pos, 20, True) self.ishit = False
def render(self): for hidingspot in self.hidingspots: egi.blue_pen() egi.cross(hidingspot, 5) for obstacle in self.obstacles: obstacle.render() self.hunter.render() for agent in self.agents: agent.render() if self.show_info: infotext = ', '.join(set(agent.mode for agent in self.agents)) egi.white_pen() egi.text_at_pos(0, 0, infotext)
def drawBody(self, color=None): egi.set_pen_color(color) if(self.world.drawDebug): if(self.isNeighbour): egi.blue_pen() if(self.tagged): egi.green_pen() if(self.chosenOne): if(self.world.drawDebug or self.world.drawComponentForces): egi.white_pen() pts = self.pointsInWorldSpace(self.vehicle_shape, self.renderPosition) # pts = self.world.transform_points(self.vehicle_shape, self.renderPosition, self.heading, self.side, self.scale) # draw it! egi.closed_shape(pts) self.drawEye(color)
def idleSteer(self, delta): wanderForce = self.wander(delta) * self.state['wanderInfluence'] flockForce = self.flock(delta) * self.flockingInfluence # obstaclesForce = self.obstacleAvoidance(self.world.solids) percentFromCenterX = (self.pos.x - self.world.center.x) / self.world.width percentFromCenterY = (self.pos.y - self.world.center.y) / self.world.height # Square the falloff valueX = -Util.sign(percentFromCenterX) * (self.maxCenterForce * percentFromCenterX**2) valueY = -Util.sign(percentFromCenterY) * (self.maxCenterForce * percentFromCenterY**2) centerForce = Vector2D(valueX, valueY) survivalSteer = self.survivalSteer(delta) foodForce = self.foodSteer(delta) * (1 + self.sickness / 10) self.maxSpeed = self.stat('speed') - (self.sickness / 2) netForce = wanderForce + flockForce + centerForce + survivalSteer + foodForce # print 'self.flockingInfluence', self.flockingInfluence if (self.chosenOne and self.world.drawDebug): egi.blue_pen() egi.line_by_pos(self.pos, self.pos + wanderForce * 5) egi.green_pen() egi.line_by_pos(self.pos, self.pos + flockForce * 5) egi.orange_pen() egi.line_by_pos(self.pos, self.pos + netForce * 5) egi.set_pen_color(name='BROWN') egi.line_by_pos(self.pos, self.pos + centerForce * 5) return netForce
def render(self): ''' Draw the path, open or closed, using the current pen colour. ''' for index, wp in enumerate(self._way_pts): egi.blue_pen() filled = False if (index < self._cur_pt_idx): egi.green_pen() if (index == self._cur_pt_idx): egi.orange_pen() filled = True egi.circle(pos=wp, radius=5, filled=filled, slices=32) egi.blue_pen() if self.looped: egi.closed_shape(self._way_pts) else: egi.polyline(self._way_pts)
def render(self): ''' Draw the path, open or closed, using the current pen colour. ''' for index, wp in enumerate(self._way_pts): egi.blue_pen() filled = False if(index < self._cur_pt_idx): egi.green_pen() if(index == self._cur_pt_idx): egi.orange_pen() filled = True egi.circle(pos=wp, radius=5, filled=filled, slices=32) egi.blue_pen() if self.looped: egi.closed_shape(self._way_pts) else: egi.polyline(self._way_pts)
def flock(self, delta): alignment = self.alignmentForce() separation = self.separationForce() cohesion = self.cohesionForce() if(self.chosenOne and self.world.drawComponentForces): s = 0.1 egi.green_pen() egi.line_with_arrow(self.pos, self.pos + alignment * s, 10) egi.blue_pen() egi.line_with_arrow(self.pos, self.pos + separation * s, 10) egi.red_pen() egi.line_with_arrow(self.pos, self.pos + cohesion * s, 10) egi.grey_pen() egi.line_with_arrow(self.pos, self.pos + self.force * s, 10) egi.circle(self.pos, self.neighbourDistance) return alignment + separation + cohesion
def bestHidingPlaceFromHunter(self, hidingPlaces, hunter, closest=True): closestPlaces = sorted(hidingPlaces, key=lambda p: p.distanceSq(self.pos)) if(closest): return closestPlaces[0] # Get the closest places that are out of range of the hunter safePlaces = [place for place in closestPlaces if not hunter.canSeePosition(place)] if(self.chosenOne and self.world.drawHidingSpots): egi.blue_pen() [egi.circle(p, 10) for p in safePlaces] # If there actually are some safe places then choose the closest (they'll still be in order) if(len(safePlaces)): return safePlaces[0] # If all hiding places are close to the hunter, then just pick the furthest return max(hidingPlaces, key=lambda p: p.distanceSq(hunter.pos))
def render(self): for agent in self.agents: if agent.mode == 'hunt': egi.blue_pen() for spot in agent.hiding_spots: egi.cross(spot, 10) elif agent.mode == 'prey': egi.green_pen() egi.circle(agent.best_spot, 10) agent.render() for obstacle in self.obstacles: obstacle.render() if self.target: egi.red_pen() egi.cross(self.target, 10) if self.show_info: infotext = ', '.join(set(agent.mode for agent in self.agents)) egi.white_pen() egi.text_at_pos(0, 0, infotext)
def render(self, color=None): ''' Draw moving target ''' #calculate target points self.movingTarget() #draw target using those points egi.blue_pen() dbox = [ Point2D(self.x0, self.y0), Point2D(self.x1, self.y0), Point2D(self.x1, self.y1), Point2D(self.x0, self.y1) ] egi.closed_shape(dbox, False) #pos of target self.target_pos = Vector2D(self.x0 + self.target_mid.x, self.y1 + self.target_mid.y) ''' Draw the triangle agent with color''' # draw the ship egi.set_pen_color(name=self.color) pts = self.world.transform_points(self.vehicle_shape, self.pos, self.heading, self.side, self.scale) # draw it! egi.closed_shape(pts) #draw bullets being fired egi.green_pen() if self.mode == 'rifle' or self.mode == 'rocket' or self.mode == 'handgun' or self.mode == 'grenade': if self.step_count == 0: egi.circle(self.bullet_pos, self.size) self.step_count += 1 elif self.bullet_pos.y > self.target_pos.y: self.step_count = 0 self.bullet_pos = Vector2D(250,250) self.mode = 'aim' else: self.bullet_pos += self.avg egi.circle(self.bullet_pos, self.size) self.step_count += 1
def render(self): egi.green_pen() egi.cross(self.pos, self.size) egi.blue_pen() egi.cross(self.aimpos, 5)
def render(self): egi.blue_pen() egi.circle(self.pos, 15)
def draw(self): egi.blue_pen() egi.circle(Point2D(self.my_x, self.my_y), 5)
def draw(self): egi.blue_pen() super().draw()
def render(self): egi.blue_pen() egi.circle(self.coords, self.radius)
def render(self): egi.blue_pen() egi.circle(self.pos, self.radius, True)
def render(self, color=None): ''' Draw the triangle agent with color''' color = None shape = None if (self != Agent.world.hunter): color = self.color shape = Agent.vehicle_shape else: color = 'RED' shape = Agent.hunter_shape egi.set_pen_color(name=color) pts = Agent.world.transform_points(shape, self.pos, self.heading, self.side, Agent.scale * Agent.floatScale) # draw it! egi.closed_shape(pts) #cap taget pos to window diameters if ((self.mode == 'pursuit' or self.mode == 'flee') and self == Agent.world.hunter): egi.green_pen() if self.hunterTargVec.y > Agent.world.cy: self.hunterTargVec = Vector2D(self.hunterTargVec.x, Agent.world.cy) elif self.hunterTargVec.y < 0: self.hunterTargVec = Vector2D(self.hunterTargVec.x, 0) if self.hunterTargVec.x > Agent.world.cx: self.hunterTargVec = Vector2D(Agent.world.cx, self.hunterTargVec.y) elif self.hunterTargVec.x < 0: self.hunterTargVec = Vector2D(0, self.hunterTargVec.y) egi.cross(self.hunterTargVec, 10) # add some handy debug drawing info lines - force and velocity if Agent.show_info: #s = 0.5 # <-- scaling factor # force egi.red_pen() egi.line_with_arrow(self.pos, self.pos + self.force, 5) #replaced s with Agent.floatScale # velocity egi.grey_pen() egi.line_with_arrow(self.pos, self.pos + self.vel, 5) #replaced s with Agent.floatScale # draw the path if it exists and the mode is follow if self.mode == 'follow_path': self.path.render() # draw wander info? elif self.mode == 'wander': # calculate the center of the wander circle in front of the agent wnd_pos = Vector2D(Agent.wander_dist * Agent.floatScale, 0) wld_pos = self.world.transform_point(wnd_pos, self.pos, self.heading, self.side) # draw the wander circle egi.green_pen() egi.circle(wld_pos, Agent.wander_radius * Agent.floatScale) # draw the wander target (little circle on the big circle) egi.red_pen() wnd_pos = (self.wander_target + Vector2D(Agent.wander_dist * Agent.floatScale, 0)) wld_pos = Agent.world.transform_point(wnd_pos, self.pos, self.heading, self.side) egi.circle(wld_pos, 3) #draw cohesion range egi.blue_pen() egi.circle(self.pos, Agent.cohesiveRange * Agent.floatScale) egi.red_pen() egi.circle(self.pos, Agent.seperationRange * Agent.floatScale) egi.green_pen() egi.circle(self.pos, Agent.alignmentRange * Agent.floatScale) if self == Agent.world.hunter: #draw panic dist and hide dist egi.aqua_pen() egi.circle(self.pos, Agent.panicDist * Agent.floatScale) egi.circle(self.pos, (Agent.panicDist + Agent.hiderange) * Agent.floatScale) for hidepos in self.hunterHidePositions: egi.aqua_pen() egi.line_by_pos(self.pos, hidepos[0]) #debugging #TODO REMOVE egi.orange_pen() egi.line_by_pos( self.pos, self.pos + self.AvoidEnvironmentRedirect(self.force))