コード例 #1
0
ファイル: Visualizer.java プロジェクト: PurdueSIGAI/fishtank
 private void drawTooltip(FishState fishUnderMouse) {
   int tooltipHeight = 20, tooltipBottomMargin = 10;
   bufferGraphics.setColor(Color.WHITE);
   bufferGraphics.fillRect(
       0, buffer.getHeight() - tooltipHeight, buffer.getWidth(), tooltipHeight);
   bufferGraphics.setColor(Color.BLACK);
   if (fishUnderMouse != null) {
     bufferGraphics.drawString(
         String.format(
             "Frame %d ID %d, Nut %.2f, Change %.2f, Speed %.2f, Dir %s",
             state.seqID,
             fishUnderMouse.fish_id,
             fishUnderMouse.getNutrients(),
             Rules.decay(fishUnderMouse),
             fishUnderMouse.getSpeed(),
             fishUnderMouse.getRudderVector()),
         5,
         buffer.getHeight() - tooltipBottomMargin);
   } else {
     bufferGraphics.drawString(
         String.format(
             "Frame %d, Fish %d, Controllers %d, Max fish %d, Max nut %.2f",
             state.seqID,
             state.getNumFish(),
             state.getNumControllers(),
             state.getMaxFish(),
             state.getMaxNutrients()),
         5,
         buffer.getHeight() - tooltipBottomMargin);
   }
 }
コード例 #2
0
ファイル: Visualizer.java プロジェクト: PurdueSIGAI/fishtank
 private FishState drawFish() {
   FishState fishUnderMouse = null;
   for (FishState fs : state.getFish()) {
     if (fs.isAlive()) {
       Vector pos = fs.getPosition();
       // Draw tail and outline according to speed
       int tailBrightness = (int) ((double) fs.getSpeed() / Rules.MAX_SPEED * 255);
       bufferGraphics.setColor(Color.BLACK);
       bufferGraphics.drawLine(
           (int) pos.x,
           (int) pos.y,
           (int) (pos.x - fs.getRudderVector().x * fs.getRadius() * 2),
           (int) (pos.y - fs.getRudderVector().y * fs.getRadius() * 2));
       bufferGraphics.fillOval(
           (int) pos.x - fs.getRadius(),
           (int) pos.y - fs.getRadius(),
           2 * fs.getRadius(),
           2 * fs.getRadius());
       bufferGraphics.setColor(fishtank.getColor(fs.fish_id));
       bufferGraphics.fillOval(
           (int) pos.x - fs.getRadius() + 1,
           (int) pos.y - fs.getRadius() + 1,
           2 * fs.getRadius() - 2,
           2 * fs.getRadius() - 2);
     }
     if (fs.getPosition().minus(mousePosition).length() < fs.getRadius()) {
       fishUnderMouse = fs;
     }
   }
   return fishUnderMouse;
 }
コード例 #3
0
ファイル: Visualizer.java プロジェクト: PurdueSIGAI/fishtank
  private void drawFood() {
    for (Food food : state.getFood()) {
      bufferGraphics.setColor(Color.GREEN);
      bufferGraphics.fillOval(
          (int) (food.position.x - food.getRadius()),
          (int) (food.position.y - food.getRadius()),
          (int) (2 * food.getRadius()),
          (int) (2 * food.getRadius()));
    }

    bufferGraphics.setColor(Color.GREEN);
    /*
    for (int y = 0; y < Rules.tankHeight; y++) {
    	for (int x = 0; x < Rules.tankWidth; x++) {
    		if (fishtank.plants[x][y] != null) {
    			bufferGraphics.drawRect(x, y, 1, 1);
    		}
    	}
    }
    */
  }