Example #1
0
 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;
 }
Example #2
0
  private void drawJuliaLine() {
    int x0, y0, x1 = 0, y1 = 0, list_size;

    Graphics2D full_image_g = image.createGraphics();

    pixel_orbit.calculateJuliaOrbit();

    full_image_g.setColor(orbit_color);

    full_image_g.setRenderingHint(
        RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    list_size = complex_orbit.size() - 1;

    double size = pixel_orbit.getSize();
    int image_size = ptr.getImageSize();

    double temp_xcenter_size = pixel_orbit.getXCenter() - size / 2;
    double temp_ycenter_size = pixel_orbit.getYCenter() - size / 2;
    double temp_size_image_size = size / image_size;

    for (int i = 0; i < list_size; i++) {
      x0 = (int) ((complex_orbit.get(i).getRe() - temp_xcenter_size) / temp_size_image_size);
      y0 = (int) ((complex_orbit.get(i).getIm() - temp_ycenter_size) / temp_size_image_size);
      x1 = (int) ((complex_orbit.get(i + 1).getRe() - temp_xcenter_size) / temp_size_image_size);
      y1 = (int) ((complex_orbit.get(i + 1).getIm() - temp_ycenter_size) / temp_size_image_size);
      full_image_g.drawLine(x0, y0, x1, y1);
      full_image_g.fillOval(x0, y0, 3, 3);
    }

    full_image_g.fillOval(x1, y1, 3, 3);
  }
Example #3
0
 // <editor-fold defaultstate="collapsed" desc=" Paint ">
 @Override
 public void paint(Graphics g) {
   Graphics2D gg = (Graphics2D) g;
   gg.addRenderingHints(VNSwingUtils.getHints());
   if (active) {
     switch (errorLevel) {
       case ERRORLEVEL_OK:
         gg.setPaint(okSmooth);
         break;
       case ERRORLEVEL_WARNING:
         gg.setPaint(warningSmooth);
         break;
       case ERRORLEVEL_ERROR:
         gg.setPaint(errorSmooth);
         break;
     }
     gg.fillOval(0, 0, w, h);
   } else {
     switch (errorLevel) {
       case ERRORLEVEL_OK:
         gg.setPaint(okSmoothSmall);
         break;
       case ERRORLEVEL_WARNING:
         gg.setPaint(warningSmoothSmall);
         break;
       case ERRORLEVEL_ERROR:
         gg.setPaint(errorSmoothSmall);
         break;
     }
     gg.fillOval(0, 0, w, h);
   }
 }
Example #4
0
  @Override
  public void setBounds(int x, int y, int width, int height) {
    super.setBounds(x, y, width, height);
    int w = getWidth() - (SHADOW_SIZE - 2) * 2;
    int h = getHeight() - (SHADOW_SIZE - 2) * 2;
    int arc = 15;
    int shadowSize = SHADOW_SIZE;
    shadow = GraphicsUtilities.createCompatibleTranslucentImage(w, h);
    Graphics2D g2 = shadow.createGraphics();

    if (active) {
      g2.setColor(new Color(243, 238, 39, 150));
    } else {
      g2.setColor(Color.WHITE);
    }

    g2.setColor(Color.WHITE);
    g2.fillOval(0, 0, w, h);
    g2.dispose();
    ShadowRenderer renderer = new ShadowRenderer(shadowSize, 0.5f, Color.BLACK);
    shadow = renderer.createShadow(shadow);
    g2 = shadow.createGraphics();
    g2.setColor(Color.GRAY);
    g2.setComposite(AlphaComposite.Clear);
    g2.fillOval(shadowSize, shadowSize, w, h);
    g2.dispose();
  }
    @Override
    protected void paintComponent(Graphics g) {
      super.paintComponent(g);
      Graphics2D g2d = (Graphics2D) g.create();

      int[] x = new int[3];
      int[] y = new int[3];
      double distance = startPoint.distance(endPoint);
      double halfDistance = distance / 2;
      double angle = -Math.atan2(endPoint.y - startPoint.y, endPoint.x - startPoint.x);

      System.out.println(angle);

      x[0] = (int) endPoint.getX();
      y[0] = (int) endPoint.getY();

      x[1] = (int) ((Math.sin(angle) * halfDistance) + startPoint.getX());
      y[1] = (int) ((Math.cos(angle) * halfDistance) + startPoint.getY());

      x[2] = (int) (startPoint.getX() - (Math.sin(angle) * halfDistance));
      y[2] = (int) (startPoint.getY() - (Math.cos(angle) * halfDistance));

      g2d.setColor(Color.RED);
      g2d.fillPolygon(x, y, 3);

      g2d.setColor(Color.BLUE);
      g2d.fillOval(startPoint.x - 5, startPoint.y - 5, 10, 10);
      g2d.setColor(Color.GREEN);
      g2d.fillOval(endPoint.x - 5, endPoint.y - 5, 10, 10);

      g2d.dispose();
    }
Example #6
0
  private static Icon getThemeIcon(ColorScheme colorScheme, boolean square) {
    int iSize = SubstanceSizeUtils.getTitlePaneIconSize();
    BufferedImage result = SubstanceCoreUtilities.getBlankImage(iSize, iSize);
    Graphics2D graphics = (Graphics2D) result.getGraphics().create();
    graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    Color color1 = (colorScheme == null) ? Color.red : colorScheme.getUltraDarkColor();
    Color color2 = (colorScheme == null) ? Color.green : colorScheme.getMidColor();
    Color color3 = (colorScheme == null) ? Color.blue : colorScheme.getExtraLightColor();

    graphics.setColor(color1);
    if (square) graphics.fillRect(5, 2, 6, 6);
    else graphics.fillOval(5, 2, 6, 6);
    graphics.setColor(color1.darker());
    if (square) graphics.drawRect(5, 2, 6, 6);
    else graphics.drawOval(5, 2, 6, 6);

    graphics.setColor(color2);
    if (square) graphics.fillRect(1, 9, 6, 6);
    else graphics.fillOval(1, 9, 6, 6);
    graphics.setColor(color2.darker());
    if (square) graphics.drawRect(1, 9, 6, 6);
    else graphics.drawOval(1, 9, 6, 6);

    graphics.setColor(color3);
    if (square) graphics.fillRect(9, 9, 6, 6);
    else graphics.fillOval(9, 9, 6, 6);
    graphics.setColor(color3.darker());
    if (square) graphics.drawRect(9, 9, 6, 6);
    else graphics.drawOval(9, 9, 6, 6);

    graphics.dispose();
    return new ImageIcon(result);
  }
Example #7
0
  @Override
  public void paintComponent(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    // obtengo el alto y el ancho de la pantalla
    width = getWidth();
    height = getHeight();
    diameter = Math.min(width, height);
    centreX = width / 2;
    centreY = diameter / 2;
    diameterCircleMax = ((diameter * 8) / 10);
    g2.setColor(Color.WHITE);
    g2.fillRect(0, 0, (int) width, (int) height);
    // we traslate the origin to the centre
    g2.translate(centreX, centreY);
    g2.setColor(Color.getHSBColor((float) 0.001, (float) 0.001, (float) 0.4));
    g2.fillOval(
        (int) (-diameterCircleMax) / 2,
        (int) (-diameterCircleMax) / 2,
        (int) diameterCircleMax,
        (int) diameterCircleMax);
    g2.setColor(Color.BLACK);
    // we define a width for the lines
    g2.setStroke(new BasicStroke(5));
    // we draw a circle
    g2.drawOval(
        (int) (-diameterCircleMax) / 2,
        (int) (-diameterCircleMax) / 2,
        (int) diameterCircleMax,
        (int) diameterCircleMax);

    //        g2.setColor(Color.WHITE);
    //        g2.fillOval((int)(-diameter*9)/20, (int)(-diameter*9)/20, (int)(diameter*9)/10,
    // (int)(diameter*9)/10);
    //        g2.setColor(Color.BLACK);

    // we draw a little circle
    if (activate) {
      // return the centre of the circle
      g2.translate(-width / 2, -diameter / 2);
      g2.translate((int) positionX, (int) positionY);
      //        g2.setColor(Color.WHITE);
      //        g2.fillOval((int)(-diameter)/2, (int)(-diameter)/2, (int)(diameter),
      // (int)(diameter));
      //        g2.setColor(Color.BLACK);
    }
    g2.setStroke(new BasicStroke(1));
    g2.setColor(Color.getHSBColor((float) 0.001, (float) 0.001, (float) 0.3));
    g2.fillOval(
        (int) (-diameter) / 12, (int) (-diameter) / 12, (int) (diameter) / 6, (int) (diameter) / 6);
    g2.setColor(Color.getHSBColor((float) 0.001, (float) 0.001, (float) 0.1));
    g2.fillOval(
        (int) (-diameter) / 20,
        (int) (-diameter) / 20,
        (int) (diameter) / 10,
        (int) (diameter) / 10);
  }
Example #8
0
  private void renderMarkers(Graphics2D g2d) {
    BaikalCore core = BaikalCore.getInstance();
    Insets insets = getInsets();
    int margin = ((Number) core.getEntry(PrefConst.MARKER_MARGIN)).intValue();
    int radius = ((Number) core.getEntry(PrefConst.MARKER_RADIUS)).intValue();
    int diameter = 2 * radius;

    int left = insets.left + margin;
    int right = getWidth() - insets.right - margin - diameter;
    int top = insets.top + margin;
    int bottom = getHeight() - insets.bottom - margin - diameter;
    int center_x = (left + right) / 2;
    int center_y = (top + bottom) / 2;

    g2d.setColor(MARKER_COLOR);
    g2d.fillOval(left, center_y, diameter, diameter);
    g2d.fillOval(center_x, top, diameter, diameter);
    g2d.fillOval(center_x, center_y, diameter, diameter);
    g2d.fillOval(center_x, bottom, diameter, diameter);
    g2d.fillOval(right, center_y, diameter, diameter);
    g2d.fillOval(left, top, diameter, diameter);
    g2d.fillOval(right, top, diameter, diameter);
    g2d.fillOval(left, bottom, diameter, diameter);
    g2d.fillOval(right, bottom, diameter, diameter);
  }
Example #9
0
 public void draw(Graphics2D g) {
   g.setColor(Color.BLACK);
   g.fillRect(xPos, yPos, width, length);
   if (onPlate == true) {
     g.setColor(Color.white);
     g.fillOval(600, 20, 15, 15);
     g.setColor(Color.black);
     g.fillOval(602, 22, 10, 10);
   }
   if (isCooking == true) {
     g.setColor(Color.black);
     g.fillOval(700, 20, 10, 10);
   }
 }
Example #10
0
  public static void drawNodePath(
      Graphics2D g2d,
      Color curveStart,
      Color curveEnd,
      boolean drawOutputOval,
      boolean drawInputOval,
      int[] locationOutput,
      int[] locationInput,
      GraphCamera camera) {

    int[] cameraLocation = camera.getLocation();
    float cameraScale = camera.getScale();

    int[] bCurvePoints = getBCurvePointsFromNodes(locationOutput, locationInput, camera);

    BCurve.drawCurve(
        g2d,
        BCurve.solid,
        true,
        curveStart,
        curveEnd,
        bCurvePoints[0],
        bCurvePoints[1],
        bCurvePoints[2],
        bCurvePoints[3],
        bCurvePoints[4],
        bCurvePoints[5],
        bCurvePoints[6],
        bCurvePoints[7],
        camera.getScale());

    int pointRadius = (int) (7 * cameraScale);

    if (drawOutputOval) {
      g2d.setColor(curveStart);
      g2d.fillOval(
          bCurvePoints[0] - pointRadius,
          bCurvePoints[1] - pointRadius,
          pointRadius * 2,
          pointRadius * 2);
    }
    if (drawInputOval) {
      g2d.setColor(curveEnd);
      g2d.fillOval(
          bCurvePoints[6] - pointRadius,
          bCurvePoints[7] - pointRadius,
          pointRadius * 2,
          pointRadius * 2);
    }
  }
Example #11
0
 public void draw(boolean showEdges, boolean showAoi, Graphics2D graphics) {
   graphics.setStroke(stroke);
   graphics.setColor(color);
   for (int i = 0; i < 5; i++) {
     graphics.fillOval(
         scale(oldPositions[i].x) - i, scale(oldPositions[i].y) - i, i * tailScale, i * tailScale);
   }
   graphics.fillOval(
       scale(position.x - width / 2), scale(position.y - height / 2),
       scale(width), scale(height));
   if (selected) {
     graphics.setPaint(Color.red);
     for (AbstractNode<? extends Perceiving> neighbor : perceptron.getNeighbors()) {
       if (!neighbor.equals(perceptron)) {
         graphics.draw(
             new Ellipse2D.Double(
                 scale(neighbor.getLocation().x) - node_radius * 2,
                 scale(neighbor.getLocation().y) - node_radius * 2,
                 node_radius * 2 * 2,
                 node_radius * 2 * 2));
       }
     }
     graphics.setPaint(Color.blue);
     graphics.draw(
         new Ellipse2D.Double(
             scale(position.x) - node_radius * 2,
             scale(position.y) - node_radius * 2,
             node_radius * 2 * 2,
             node_radius * 2 * 2));
     graphics.setPaint(Color.red);
     if (showEdges) {
       List<Point2d[]> edges = perceptron.getVoronoiDomainEdges();
       for (Point2d[] edge : edges) {
         graphics.draw(
             new Line2D.Double(
                 scale(edge[0].x), scale(edge[0].y), scale(edge[1].x), scale(edge[1].y)));
       }
     }
     if (showAoi) {
       graphics.setStroke(aoiStroke);
       graphics.draw(
           new Ellipse2D.Double(
               scale(position.x - perceptron.getAoiRadius()),
               scale(position.y - perceptron.getAoiRadius()),
               scale(perceptron.getAoiRadius()) * 2,
               scale(perceptron.getAoiRadius()) * 2));
       graphics.setStroke(stroke);
     }
   }
 }
Example #12
0
    @Override
    public void paintPanel(WebcamPanel owner, Graphics2D g2) {

      g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      g2.setBackground(Color.BLACK);
      g2.fillRect(0, 0, getWidth(), getHeight());

      int cx = (getWidth() - 70) / 2;
      int cy = (getHeight() - 40) / 2;

      g2.setStroke(new BasicStroke(2));
      g2.setColor(Color.LIGHT_GRAY);
      g2.fillRoundRect(cx, cy, 70, 40, 10, 10);
      g2.setColor(Color.WHITE);
      g2.fillOval(cx + 5, cy + 5, 30, 30);
      g2.setColor(Color.LIGHT_GRAY);
      g2.fillOval(cx + 10, cy + 10, 20, 20);
      g2.setColor(Color.WHITE);
      g2.fillOval(cx + 12, cy + 12, 16, 16);
      g2.fillRoundRect(cx + 50, cy + 5, 15, 10, 5, 5);
      g2.fillRect(cx + 63, cy + 25, 7, 2);
      g2.fillRect(cx + 63, cy + 28, 7, 2);
      g2.fillRect(cx + 63, cy + 31, 7, 2);

      g2.setColor(Color.DARK_GRAY);
      g2.setStroke(new BasicStroke(3));
      g2.drawLine(0, 0, getWidth(), getHeight());
      g2.drawLine(0, getHeight(), getWidth(), 0);

      String str = starting ? "Initializing" : "No Image";
      FontMetrics metrics = g2.getFontMetrics(getFont());
      int w = metrics.stringWidth(str);
      int h = metrics.getHeight();

      g2.setColor(Color.WHITE);
      g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
      g2.drawString(str, (getWidth() - w) / 2, cy - h);

      if (name == null) {
        name = webcam.getName();
      }

      str = name;
      w = metrics.stringWidth(str);
      h = metrics.getHeight();

      g2.drawString(str, (getWidth() - w) / 2, cy - 2 * h);
    }
  @Override
  public void draw(Graphics2D g) {
    g.setColor(color.getProp());
    if (bSelected) g.setColor(Color.BLACK);

    Vec2 point = null;
    Vec2 point1 = null;
    for (int i = 0; i < getNumPointsWithPort() - 1; i++) {
      point = getPointWithPort(i);
      point1 = getPointWithPort(i + 1);

      Line2D line = new Line2D.Float(point.x, point.y, point1.x, point1.y);
      drawHighlight(g, line);
      if (bSelected) {
        // Color c=g.getColor();
        // drawShade(g, line, Color.ORANGE, 5);
        // g.setColor(c);
        Color c = g.getColor();
        g.setColor(Color.ORANGE);
        Stroke oldStroke = g.getStroke();
        BasicStroke stroke = createStroke(width.getProp() + 3);
        g.setStroke(stroke);
        g.drawLine((int) point.x, (int) point.y, (int) point1.x, (int) point1.y);
        g.setStroke(oldStroke);
        g.setColor(c);
      }
      ;

      Stroke oldStroke = g.getStroke();
      BasicStroke stroke = getLineStroke();
      g.setStroke(stroke);
      g.draw(line);
      g.setStroke(oldStroke);

      g.setColor(Color.BLACK);
      if (i == 0) {
        g.fillOval((int) point.x - 3, (int) point.y - 3, 6, 6);
      }
      if (i == getNumPointsWithPort() - 2) {
        g.fillOval((int) point1.x - 3, (int) point1.y - 3, 6, 6);
      }
      ;
    }
    ;

    super.draw(g);
    return;
  }
Example #14
0
  @Override
  protected void paintComponent(Graphics g) {
    super.paintComponent(g);

    Graphics2D g2d = (Graphics2D) g;
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setColor(Color.GREEN);

    if (player != null) {
      g2d.fillOval(player.getX(), player.getY(), 5, 5);
    }
    /*
    if(trees != null)
    {
     for(Circle tree: trees)
     {
     	g2d.fillOval((int) tree.x, (int) tree.y,(int) tree.RADIUS,(int) tree.RADIUS);
     }
    }
    if(bigHerbivores != null)
    {
    	for(BigHerbivore c: bigHerbivores)
    	{
    		int rad = Math.round(c.RADIUS/2);

    		g2d.setColor(Color.RED);
    		g2d.fillOval((int) c.x - rad,(int) c.y - rad,(int) c.RADIUS,(int) c.RADIUS);
    		g2d.drawLine((int) c.x,(int) c.y,(int) c.destX,(int) c.destY);
    	}
    }
    */
  }
Example #15
0
  private void drawGraph(Graphics2D g, List<Point> points) {
    if (points.isEmpty()) {
      return;
    }

    Point p, prevP = null;
    for (Point point : points) {
      p = point;
      if (prevP != null) {
        g.drawLine(prevP.x, prevP.y, p.x, p.y);
        g.fillOval(prevP.x - PointRadius, prevP.y - PointRadius, PointRadius2, PointRadius2);
      }
      prevP = p;
    }
    g.fillOval(prevP.x - PointRadius, prevP.y - PointRadius, PointRadius2, PointRadius2);
  }
  public void paintComponent(Graphics A00) {

    super.paintComponent(A00);

    Graphics2D L00 = (Graphics2D) A00;
    L00.setRenderingHint(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON);

    L00.setColor(I00);
    L00.fillOval(C02 + C03, C02 + C03, C04, C04);

    int L01 = 90; // 円グラフの描画開始角度
    int L02 = 0; // 扇形の中心角

    setRates();

    for (Color L03 : I01.keySet()) {
      L02 = Math.round(360f * I01.get(L03) / I02);
      L01 -= L02;
      L00.setColor(L03);
      L00.fillArc(C02, C02, C04, C04, L01, L02);
    }
    // 四捨五入の都合で塗り残しが出た場合の対処
    L00.fillArc(C02, C02, C04, C04, -270, L02);

    L00.setColor(I00);
    L00.drawOval(C02, C02, C04, C04);
  }
Example #17
0
    protected void drawObject(
        long time,
        SpaceObject o,
        double x,
        double y,
        double a,
        Graphics2D g2d,
        SpaceObjectPosition pos) {
      double sRad = zoom * o.solidRadius;
      g2d.setColor(o.solidColor);
      g2d.fillOval((int) (x - sRad), (int) (y - sRad), (int) (sRad * 2), (int) (sRad * 2));

      double sin = Math.sin(a);
      double cos = Math.cos(a);

      for (SpaceObject subObj : o.subObjects) {
        subObj.position.getPosition(time, pos);

        double subX = x + zoom * pos.x * cos - zoom * pos.y * sin;
        double subY = y + zoom * pos.x * sin + zoom * pos.y * cos;
        double subAng = a + pos.angle;

        drawObject(time, subObj, subX, subY, subAng, g2d, pos);
      }
    }
  @Override
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2d = (Graphics2D) g;
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    // Minus Button
    g2d.setColor(borderColor);
    g2d.fillOval(x, y, widthHeight, widthHeight);
    g2d.setColor(minusBackground);
    g2d.fillOval(xs, ys, widthHeightSmall, widthHeightSmall);

    // Beschriftung
    g2d.setColor(minusForeground);
    g2d.drawLine(linePosition - 3, linePosition, linePosition + 3, linePosition);
  }
 private void placerPostes(Graphics2D g) {
   g.setStroke(new BasicStroke());
   for (PlanSalle.Poste poste : modele.listerPostes()) {
     g.setColor(Color.gray);
     int xPoste = Parametres.posteX(poste.getPosition().getTravee(), poste.getOrientation());
     int yPoste = Parametres.posteY(poste.getPosition().getRangee(), poste.getOrientation());
     int xPersonne =
         Parametres.personneX(poste.getPosition().getTravee(), poste.getOrientation());
     int yPersonne =
         Parametres.personneY(poste.getPosition().getRangee(), poste.getOrientation());
     if (poste.getOrientation() == Orientation.NORD
         || poste.getOrientation() == Orientation.SUD) {
       g.fill3DRect(xPoste, yPoste, Parametres.LONGUEUR_POSTE, Parametres.LARGEUR_POSTE, true);
     } else {
       g.fill3DRect(xPoste, yPoste, Parametres.LARGEUR_POSTE, Parametres.LONGUEUR_POSTE, true);
     }
     g.drawOval(xPersonne, yPersonne, Parametres.LARGEUR_PERSONNE, Parametres.LARGEUR_PERSONNE);
     if (poste.peutVoir()) {
       g.setColor(Color.red);
     } else {
       g.setColor(Color.blue);
     }
     g.fillOval(xPersonne, yPersonne, 20, 20);
   }
 }
 private void drawPoint(PointDP point, Graphics2D g) {
   g.fillOval(
       frameWidth / 2 + (int) (point.x * unityX) - 3,
       frameHeight / 2 - (int) (point.y * unityY) - 3,
       6,
       6);
 }
Example #21
0
 public void run() {
   BufferedImage img = panel.getImage();
   Graphics2D g2 = img.createGraphics();
   int anzahl = 255;
   int st = 6;
   int r = st / 2;
   int x1, y1;
   int c;
   Random random = new Random();
   MyColor myColor = MyColor.getInstance();
   for (int y = 0; y < img.getHeight(); y += st) {
     for (Integer x = 0; x < img.getWidth(); x += st) {
       int color = img.getRGB(x, y);
       if (color != RED && color != WHITE) {
         c = 0;
         for (int i = 0; i < anzahl; i++) {
           x1 = x;
           y1 = y;
           color = BLACK;
           while (color != RED && color != WHITE) {
             x1 += random.nextBoolean() ? 5 : -5;
             y1 += random.nextBoolean() ? 5 : -5;
             color = img.getRGB(x1, y1);
           }
           if (color == RED) {
             c += 1;
           }
         }
         System.out.println("Point(" + x + "," + y + ")  c=" + c);
         g2.setColor(myColor.getColorAt(c));
         g2.fillOval(x - r, y - r, st, st);
       }
     }
   }
 }
Example #22
0
 public void draw(Graphics g) {
   Graphics2D g2d = (Graphics2D) g;
   g2d.setPaint(this.getPaint());
   int width = Math.abs(this.getX1() - this.getX2());
   int height = Math.abs(this.getY1() - this.getY2());
   int smallX = this.getX1() < this.getX2() ? this.getX1() : this.getX2();
   int smallY = this.getY1() < this.getY2() ? this.getY1() : this.getY2();
   Stroke myStroke;
   if (this.isDashed()) {
     myStroke =
         new BasicStroke(
             this.getWidth(),
             BasicStroke.CAP_ROUND,
             BasicStroke.JOIN_BEVEL,
             10,
             this.getDashWidth(),
             0);
   } else {
     myStroke = new BasicStroke(this.getWidth(), BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL);
   }
   g2d.setStroke(myStroke);
   if (this.isFilled()) {
     g2d.fillOval(smallX, smallY, width, height);
   } else {
     g2d.drawOval(smallX, smallY, width, height);
   }
 }
Example #23
0
  @Override
  public void draw(Graphics2D g2d, Surface s) {

    g2d.setPaint(getColor());
    g2d.fill(getSurface());

    if (getHover() && !selected) {
      Stroke outl = new BasicStroke(2f);
      g2d.setStroke(outl);
      if (getColor() != Color.red) g2d.setPaint(Color.red);
      else g2d.setPaint(Color.BLACK);
      g2d.drawPolygon(getSurface());
    } else if (selected) {
      float[] dash = {4f, 0f, 2f};
      BasicStroke outl =
          new BasicStroke(
              2f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 1.0f, dash, getFramesAlive() * .2f);
      g2d.setStroke(outl);

      if (ownedby.equals(Player.NONE)) {
        g2d.setPaint(Color.black);
      } else if (ownedby.equals(Player.COMPUTER)) {
        g2d.setPaint(Color.RED);
      } else if (ownedby.equals(Player.PLAYER)) {
        g2d.setPaint(Color.BLUE);
      }

      g2d.drawPolygon(getSurface());
    }

    g2d.setPaint(Color.BLUE.brighter());
    for (Territory t : neighbors) {
      double distance;
      if (CalculateDistance(this.capital.x, this.capital.y, t.GetCapital().x, t.GetCapital().y)
          < 800) g2d.drawLine(this.capital.x, this.capital.y, t.GetCapital().x, t.GetCapital().y);
      else {
        if (CalculateDistance(this.capital.x, this.capital.y, 0, 0) < 500) {
          g2d.drawLine(this.capital.x, this.capital.y, 0, 70);
        } else if (CalculateDistance(this.capital.x, this.capital.y, 0, 0) > 500) {
          g2d.drawLine(this.capital.x, this.capital.y, 1280, 70);
        }
      }
    }

    if (ownedby.equals(Player.NONE)) {
      g2d.setPaint(Color.black);
    } else if (ownedby.equals(Player.COMPUTER)) {
      g2d.setPaint(Color.RED);
    } else if (ownedby.equals(Player.PLAYER)) {
      g2d.setPaint(Color.BLUE);
    }

    g2d.setFont(new Font("TimesRoman", Font.PLAIN, 18));
    g2d.setStroke(new BasicStroke(1f));
    g2d.fillOval(capital.x - 10, capital.y - 10, 20, 20);
    g2d.setPaint(Color.BLACK);
    g2d.drawOval(capital.x - 10, capital.y - 10, 20, 20);
    g2d.setPaint(Color.WHITE);
    g2d.drawString("" + armies, capital.x - 5, capital.y + 5);
  }
  @Override
  protected void paintIcon(JComponent c, Graphics2D g, Rectangle viewRect, Rectangle iconRect) {
    int rad = JBUI.scale(4);

    // Paint the radio button
    final int x = iconRect.x + (rad - (rad % 2 == 1 ? 1 : 0)) / 2;
    final int y = iconRect.y + (rad - (rad % 2 == 1 ? 1 : 0)) / 2;
    final int w = iconRect.width - rad;
    final int h = iconRect.height - rad;
    final boolean enabled = c.isEnabled();
    Color color = enabled ? Gray.x50 : Gray.xD3;
    g.translate(x, y);
    // setup AA for lines
    final GraphicsConfig config = GraphicsUtil.setupAAPainting(g);
    g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
    final boolean selected = ((AbstractButton) c).isSelected();
    g.setPaint(color);
    g.drawOval(0, 0, w, h);

    if (selected) {
      g.setColor(color);
      g.fillOval(JBUI.scale(3), JBUI.scale(3), w - 2 * JBUI.scale(3), h - 2 * JBUI.scale(3));
    }
    config.restore();
    g.translate(-x, -y);
  }
Example #25
0
  /*
   * Draws this place.
   */
  void paint(Graphics g) {
    super.paint(g); // very important, do not forget

    Graphics2D g2 = (Graphics2D) g;
    int w = this.getSize().width;
    int h = this.getSize().height;
    int x = this.getPosition().x - (w >> 1);
    int y = this.getPosition().y - (h >> 1);

    // draw forground
    if (this.getAction()) g2.setPaint(this.actionColor);
    else if (this.getSelected()) g2.setPaint(this.selectColor);
    else if (this.getEmphasized()) g2.setPaint(emphasize_color);
    // else g2.setPaint(new GradientPaint(x,y,this.foreground_color,x+w,y+h,Color.white));
    else g2.setPaint(Props.PLACE_FILL_COLOR);

    if (isMouseOver()) {
      Color c = (Color) g2.getPaint();
      g2.setPaint(new Color(c.getRed() ^ 0x66, c.getGreen() ^ 0x00, c.getBlue() ^ 0x00));
    }

    g2.fillOval(x, y, w, h);

    // draw background

    g2.setPaint(Props.PLACE_BORDER_COLOR);
    if (this.getJoined()) {
      Stroke oldStroke = g2.getStroke();
      g2.setStroke(new BasicStroke(2.5f));
      g2.drawOval(x, y, w, h);
      g2.setStroke(oldStroke);
    } else g2.drawOval(x, y, w, h);
  }
Example #26
0
  /**
   * Erases the ball.
   *
   * @param ballGraphic The graphics object to use.
   */
  public void erase(Graphics2D ballGraphic) {
    double upperLeftX = _position.x - (_pixelWidth / 2);
    double upperLeftY = _position.y - (_pixelHeight / 2);

    ballGraphic.setPaint(Color.WHITE);
    ballGraphic.fillOval((int) upperLeftX, (int) upperLeftY, _pixelWidth, _pixelHeight);
  }
Example #27
0
  @Override
  protected void paintWidget() {
    Graphics2D g = getGraphics();
    g.setStroke(Util.STROKE_2);
    g.setFont(getFont());
    Rectangle bounds = getBounds();

    String text = Util.node(this).toString();
    if (text.length() == 0) {
      g.setColor((Color) getBackground());
      g.fillOval(bounds.x, bounds.y, bounds.width - 1, bounds.height - 1);
      g.setColor(getForeground());
      g.drawOval(bounds.x, bounds.y, bounds.width - 1, bounds.height - 1);
    } else {
      g.setColor((Color) getBackground());
      int arc = (bounds.height - 1);
      g.fillRoundRect(bounds.x, bounds.y, bounds.width - 1, bounds.height - 1, arc, arc);
      g.setColor(getForeground());
      g.drawString(
          text,
          bounds.x + (bounds.height - 1) / 2,
          bounds.y + bounds.height - vborder - 1 - g.getFontMetrics().getMaxDescent());
      g.drawRoundRect(bounds.x, bounds.y, bounds.width - 1, bounds.height - 1, arc, arc);
    }
  }
Example #28
0
  @Override
  protected void paintComponent(Graphics g) {
    super.paintComponent(g);

    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    int ptrPos = (int) (SIDE_PAD + (getWidth() - 2 * SIDE_PAD) * callback.getVolume() / MAX_VOLUME);

    final int x = 0;
    final int y = (PTR_HEIGHT - BAR_HEIGHT) / 2;
    int right = getWidth();

    g2.setClip(new RoundRectangle2D.Float(x, y, right - x, BAR_HEIGHT, ROUND, ROUND));
    g2.setPaint(new GradientPaint(0, y, Color.DARK_GRAY, 0, y + BAR_HEIGHT, Color.GRAY));
    g2.fillRect(x, y, ptrPos - x, BAR_HEIGHT);

    g2.setPaint(new GradientPaint(0, y, Color.LIGHT_GRAY, 0, y + BAR_HEIGHT, Color.WHITE));
    g2.fillRect(ptrPos, y, right - ptrPos, BAR_HEIGHT);
    g2.setClip(null);

    g2.setColor(Color.BLACK);
    g2.drawRoundRect(x, y, right - x - 1, BAR_HEIGHT, ROUND, ROUND);

    // Pointer
    int left = ptrPos - PTR_WIDTH / 2;

    final Color PTR_COLOR_1 = Color.WHITE;
    final Color PTR_COLOR_2 = Color.LIGHT_GRAY;

    g2.setPaint(new GradientPaint(left, 0, PTR_COLOR_1, left + PTR_WIDTH, 0, PTR_COLOR_2));
    g2.fillOval(left, 0, PTR_WIDTH, PTR_HEIGHT);
    g2.setColor(Color.BLACK);
    g2.drawOval(left, 0, PTR_WIDTH - 1, PTR_HEIGHT - 1);
  }
Example #29
0
  public void paintComponent(Graphics g) {

    GradientPaint gradient = new GradientPaint(70, 70, Color.blue, 150, 150, Color.orange);
    Image image = new ImageIcon("a.jpg").getImage();
    Random generator = new Random();

    int x1 = generator.nextInt(200) + 1;
    int y1 = generator.nextInt(200) + 1;
    int x2 = x1 + generator.nextInt(100) + 1;
    int y2 = x1 + generator.nextInt(100) + 1;

    g.setColor(Color.blue);
    g.fillRect(70, 70, 200, 100);

    g.setColor(Color.black);
    g.fillOval(80, 80, 170, 70);

    Graphics2D g2d = (Graphics2D) g;

    g.setColor(Color.yellow);
    g2d.fill3DRect(10, 10, 100, 100, true);

    g.drawImage(image, 300, 300, this);

    g2d.setPaint(gradient);
    g2d.fillOval(x1, y1, x2, y2);
  }
Example #30
0
  /** Draw ICY style background on the specified Graphics object with specified dimension. */
  public static void paintIcyBackGround(int width, int height, Graphics g) {
    final Graphics2D g2 = (Graphics2D) g.create();

    final float ray = Math.max(width, height) * 0.05f;
    final RoundRectangle2D roundRect =
        new RoundRectangle2D.Double(
            0, 0, width, height, Math.min(ray * 2, 20), Math.min(ray * 2, 20));

    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g2.setPaint(new GradientPaint(0, 0, Color.white.darker(), 0, height / 1.5f, Color.black));
    g2.fill(roundRect);

    g2.setPaint(Color.black);
    g2.setColor(Color.black);
    mixAlpha(g2, AlphaComposite.SRC_OVER, 1f / 3f);
    // g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f));
    g2.fillOval(-width + (width / 2), height / 2, width * 2, height);

    mixAlpha(g2, AlphaComposite.SRC_OVER, 3f / 1f);
    // g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f));
    g2.setStroke(new BasicStroke(Math.max(1f, Math.min(5f, ray))));
    g2.draw(roundRect);

    g2.dispose();
  }