def _draw_agents(self):
     """ Draw all Agent objects to the screen """
     blue = pygame.Color(100, 100, 200)
     black = pygame.Color(0, 0, 0)
     green = pygame.Color(0, 255, 0)
     red = pygame.Color(255, 0, 0)
     for agent in self.model.agents:
         health = agent.health / 100.0
         health = util.clamp(health, 0, 1)
         pos = util.int_tuple(agent.get_pos())
         radians = agent.radians
         radius = agent.radius
         # Draw a black line showing current heading
         line_p0 = agent.get_pos()
         line_r = radius * 1.5
         line_p1 = (line_p0[0] + math.cos(radians) * line_r,
                    line_p0[1] + math.sin(radians) * line_r)
         pygame.draw.line(self.buffer, black, line_p0, line_p1, 2)
         # Draw a circle for the body. Blue for normal, red for attacking
         col = blue
         if agent.interact_attacked:
             col = red
         pygame.draw.circle(self.buffer, col, pos, radius, 0)
         pygame.draw.circle(self.buffer, black, pos, radius, 1)
         # Draw a green health bar
         rect = (int(agent.x) - 20, int(agent.y) - 30, 40, 3)
         pygame.draw.rect(self.buffer, red, rect)
         rect = (int(agent.x) - 20, int(agent.y) - 30, int(40 * health), 3)
         pygame.draw.rect(self.buffer, green, rect)
	def _draw_agents(self):
		""" Draw all Agent objects to the screen """
		blue = pygame.Color(100,100,200)
		black = pygame.Color(0,0,0)
		green = pygame.Color(0,255,0)
		red = pygame.Color(255,0,0)
		for agent in self.model.agents:
			health = agent.health / 100.0
			health = util.clamp(health, 0, 1)
			pos = util.int_tuple(agent.get_pos())
			radians = agent.radians
			radius = agent.radius
			# Draw a black line showing current heading
			line_p0 = agent.get_pos()
			line_r = radius * 1.5
			line_p1 = (line_p0[0] + math.cos(radians)*line_r,
					   line_p0[1] + math.sin(radians)*line_r)
			pygame.draw.line(self.buffer, black, line_p0, line_p1, 2)
			# Draw a circle for the body. Blue for normal, red for attacking
			col = blue
			if agent.interact_attacked:
				col = red
			pygame.draw.circle(self.buffer, col, pos, radius, 0)
			pygame.draw.circle(self.buffer, black, pos, radius, 1)
			# Draw a green health bar
			rect = (int(agent.x)-20, int(agent.y)-30, 40, 3)
			pygame.draw.rect(self.buffer, red, rect)
			rect = (int(agent.x)-20, int(agent.y)-30, int(40*health), 3)
			pygame.draw.rect(self.buffer, green, rect)
Example #3
0
File: img.py Project: abhishah/camo
def merge_ims(srcs, pts_or_rects, bg, opt = None):
  """ Makes a new image where each image in patches is copied at a
  corresponding pixel location.  Overlapping images are averaged
  together. """
  dst = bg.copy()
  layer = np.zeros(dst.shape)
  counts = np.zeros(dst.shape[:2], 'l')
  for src, r in itl.izip(srcs, pts_or_rects):
    r = ut.int_tuple(r)
    x, y = r[:2]

    # rescale if we're given a rectangle, and it has a different size
    if len(r) > 2:
      assert len(r) == 4
      assert opt != 'center'
      if src.shape[:2] != (r[3], r[2]):
        src = resize(src, (r[3], r[2]))
    elif opt == 'center':
      x -= src.shape[1]/2
      y -= src.shape[0]/2

    # crop intersecting 
    dx, dy, dw, dh = ut.crop_rect_to_img((x, y, src.shape[1], src.shape[0]), dst)
    sx = dx - x
    sy = dy - y
    layer[dy : dy + dh, dx : dx + dw] += src[sy : sy + dh, sx : sx + dw]
    counts[dy : dy + dh, dx : dx + dw] += 1
  dst[counts > 0] = layer[counts > 0] / counts[counts > 0][:, np.newaxis]
  return dst
def merge_ims(srcs, pts_or_rects, bg, opt=None):
    """ Makes a new image where each image in patches is copied at a
  corresponding pixel location.  Overlapping images are averaged
  together. """
    dst = rgb_from_gray(bg)
    layer = np.zeros(dst.shape)
    #counts = np.zeros(dst.shape[:2], 'l')
    counts = np.zeros(dst.shape[:2], 'd')
    for src, r in itl.izip(srcs, pts_or_rects):
        r = ut.int_tuple(r)
        x, y = r[:2]

        # rescale if we're given a rectangle, and it has a different size
        if len(r) > 2:
            assert len(r) == 4
            assert opt != 'center'
            if src.shape[:2] != (r[3], r[2]):
                src = resize(src, (r[3], r[2]))
        elif opt == 'center':
            x -= src.shape[1] / 2
            y -= src.shape[0] / 2

        # crop intersecting
        dx, dy, dw, dh = ut.crop_rect_to_img(
            (x, y, src.shape[1], src.shape[0]), dst)
        sx = dx - x
        sy = dy - y
        layer[dy:dy + dh, dx:dx + dw] += src[sy:sy + dh, sx:sx + dw, :3]
        if np.ndim(src) == 3 and src.shape[2] == 4:
            counts[dy:dy + dh, dx:dx +
                   dw] += np.array(src[sy:sy + dh, sx:sx + dw, 3], 'd') / 255.
        else:
            counts[dy:dy + dh, dx:dx + dw] += 1
    dst[counts > 0] = layer[counts > 0] / counts[counts > 0][:, np.newaxis]
    return dst
Example #5
0
File: img.py Project: abhishah/camo
  def f(draw):
    if font_size is None:
      font = None
    else:
      #font_name = '/usr/share/fonts/truetype/ttf-liberation/LiberationMono-Regular.ttf'
      font_name = '/usr/share/fonts/truetype/freefont/FreeMono.ttf'
      if not os.path.exists(font_name):
        raise RuntimeError('need to change hard-coded font path to make this work on other machines')
      font = ImageFont.truetype(font_name, size = font_size)  

    for pt, text, color in itl.izip(pts, texts, colors):
      draw.text(ut.int_tuple(pt), text, fill = color, font = font)
Example #6
0
    def f(draw):
        if font_size is None:
            font = None
        else:
            #font_name = '/usr/share/fonts/truetype/ttf-liberation/LiberationMono-Regular.ttf'
            font_name = '/usr/share/fonts/truetype/freefont/FreeMono.ttf'
            if not os.path.exists(font_name):
                raise RuntimeError(
                    'need to change hard-coded font path to make this work on other machines'
                )
            font = ImageFont.truetype(font_name, size=font_size)

        for pt, text, color in itl.izip(pts, texts, colors):
            draw.text(ut.int_tuple(pt), text, fill=color, font=font)
Example #7
0
  def f(draw):
    if font_size is None:
      font = None
    else:
      #font_name = '/usr/share/fonts/truetype/ttf-liberation/LiberationMono-Regular.ttf'
      font_choices = ['/usr/share/fonts/truetype/freefont/FreeMono%s.ttf' % ('Bold' if bold else ''), '/Library/Fonts/PTMono.ttc']
      for font_name in font_choices:
        if os.path.exists(font_name):
          break
      else:
        raise RuntimeError('could not find a suitable font on this machine (please edit paths in img.py)')

      font = ImageFont.truetype(font_name, size = font_size)  

    for pt, text, color in itl.izip(pts, texts, colors):
      draw.text(ut.int_tuple(pt), text, fill = color, font = font)
	def _draw_food(self):
		""" Draw all Food objects to the sceen """
		green = pygame.Color(0,200,0)
		for food in self.model.food:
			pygame.draw.circle(self.buffer, green,
							   util.int_tuple(food.get_pos()), food.radius, 0)
Example #9
0
File: img.py Project: abhishah/camo
 def f(draw):
   for p1, p2, c in itl.izip(pts1, pts2, colors):
     draw.line(ut.int_tuple(p1) + ut.int_tuple(p2), fill = c, width = width)
 def _draw_food(self):
     """ Draw all Food objects to the sceen """
     green = pygame.Color(0, 200, 0)
     for food in self.model.food:
         pygame.draw.circle(self.buffer, green,
                            util.int_tuple(food.get_pos()), food.radius, 0)
 def f(draw):
     for p1, p2, c in itl.izip(pts1, pts2, colors):
         draw.line(ut.int_tuple(p1) + ut.int_tuple(p2), fill=c, width=width)