示例#1
1
 public static boolean pngCaptcha(String randomStr, int width, int height, String file) {
   char[] strs = randomStr.toCharArray();
   try (OutputStream out = new FileOutputStream(file)) {
     BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
     Graphics2D g = (Graphics2D) bi.getGraphics();
     AlphaComposite ac3;
     Color color;
     int len = strs.length;
     g.setColor(Color.WHITE);
     g.fillRect(0, 0, width, height);
     for (int i = 0; i < 15; i++) {
       color = color(150, 250);
       g.setColor(color);
       g.drawOval(num(width), num(height), 5 + num(10), 5 + num(10));
     }
     g.setFont(font);
     int h = height - ((height - font.getSize()) >> 1),
         w = width / len,
         size = w - font.getSize() + 1;
     for (int i = 0; i < len; i++) {
       // 指定透明度
       ac3 = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f);
       g.setComposite(ac3);
       // 对每个字符都用随机颜色
       color = new Color(20 + num(110), 30 + num(110), 30 + num(110));
       g.setColor(color);
       g.drawString(strs[i] + "", (width - (len - i) * w) + size, h - 4);
     }
     ImageIO.write(bi, "png", out);
     out.flush();
     return true;
   } catch (IOException e) {
     return false;
   }
 }
示例#2
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);
  }
示例#3
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);
  }
示例#4
0
	public void paint(Graphics g){ //Graphics is a crayon box; Graphics2d is like an art kit
		BufferedImage image = new BufferedImage(width,height,BufferedImage.TYPE_INT_ARGB);
		Graphics2D g2 = (Graphics2D)image.getGraphics();
		//Graphics2D g2 = (Graphics2D)g;
		g2.setColor(Color.white);
		g2.fillRect(0,0,width,height);
		g2.setColor(Color.pink);
		g2.drawOval(50, 50, width-100, height-100);
		g2.drawOval(175, 175, width-490, height-490);
		g2.drawOval(375, 175, width-490, height-490);
		g2.drawLine(0,10,height,0);
		g2.drawArc(175, 250, 250, 130, 200, 90);
		Hero hero2 = new Hero("Dorami", "/images/heroes/Dorami.jpg",100,100);

		if(Math.abs(hero1.getX()-hero2.getX()) + Math.abs(hero1.getY()-hero2.getY()) <20  ){
			itemPickedUp=true;
		}
		if(!itemPickedUp){g2.drawImage(hero2.getImage(), hero2.getX(), hero2.getY(), null);}
		g2.drawImage(hero1.getImage(), hero1.getX(), hero1.getY(), null);
		//g2.fillOval(50,100,200,100);
		//g2.drawArc(50, 300, 200, 100,0,90);
	/*	int c =0;
		int margin =2;
		int squareD =20;
		for(int x=0; x<width; x+= squareD +margin){
			for(int y=0; y<height; y+= squareD+margin){
				if(c<255) c++;
				else c=0;
				Color local = new Color((int) Math.floor(Math.random() * 256),(int) Math.floor(Math.random() * 256),c);
				g2.setColor(local);
				g2.fillRect(x,y,squareD,squareD);
			}
		}*/
		g.drawImage(image, 0, 0, null);
	}
示例#5
0
  @Override
  public void DesenhaSe(Graphics2D dbg, int xmundo, int ymundo) {

    if (estaSelecionado) {
      raio *= 2;
      dbg.setColor(Color.RED);
      dbg.drawOval(((int) X - xmundo) - raio, ((int) Y - ymundo) - raio, raio * 2, raio * 2);
      dbg.setColor(Color.YELLOW);
      dbg.drawOval(
          ((int) X - xmundo) - raio - 1, ((int) Y - ymundo) - raio - 1, raio * 2, raio * 2);
      dbg.setColor(Color.GREEN);
      dbg.drawOval(
          ((int) X - xmundo) - raio + 1, ((int) Y - ymundo) - raio + 1, raio * 2, raio * 2);
      raio /= 2;
      //			if(codPersonagem == 0){
      //				this.botaoCriaCasa.DesenhaSe(dbg, xmundo, ymundo);
      //			}
      dbg.setColor(Color.GREEN);
      dbg.fillRect((int) (X - xmundo) - 20, (int) (Y - ymundo) - 30, (int) (vida / 32), (int) 10);
      dbg.setColor(Color.RED);
      dbg.drawRect((int) (X - xmundo) - 20, (int) (Y - ymundo) - 30, (int) (vida / 32), (int) 10);
    }

    dbg.drawImage(
        img,
        ((int) X - xmundo) - L2,
        ((int) Y - ymundo) - A2,
        (int) (X - xmundo + L2),
        (int) (Y - ymundo + A2),
        (largura * frame),
        (anim * altura),
        (largura * frame) + largura,
        (anim * altura) + altura,
        null);
  }
示例#6
0
  public void onPaint(Graphics2D g) {
    super.onPaint(g);

    // draw the wave models
    WaveModel wave;
    for (int i = 0; i < surf_bum.size(); i++) {
      wave = surf_bum.get(i);
      System.out.println("Displaying Wave " + (i + 1) + " of " + surf_bum.size());
      g.setColor(Color.BLUE);
      g.drawOval(
          (int) (wave.early_origin_x - wave.early_radius - (robot.getHeight() / 2)),
          (int) (wave.early_origin_y - wave.early_radius - (robot.getHeight() / 2)),
          (int) (wave.early_radius * 2 + robot.getHeight()),
          (int) (wave.early_radius * 2 + robot.getHeight()));
      g.drawOval(
          (int) (wave.late_origin_x - wave.late_radius + (robot.getHeight() / 2)),
          (int) (wave.late_origin_y - wave.late_radius + (robot.getHeight() / 2)),
          (int) (wave.late_radius * 2 - robot.getHeight()),
          (int) (wave.late_radius * 2 - robot.getHeight()));
    }

    // draw the movement calculations
    g.setColor(Color.RED);
    for (int i = 0; i < (int) fraction; i++) {

      g.setColor(Color.GREEN);
      g.fillRect((int) (disp_x[i]), (int) (disp_y[i]), 5, 5);
      g.fillRect((int) (disp_ix[i]), (int) (disp_iy[i]), 5, 5);

      if (disp_wave_func[i] < .5) {
        g.setColor(Color.RED);
        g.fillRect((int) (disp_x[i]), (int) (disp_y[i]), 5, 5);
      }
      if (disp_iwave_func[i] < .5) {
        g.setColor(Color.RED);
        g.fillRect((int) (disp_ix[i]), (int) (disp_iy[i]), 5, 5);
      }
      if (disp_wave_func[i] < .9) {
        g.setColor(Color.ORANGE);
        g.fillRect((int) (disp_x[i]), (int) (disp_y[i]), 5, 5);
      }
      if (disp_iwave_func[i] < .9) {
        g.setColor(Color.ORANGE);
        g.fillRect((int) (disp_ix[i]), (int) (disp_iy[i]), 5, 5);
      }
      if (disp_wave_count[i] >= 1) {
        g.setColor(Color.BLUE);
        g.fillRect((int) (disp_x[i]), (int) (disp_y[i]), 5, 5);
      }
      if (disp_iwave_count[i] >= 1) {
        g.setColor(Color.BLACK);
        g.fillRect((int) disp_ix[i], (int) disp_iy[i], 5, 5);
      }

      g.setColor(Color.PINK);
      g.fillRect((int) last_far_x, (int) last_far_y, 5, 5);
      g.fillRect((int) last_near_x, (int) last_near_y, 5, 5);
    }
  }
    private final void render(Graphics2D g) {
      if (!expanded) {
        g.setColor(colour);
        g.drawOval(x - 8, y - 8, 16, 16);
        g.drawOval(x - 6, y - 6, 12, 12);
        g.fillOval(x - 4, y - 4, 8, 8);

        if (isSelected()) {
          g.setColor(Color.WHITE);
          g.drawOval(x - 10, y - 10, 20, 20);
        }
      }
    }
示例#8
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);
  }
 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);
   }
 }
示例#11
0
  @Override
  public void draw(
      Graphics2D g2d,
      ComponentState componentState,
      boolean outlineMode,
      Project project,
      IDrawingObserver drawingObserver) {
    g2d.setStroke(
        ObjectCache.getInstance().fetchBasicStroke((int) borderThickness.convertToPixels()));

    if (componentState != ComponentState.DRAGGING) {
      Composite oldComposite = g2d.getComposite();
      if (alpha < MAX_ALPHA) {
        g2d.setComposite(
            AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
      }
      g2d.setColor(color);
      g2d.fillOval(
          firstPoint.x, firstPoint.y, secondPoint.x - firstPoint.x, secondPoint.y - firstPoint.y);
      g2d.setComposite(oldComposite);
    }
    // Do not track any changes that follow because the whole oval has been
    // tracked so far.
    drawingObserver.stopTracking();
    g2d.setColor(
        componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING
            ? SELECTION_COLOR
            : borderColor);
    g2d.drawOval(
        firstPoint.x, firstPoint.y, secondPoint.x - firstPoint.x, secondPoint.y - firstPoint.y);
  }
示例#12
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);
    }
  }
  protected void drawRobotBasic(Graphics graphics, Robot robot) {
    if (image.getWidth() != getWidth() || image.getHeight() != getHeight()) createImage();
    int circleDiameter =
        bigRobots
            ? (int) Math.max(10, Math.round(robot.getDiameter() * scale))
            : (int) Math.round(robot.getDiameter() * scale);
    int x = transformX(robot.getPosition().getX()) - circleDiameter / 2;
    int y = transformY(robot.getPosition().getY()) - circleDiameter / 2;

    Graphics2D g2d = (Graphics2D) graphics;
    g2d.setStroke(new BasicStroke(2));

    graphics.setColor(Color.RED);
    g2d.drawOval(x, y, circleDiameter, circleDiameter);

    double orientation = robot.getOrientation();

    double x2 = robot.getPosition().getX() + robot.getDiameter() / 2.0 * Math.cos(orientation);
    double y2 = robot.getPosition().getY() + robot.getDiameter() / 2.0 * Math.sin(orientation);

    graphics.drawLine(
        transformX(robot.getPosition().getX()),
        transformY(robot.getPosition().getY()),
        transformX(x2),
        transformY(y2));

    g2d.setStroke(new BasicStroke(1));

    graphics.setColor(Color.BLACK);
  }
示例#14
0
 @Override
 public void paintComponent(Graphics g) {
   super.paintComponent(g);
   Graphics2D copy = (Graphics2D) g.create();
   if (dragging) {
     copy.drawImage(imageBuffer, 0, 0, null);
     if (objectDragging == SelectedForm.LINE) {
       Line l = (Line) objectDragged;
       copy.setColor(l.getColor());
       copy.drawLine(l.getP1().x, l.getP1().y, l.getP2().x, l.getP2().y);
     } else if (objectDragging == SelectedForm.SQUARE) {
       Square sq = (Square) objectDragged;
       copy.setColor(sq.getColor());
       copy.drawRect(
           sq.adjustRendering().x, sq.adjustRendering().y, sq.getWidth(), sq.getHeight());
     } else if (objectDragging == SelectedForm.CIRCLE) {
       Circle c = (Circle) objectDragged;
       copy.setColor(c.getColor());
       copy.drawOval(c.adjustRendering().x, c.adjustRendering().y, c.getWidth(), c.getHeight());
     } else if (objectDragging == SelectedForm.POLYLINE) {
       Polyline poly = (Polyline) objectDragged;
       copy.setColor(poly.getColor());
       poly.fill();
       int[] XIS = poly.getX();
       int[] YSP = poly.getY();
       copy.drawPolyline(XIS, YSP, poly.getN());
       copy.drawLine(
           XIS[poly.getN() - 1], YSP[poly.getN() - 1], poly.getActualX(), poly.getActualY());
     }
   } else {
     copy.drawImage(imageBuffer, 0, 0, null);
   }
   copy.dispose();
 }
示例#15
0
  @Override
  protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    int width = this.getBounds().width;
    int height = this.getBounds().height;

    Graphics2D g2 = (Graphics2D) g;

    g2.setStroke(new BasicStroke(3.0f));
    g2.drawOval(width / 3, height / 5, width / 3, height / 2);

    int x1 = width / 2;
    int y1 = height * 3 / 10;
    int x2 = x1 + (int) (height / 5 * Math.sin(anguloVela));
    int y2 = y1 + (int) (height / 5 * Math.cos(anguloVela));
    if (focusVela) {
      g2.setColor(Color.RED);
      g2.drawLine(x1, y1, x2, y2);
      g2.setColor(Color.BLACK);
    } else {
      g2.drawLine(x1, y1, x2, y2);
    }

    y1 = height * 7 / 10;
    x2 = x1 + (int) (height / 10 * Math.sin(anguloTimon));
    y2 = y1 + (int) (height / 10 * Math.cos(anguloTimon));
    if (focusTimon) {
      g2.setColor(Color.RED);
      g2.drawLine(x1, y1, x2, y2);
      g2.setColor(Color.BLACK);
    } else {
      g2.drawLine(x1, y1, x2, y2);
    }
  }
示例#16
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);
  }
示例#17
0
  public void setImage() {

    BufferedImage image = ImageUtils.createCompatibleImage(300, 300);
    Graphics2D g2 = image.createGraphics();

    g2.setColor(Color.green);

    float thickness = 5;

    g2.setStroke(new BasicStroke(thickness));

    int centerX = image.getWidth() / 2;
    int centerY = image.getHeight() / 2;

    int x = (int) (centerX + thickness / 2 - 30);
    int y = (int) (centerY + thickness / 2 - 30);

    int width = (int) (2 * 30 - thickness / 2 - 1);
    int height = (int) (2 * 30 - thickness / 2 - 1);

    g2.drawOval(x, y, width, height);
    g2.dispose();

    imageType.setValue(image);
  }
示例#18
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);
   }
 }
  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);
  }
示例#20
0
文件: Well.java 项目: RoboSquirt/java
  /**
   * Called by the dispatcher, tells its well to paint itself at the proper location.
   *
   * @param g - graphics to paint on
   * @param sF - scale factor from cm to pixels
   */
  public void paint(Graphics g, double sF, boolean isRotated) {

    // get the graphics objects
    Graphics2D g2d = (Graphics2D) g;
    AffineTransform at = new AffineTransform();

    // draw well's outline
    at.translate(parentPlate.getTLcorner().getX() * sF, parentPlate.getTLcorner().getY() * sF);
    if (isRotated) {
      at.translate(parentPlate.getPlateSpecs().getBorderDimensions().getY() * sF, 0);
      at.rotate(Math.PI / 2);
    }
    at.translate(
        (relativeLocation.getX() - diameter / 2) * sF,
        (relativeLocation.getY() - diameter / 2) * sF);
    at.scale(sF, sF);

    g2d.setTransform(at);
    g2d.setColor(Color.BLACK);
    g2d.drawOval(0, 0, (int) diameter, (int) diameter);

    // highlight well if it is selected
    if (isSelected) {
      g2d.setColor(Color.LIGHT_GRAY);
      g2d.fillOval(0, 0, (int) diameter, (int) diameter);
    }
  }
示例#21
0
  private void drawAlgorithm(Graphics2D g, LpAlgorithm alg) {
    if (alg == null) {
      return;
    }
    int unsafeDrawRadius = (int) alg.unsafeRadius / 2;

    drawImageGraph(alg.drawing, g, Color.LIGHT_GRAY, 12);

    if (drawTubes) {
      for (ImageGraph tube : alg.reachTubes.values())
        drawImageGraph(tube, g, Color.red, 12, unsafeDrawRadius);

      // Draw each robot position with a red unsafe boundary around it

      g.setColor(Color.RED);
      for (Entry<String, ImagePoint> robot : alg.unsafeRobots.entrySet()) {
        g.drawOval(
            (int) (robot.getValue().getX() - unsafeDrawRadius),
            (int) (robot.getValue().getY() - unsafeDrawRadius),
            2 * unsafeDrawRadius,
            2 * unsafeDrawRadius);
      }
    }

    drawImageGraph(alg.painted, g, Color.GREEN, 12);
  }
示例#22
0
  @Override
  public void paintImage(WebcamPanel panel, BufferedImage image, Graphics2D g2) {
    double s = detector.getMotionArea();
    Point cog = detector.getMotionCog();

    Graphics2D g = image.createGraphics();
    g.setColor(Color.WHITE);
    g.drawString(String.format("Area: %.2f%%", s), 10, 20);

    if (detector.isMotion()) {
      if (saveImages) {
        BufferedImage img = webcam.getImage();
        try {
          String fileName = "motion-detected_";
          fileName += System.currentTimeMillis() + ".png";
          ImageIO.write(img, "PNG", new File(fileName));
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
      g.setStroke(new BasicStroke(2));
      g.setColor(Color.RED);
      g.drawOval(cog.x - 5, cog.y - 5, 10, 10);
    } else {
      g.setColor(Color.GREEN);
      g.drawRect(cog.x - 5, cog.y - 5, 10, 10);
    }

    g.dispose();

    panel.getDefaultPainter().paintImage(panel, image, g2);
  }
示例#23
0
  @Override
  public void drawActive(
      Graphics2D g,
      Position canvasCenter,
      Position mousePosition,
      List<Inputs> inputs,
      Position canvasSize,
      double scale) {
    drawCircle(g, canvasCenter, Color.red);
    if ((isOnEdge(mousePosition, canvasCenter) || adjustingRadius) && moveCircleStart == null) {
      if (!adjustingRadius) adjustingRadius = true;
      g.setStroke(new BasicStroke(5));
      Position upperLeft = canvasCenter.add(center).subtract(new Position(radius, radius));
      Position lowerRight = new Position(radius, radius).scale(2);
      g.drawOval(
          (int) upperLeft.getX(),
          (int) upperLeft.getY(),
          (int) lowerRight.getX(),
          (int) lowerRight.getY());
      if (inputs.contains(Inputs.leftMouse))
        radius = Math.sqrt(mousePosition.distanceSquared(canvasCenter.add(center)));
    } else if ((mousePosition.distanceSquared(canvasCenter.add(center)) < radius * radius
            && inputs.contains(Inputs.leftMouse))
        || moveCircleStart != null) {
      if (moveCircleStart == null) moveCircleStart = mousePosition;
      else {
        center = center.subtract(moveCircleStart.subtract(mousePosition));
        moveCircleStart = mousePosition;
      }
    }

    if (!inputs.contains(Inputs.leftMouse)) moveCircleStart = null;
    if (!isOnEdge(mousePosition, canvasCenter) && adjustingRadius) adjustingRadius = false;
  }
示例#24
0
  public void StaticObjNew(StaticObj so) {
    Graphics2D g = radarArea.backImage.createGraphics();
    g.setColor(so_color);

    if (so instanceof Beacon) {
      g.drawOval(
          convPos(so.pos.x) - grid_size / 6,
          convPos(so.pos.y) - grid_size / 6,
          grid_size / 3,
          grid_size / 3);
      JLabel sol = new JLabel(Integer.toString(so.id));
      sol.setForeground(so_text_color);
      sol.setBounds(
          convPos(so.pos.x) + grid_size / 6, convPos(so.pos.y), grid_size / 3, grid_size / 2);
      radarArea.add(sol, new Integer(1));
    }

    if (so instanceof Airfield) {
      int xa[] = new int[3], ya[] = new int[3];
      int l1 = grid_size / 2, l2 = grid_size / 6;
      xa[0] = convPos(so.pos.x);
      ya[0] = convPos(so.pos.y);
      xa[1] = convPos(so.pos.x) - l1 * so.dir.x - l2 * so.dir.y;
      ya[1] = convPos(so.pos.y) - l1 * so.dir.y + l2 * so.dir.x;
      xa[2] = convPos(so.pos.x) - l1 * so.dir.x + l2 * so.dir.y;
      ya[2] = convPos(so.pos.y) - l1 * so.dir.y - l2 * so.dir.x;
      g.drawPolygon(xa, ya, 3);
      JLabel sol = new JLabel(Integer.toString(so.id));
      sol.setForeground(so_text_color);
      sol.setBounds(
          convPos(so.pos.x) + grid_size / 6, convPos(so.pos.y), grid_size / 3, grid_size / 2);
      radarArea.add(sol, new Integer(1));
    }

    if (so instanceof Exit) {
      g.drawRect(
          convPos(so.pos.x) - grid_size / 6,
          convPos(so.pos.y) - grid_size / 6,
          grid_size / 3,
          grid_size / 3);
      JLabel sol = new JLabel(Integer.toString(so.id));
      sol.setForeground(so_text_color);
      sol.setBounds(
          convPos(so.pos.x) + grid_size / 6, convPos(so.pos.y), grid_size / 3, grid_size / 2);
      radarArea.add(sol, new Integer(1));
    }

    if (so instanceof Line) {
      g.setColor(line_color);
      g.drawLine(
          convPos(((Line) so).pos.x),
          convPos(((Line) so).pos.y),
          convPos(((Line) so).second_end.x),
          convPos(((Line) so).second_end.y));
    }

    radarArea.backIcon = new ImageIcon(radarArea.backImage);
    radarArea.back.setIcon(radarArea.backIcon);
  }
示例#25
0
 public void draw(Graphics2D g) {
   g.setColor(color);
   g.fillOval((int) x - r, (int) y - r, 2 * r, 2 * r);
   g.setStroke(new BasicStroke(3));
   g.setColor(color.darker());
   g.drawOval((int) x - r, (int) y - r, 2 * r, 2 * r);
   g.setStroke(new BasicStroke(1));
 }
示例#26
0
 @Override
 public void drawIcon(Graphics2D g2d, int width, int height) {
   int factor = 32 / width;
   g2d.setColor(COLOR);
   g2d.fillOval(2 / factor, 2 / factor, width - 4 / factor, height - 4 / factor);
   g2d.setColor(BORDER_COLOR);
   g2d.drawOval(2 / factor, 2 / factor, width - 4 / factor, height - 4 / factor);
 }
示例#27
0
 // Called in order to paint graphics for this robot.
 // "Paint" button on the robot console window for this robot must be
 // enabled in order to see the paintings.
 public void onPaint(Graphics2D g) {
   // Draw a red cross hair with the center at the current aim
   // coordinate (x,y)
   g.setColor(Color.RED);
   g.drawOval(aimX - 15, aimY - 15, 30, 30);
   g.drawLine(aimX, aimY - 4, aimX, aimY + 4);
   g.drawLine(aimX - 4, aimY, aimX + 4, aimY);
 }
示例#28
0
 @Override
 public void draw(Graphics2D g2d) {
   double radius = facade.getBulletRadius(getObject());
   double x = facade.getBulletX(getObject());
   double y = facade.getWorldHeight(world) - facade.getBulletY(getObject());
   g2d.setColor(getColor());
   g2d.drawOval((int) (x - radius), (int) (y - radius), (int) (2 * radius), (int) (2 * radius));
 }
    public void drawShape(Graphics2D g) {
      // super.drawShape(g);

      {
        int x = (int) (getPositionX() - width / 2);
        int y = (int) (getPositionY() - height / 2);

        g.drawOval(x, y, (int) width, (int) height);
      }

      if (doublecircle) {
        int x = (int) (getPositionX() - width / 2);
        int y = (int) (getPositionY() - height / 2);

        g.drawOval(x + 3, y + 3, (int) (width - 6), (int) (height - 6));
      }
    }
示例#30
0
 public void render(Obstacle obstacle) {
   Vector adjustedPosition = obstacle.position().add(viewPoint);
   graphics.drawOval(
       (int) (adjustedPosition.x() - obstacle.boundingRadius()),
       (int) (adjustedPosition.y() - obstacle.boundingRadius()),
       (int) (obstacle.boundingRadius() * 2),
       (int) (obstacle.boundingRadius() * 2));
 }