List of usage examples for java.awt Graphics2D drawOval
public abstract void drawOval(int x, int y, int width, int height);
From source file:Main.java
public static void main(String[] args) throws Exception { int size = 200; BufferedImage image = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB); Graphics2D g = image.createGraphics(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setColor(Color.BLUE);/*from www . ja v a 2 s. c o m*/ for (int i = 0; i < size; i += 5) { g.drawOval(i, i, size - i, size - i); } g.dispose(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(image, "png", baos); String data = DatatypeConverter.printBase64Binary(baos.toByteArray()); String imageString = "data:image/png;base64," + data; String html = "<html><body><img src='" + imageString + "'></body></html>"; System.out.println(html); }
From source file:net.noday.core.utils.Captcha.java
public static BufferedImage gen(String text, int width, int height) throws IOException { BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR); Graphics2D g = (Graphics2D) bi.getGraphics(); g.setColor(Color.GRAY);//from w ww . ja v a2s . c om g.fillRect(0, 0, width, height); for (int i = 0; i < 10; i++) { g.setColor(randColor(150, 250)); g.drawOval(random.nextInt(110), random.nextInt(24), 5 + random.nextInt(10), 5 + random.nextInt(10)); Font f = new Font("Arial", Font.ITALIC, 20); g.setFont(f); g.setColor(randColor(10, 240)); g.drawString(text, 4, 24); } return bi; }
From source file:com.hofbauer.robocode.robots.RobotSimWithAction.java
@Override public void onPaint(Graphics2D g) { g.setColor(Color.red);//from w ww . ja va2 s .c o m g.drawOval((int) (getX() - 50), (int) (getY() - 50), 100, 100); g.setColor(new Color(0, 0xFF, 0, 30)); g.fillOval((int) (getX() - 60), (int) (getY() - 60), 120, 120); }
From source file:no.met.jtimeseries.chart.XYWindArrowRenderer.java
private void drawCircle(Graphics2D g) { g.setStroke(new BasicStroke(1)); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.drawOval(-arrowHeight / 2, -arrowHeight / 2, arrowHeight, arrowHeight); }
From source file:adams.gui.visualization.stats.paintlet.Exponential.java
/** * The paint routine of the paintlet./*from w w w . j a va 2 s . c o m*/ * * @param g the graphics context to use for painting * @param moment what {@link PaintMoment} is currently being painted */ @Override protected void doPerformPaint(Graphics g, PaintMoment moment) { if ((m_Data != null) && (m_Sorted != null)) { GUIHelper.configureAntiAliasing(g, m_AntiAliasingEnabled); for (int i = 0; i < m_Sorted.length; i++) { Graphics2D g2d = (Graphics2D) g; //If data points are to be filled if (m_Fill) { g2d.setColor(m_FillColor); g2d.setStroke(new BasicStroke(0)); g2d.fillOval(m_AxisBottom.valueToPos(m_Sorted[i]) - m_Size / 2, m_AxisLeft.valueToPos(m_TransformedY[i]) - m_Size / 2, m_Size, m_Size); } //outline of data point g2d.setStroke(new BasicStroke(m_StrokeThickness)); g2d.setColor(m_Color); g2d.drawOval(m_AxisBottom.valueToPos(m_Sorted[i]) - m_Size / 2, m_AxisLeft.valueToPos(m_TransformedY[i]) - m_Size / 2, m_Size, m_Size); } //if drawing regression fit diagonal if (m_RegressionLine) { g.setColor(Color.BLACK); double[] newData = new double[m_Sorted.length]; for (int i = 0; i < m_Sorted.length; i++) { newData[i] = Math.log(m_Sorted[i]); } ExponentialDistributionImpl ex = new ExponentialDistributionImpl(StatUtils.mean(newData)); //draw the expected diagonal line using the exponential distribution for (int i = 0; i < m_Sorted.length - 1; i++) { double prob1; try { prob1 = ex.cumulativeProbability(newData[i]); } catch (MathException e) { prob1 = 0; } double prob2; try { prob2 = ex.cumulativeProbability(newData[i + 1]); } catch (MathException e) { prob2 = 0; } double p1 = -Math.log(1 - prob1); double p2 = -Math.log(1 - prob2); g.drawLine(m_AxisBottom.valueToPos(m_Sorted[i]), m_AxisLeft.valueToPos(p1), m_AxisBottom.valueToPos(m_Sorted[i + 1]), m_AxisLeft.valueToPos(p2)); } } } }
From source file:ImageDuplicity.java
private void createOffscreenImage() { Dimension d = getSize();// w ww.java 2s . com int width = d.width; int height = d.height; image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); try { String filename = "largeJava2sLogo.jpg"; InputStream in = getClass().getResourceAsStream(filename); JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(in); BufferedImage image = decoder.decodeAsBufferedImage(); in.close(); g2.drawImage(image, 0, 0, width, height, null); } catch (Exception e) { System.out.print(e); } g2.setStroke(new BasicStroke(2)); Color[] colors = { Color.red, Color.blue, Color.green }; for (int i = -32; i < 40; i += 8) { g2.setPaint(colors[Math.abs(i) % 3]); g2.drawOval(i, i, width - i * 2, height - i * 2); } }
From source file:business.ImageManager.java
public void doDrawCircle(Graphics2D big, int x, int y, Color color) { //setup para os rastros big.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); big.setStroke(new BasicStroke()); big.setColor(color);/*from ww w. j av a2 s . co m*/ //draw on graph big.drawOval(x, x, y, y); }
From source file:adams.gui.visualization.stats.paintlet.Gamma.java
/** * The paint routine of the paintlet./* w ww.j a va 2 s.c om*/ * * @param g the graphics context to use for painting * @param moment what {@link PaintMoment} is currently being painted */ @Override protected void doPerformPaint(Graphics g, PaintMoment moment) { if ((m_Data != null) && (m_Sorted != null) && m_Shape != -1.0) { GUIHelper.configureAntiAliasing(g, m_AntiAliasingEnabled); for (int i = 0; i < m_Sorted.length; i++) { Graphics2D g2d = (Graphics2D) g; //If data points are to be filled if (m_Fill) { g2d.setColor(m_FillColor); g2d.setStroke(new BasicStroke(0)); g2d.fillOval(m_AxisBottom.valueToPos(m_Sorted[i]) - m_Size / 2, m_AxisLeft.valueToPos(m_TransformedY[i]) - m_Size / 2, m_Size, m_Size); } //outline of data point g2d.setStroke(new BasicStroke(m_StrokeThickness)); g2d.setColor(m_Color); g2d.drawOval(m_AxisBottom.valueToPos(m_Sorted[i]) - m_Size / 2, m_AxisLeft.valueToPos(m_TransformedY[i]) - m_Size / 2, m_Size, m_Size); } //If drawing regression fit diagonal if (m_RegressionLine) { g.setColor(Color.BLACK); double[] newData = new double[m_Sorted.length]; for (int i = 0; i < m_Sorted.length; i++) { newData[i] = Math.log(m_Sorted[i]); } GammaDistributionImpl gd = new GammaDistributionImpl(m_Shape, m_Scale); //draw the expected diagonal line using the gamma distribution for (int i = 0; i < m_Sorted.length - 1; i++) { double p1; try { p1 = gd.cumulativeProbability(newData[i]); } catch (MathException e) { p1 = 0; } double p2; try { p2 = gd.cumulativeProbability(newData[i + 1]); } catch (MathException e) { p2 = 0; } g.drawLine(m_AxisBottom.valueToPos(m_Sorted[i]), m_AxisLeft.valueToPos(p1), m_AxisBottom.valueToPos(m_Sorted[i + 1]), m_AxisLeft.valueToPos(p2)); } } } }
From source file:AntiAlias.java
/** Draw the example */ public void paint(Graphics g1) { Graphics2D g = (Graphics2D) g1; BufferedImage image = // Create an off-screen image new BufferedImage(65, 35, BufferedImage.TYPE_INT_RGB); Graphics2D ig = image.createGraphics(); // Get its Graphics for drawing // Set the background to a gradient fill. The varying color of // the background helps to demonstrate the anti-aliasing effect ig.setPaint(new GradientPaint(0, 0, Color.black, 65, 35, Color.white)); ig.fillRect(0, 0, 65, 35);/* ww w .j av a2 s. c o m*/ // Set drawing attributes for the foreground. // Most importantly, turn on anti-aliasing. ig.setStroke(new BasicStroke(2.0f)); // 2-pixel lines ig.setFont(new Font("Serif", Font.BOLD, 18)); // 18-point font ig.setRenderingHint(RenderingHints.KEY_ANTIALIASING, // Anti-alias! RenderingHints.VALUE_ANTIALIAS_ON); // Now draw pure blue text and a pure red oval ig.setColor(Color.blue); ig.drawString("Java", 9, 22); ig.setColor(Color.red); ig.drawOval(1, 1, 62, 32); // Finally, scale the image by a factor of 10 and display it // in the window. This will allow us to see the anti-aliased pixels g.drawImage(image, AffineTransform.getScaleInstance(10, 10), this); // Draw the image one more time at its original size, for comparison g.drawImage(image, 0, 0, this); }
From source file:me.solhub.simple.engine.DebugLocationsStructure.java
@Override protected void draw() { Graphics2D g = (Graphics2D) getGraphics(); Graphics2D bbg = (Graphics2D) _backBuffer.getGraphics(); //anti-aliasing code // bbg.setRenderingHint( // RenderingHints.KEY_TEXT_ANTIALIASING, // RenderingHints.VALUE_TEXT_ANTIALIAS_ON); // bbg.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON ); bbg.setColor(Color.WHITE);/* w w w . j a v a 2s . c o m*/ bbg.fillRect(0, 0, _windowWidth, _windowHeight); bbg.translate(_xOffset, _yOffset); // draw destinations bbg.setColor(_simState.startingDestination.getColor()); bbg.drawOval(-(int) _simState.startingDestination.getRadius(), -(int) _simState.startingDestination.getRadius(), (int) _simState.startingDestination.getRadius() * 2, (int) _simState.startingDestination.getRadius() * 2); Iterator<Entry<Vector2D, Color>> blah = _destinationColors.entrySet().iterator(); double destinationRadius = _simState.getDestinationRadius(); while (blah.hasNext()) { Entry<Vector2D, Color> temp = blah.next(); bbg.setColor(temp.getValue()); //calculate center coordinate int x = (int) (temp.getKey().getX() - (destinationRadius)); int y = (int) (temp.getKey().getY() - (destinationRadius)); //drawOval draws a circle inside a rectangle bbg.drawOval(x, y, _simState.getDestinationRadius() * 2, _simState.getDestinationRadius() * 2); } // draw each of the agents Iterator<Agent> agentIter = _simState.getAgentIterator(); while (agentIter.hasNext()) { Agent temp = agentIter.next(); if (temp.isAlive()) { // decide whether to color for destination or group // if( isDestinationColors ) // { // // if stopped then blink white and destination color // if( temp.hasReachedDestination() ) // { // if( pulseWhite % 20 == 0 ) // { // bbg.setColor( Color.WHITE ); // } // else // { // bbg.setColor( temp.getDestinationColor() ); // } // } // else // { // bbg.setColor( temp.getDestinationColor() ); // } // } // else // { // // if stopped then blink black and white // if( temp.hasReachedDestination() ) // { // if( pulseWhite % 20 == 0 ) // { // bbg.setColor( Color.WHITE ); // } // else // { // bbg.setColor( temp.getGroup().getGroupColor() ); // } // } // //set color to red if cancelled and global and not multiple initiators // else if(temp.getCurrentDecision().getDecision().getDecisionType().equals( // DecisionType.CANCELLATION ) // && _simState.getCommunicationType().equals( "global" ) // && !Agent.canMultipleInitiate() // ) // { // bbg.setColor( Color.RED ); // } // else // { // bbg.setColor( temp.getGroup().getGroupColor() ); // } // } double dx = temp.getCurrentDestination().getX() - temp.getCurrentLocation().getX(); double dy = temp.getCurrentDestination().getY() - temp.getCurrentLocation().getY(); double heading = Math.atan2(dy, dx); Utils.drawDirectionalTriangle(bbg, heading - Math.PI / 2, temp.getCurrentLocation().getX(), temp.getCurrentLocation().getY(), 7, temp.getPreferredDestination().getColor(), temp.getGroup().getGroupColor()); // bbg.fillOval( (int) temp.getCurrentLocation().getX() - _agentSize, // (int) temp.getCurrentLocation().getY() - _agentSize , _agentSize * 2, _agentSize * 2 ); } } pulseWhite++; bbg.setColor(Color.BLACK); // the total number of groups bbg.setFont(_infoFont); bbg.drawString("Run: " + (_simState.getCurrentSimulationRun() + 1), _fontXOffset, _fontYOffset); bbg.drawString("Time: " + _simState.getSimulationTime(), _fontXOffset, _fontYOffset + _fontSize); bbg.drawString("Delay: " + LIVE_DELAY, _fontXOffset, _fontYOffset + _fontSize * 2); if (_simState.getCommunicationType().equals("global") && !Agent.canMultipleInitiate()) { String initiatorName = "None"; if (_initiatingAgent != null) { initiatorName = _initiatingAgent.getId().toString(); } bbg.drawString("Init: " + initiatorName, _fontXOffset, _fontYOffset + _fontSize * 3); bbg.drawString("Followers: " + _numberFollowing, _fontXOffset, _fontYOffset + _fontSize * 4); } else { bbg.drawString("Groups: " + _simState.getNumberGroups(), _fontXOffset, _fontYOffset + _fontSize * 3); bbg.drawString("Reached: " + _simState.numReachedDestination, _fontXOffset, _fontYOffset + _fontSize * 4); bbg.drawString("Inits: " + _simState.numInitiating, _fontXOffset, _fontYOffset + _fontSize * 5); bbg.drawString("Eaten: " + _simState.getPredator().getTotalAgentsEaten(), _fontXOffset, _fontYOffset + _fontSize * 6); } g.scale(_zoom, _zoom); g.drawImage(_backBuffer, 0, 0, this); if (SHOULD_VIDEO) { // setup to save to a png BufferedImage buff = new BufferedImage(_windowWidth, _windowHeight, BufferedImage.TYPE_INT_RGB); Graphics2D temp = (Graphics2D) buff.getGraphics(); temp.scale(8, 4); temp.drawImage(_backBuffer, 0, 0, this); // sub-directory File dir = new File("video"); dir.mkdir(); // format string for filename String filename = String.format("video/run-%03d-time-%05d.png", _simState.getCurrentSimulationRun(), _simState.getSimulationTime()); File outputfile = new File(filename); // save it try { ImageIO.write(buff, "png", outputfile); } catch (IOException e) { e.printStackTrace(); } } }