public void draw(Graphics g) { getPosition().transform(g); g.setColor(new Color(1f, 1f, 1f, (float) fade)); Graphics2D g2 = (Graphics2D) g; double sx = getPosition().getScaleX(); float strokeWidth = (float) (Math.pow(fade / LOW_FADE, .5) * 2 / sx); int s = 10; int gap = 90; int topGap = gap / 2; int left = 360 - gap - 10; g2.setStroke(new BasicStroke(strokeWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER)); g.drawArc(-s / 2, -s / 2, s, s, topGap, left); g2.setStroke(new BasicStroke(strokeWidth * .6f)); g.drawArc(-s / 2, -s / 2, s, s, topGap, left); g2.setStroke(new BasicStroke(strokeWidth * .4f)); g.drawArc(-s / 2, -s / 2, s, s, topGap, left); getPosition().untransform(g); }
// draw rectangles and arcs public void paintComponent(Graphics g) { super.paintComponent(g); // call superclass's paintComponent // start at 0 and sweep 360 degrees g.setColor(Color.RED); g.drawRect(15, 35, 80, 80); g.setColor(Color.BLACK); g.drawArc(15, 35, 80, 80, 0, 360); // start at 0 and sweep 110 degrees g.setColor(Color.RED); g.drawRect(100, 35, 80, 80); g.setColor(Color.BLACK); g.drawArc(100, 35, 80, 80, 0, 110); // start at 0 and sweep -270 degrees g.setColor(Color.RED); g.drawRect(185, 35, 80, 80); g.setColor(Color.BLACK); g.drawArc(185, 35, 80, 80, 0, -270); // start at 0 and sweep 360 degrees g.fillArc(15, 120, 80, 40, 0, 360); // start at 270 and sweep -90 degrees g.fillArc(100, 120, 80, 40, 270, -90); // start at 0 and sweep -270 degrees g.fillArc(185, 120, 80, 40, 0, -270); } // end method paintComponent
/** Overrides <code>Graphics.drawArc</code>. */ public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) { DebugGraphicsInfo info = info(); if (debugLog()) { info() .log( toShortString() + " Drawing arc: " + new Rectangle(x, y, width, height) + " startAngle: " + startAngle + " arcAngle: " + arcAngle); } if (isDrawingBuffer()) { if (debugBuffered()) { Graphics debugGraphics = debugGraphics(); debugGraphics.drawArc(x, y, width, height, startAngle, arcAngle); debugGraphics.dispose(); } } else if (debugFlash()) { Color oldColor = getColor(); int i, count = (info.flashCount * 2) - 1; for (i = 0; i < count; i++) { graphics.setColor((i % 2) == 0 ? info.flashColor : oldColor); graphics.drawArc(x, y, width, height, startAngle, arcAngle); Toolkit.getDefaultToolkit().sync(); sleep(info.flashTime); } graphics.setColor(oldColor); } graphics.drawArc(x, y, width, height, startAngle, arcAngle); }
public void paint(Graphics g) { g.setColor(Color.green); g.drawRect(25, 50, 200, 0); g.drawRect(25, 100, 200, 100); g.drawRoundRect(25, 250, 200, 100, 10, 10); g.drawRect(250, 100, 250, 100); g.fillRect(250, 100, 250, 100); g.setColor(Color.black); g.drawOval(250, 100, 250, 100); g.setColor(Color.green); g.drawOval(250, 250, 250, 99); g.fillOval(250, 250, 250, 100); g.drawOval(550, 100, 250, 100); g.drawArc(550, 100, 250, 100, 90, 82); g.fillArc(550, 100, 250, 100, 90, 82); g.drawOval(600, 250, 100, 100); }
// färger, se sid 43 i boken // grafiska metoder, sid 248 i boken public void paintComponent(Graphics g) { // för att vara säker på att // "super"-klassen gör sitt // anropar vi den metoden, innan // vi skriver eller ritar super.paintComponent(g); g.drawLine(185, 10, 195, 40); // x1,y1 till x2,y2 g.drawLine(200, 10, 200, 40); g.drawLine(215, 10, 205, 40); g.setColor(Color.white); g.fillOval(50, 30, 300, 150); // x,y,b,h (x,y för ö v h) g.setColor(Color.red); g.drawArc(100, 100, 200, 50, 180, 180); // x,y,b,h,s,l g.setColor(Color.yellow); g.fillRect(200, 100, 30, 30); g.fill3DRect(150, 50, 30, 50, true); // true upphöjd figur g.fill3DRect(250, 50, 30, 50, true); // skriv ut en textsträng, samt ange läget i avståndet från // övre vänstra hörnet i x-led åt höger och i y-led neråt g.drawString("** Tjenare kompis !! **", 20, 20); f = new Font("Arial", Font.BOLD, 30); setBackground(Color.cyan); g.setFont(f); g.setColor(new Color(255, 175, 175)); g.drawString("YEEEEEEEES!!", 100, 250); }
/** Repaint the screen */ public void paint(java.awt.Graphics g) { super.paintComponent(g); java.awt.Dimension panelSize = new java.awt.Dimension(); this.getSize(panelSize); int panelX = (int) panelSize.getWidth(); int panelY = (int) panelSize.getHeight(); int panelCenterX = panelX / 2; int panelCenterY = panelY / 2; /* Draw grid */ g.setColor(java.awt.Color.white); g.drawLine(0, panelCenterY, panelX, panelCenterY); g.drawLine(panelCenterX, 0, panelCenterX, panelY); g.translate(panelCenterX, panelCenterY); g.drawOval(-2, -2, 4, 4); /* Draw significant points on path */ g.setColor(java.awt.Color.blue); g.fillOval(_x1 - 2, -_y1 - 2, 4, 4); g.setColor(java.awt.Color.cyan); g.fillOval(_xTurn - 2, -_yTurn - 2, 4, 4); g.setColor(java.awt.Color.red); g.fillOval(_x2 - 2, -_y2 - 2, 4, 4); /* Draw arc and line of robot's path */ g.setColor(java.awt.Color.green); g.drawArc(_cx - RADIUS, -_cy - RADIUS, RADIUS * 2, RADIUS * 2, _theta, -_arcAngle); g.drawLine(_xTurn, -_yTurn, _x2, -_y2); }
/** Standard override -- draws all the dots. */ public void paintComponent(Graphics g) { // As a JPanel subclass we need call super.paintComponent() // so JPanel will draw the white background for us. super.paintComponent(g); Color origColor = g.getColor(); for (Line l : lines) { if (l.isPencil()) { g.setColor(Color.RED); } else { g.setColor(Color.BLACK); } g.drawLine((int) l.getX1(), (int) l.getY1(), (int) l.getX2(), (int) l.getY2()); } g.setColor(origColor); // Go through all the dots, drawing a circle for each for (ManModel dotModel : dots) { // g.drawImage(img, dotModel.getX() - MAN_WIDTH/2, dotModel.getY() - MAN_HEIGHT/2, MAN_WIDTH, // MAN_HEIGHT, null); g.drawImage( img, dotModel.getX() - Constants.MAN_WIDTH / 2, dotModel.getY() - Constants.MAN_HEIGHT / 2, null); } numberMen.setText("" + dots.size()); // Draw the "requested" clip rect in red // (this just shows off smart-repaint) if (redPaint) { Rectangle clip = g.getClipBounds(); if (clip != null) { g.setColor(Color.red); g.drawRect(clip.x, clip.y, clip.width - 1, clip.height - 1); g.setColor(origColor); } } g.setColor(Color.RED); for (Line l : circles) { g.drawLine((int) l.getX1(), (int) l.getY1(), (int) l.getX2(), (int) l.getY2()); } for (Arc l : arcs) { g.drawArc( (int) l.getX1(), (int) l.getY1(), (int) l.getWidth(), (int) l.getHeight(), (int) l.getStartAngle(), (int) l.getSweep()); // g.drawArc((int) l.getX1(), (int) l.getY1(), (int) l.getWidth()+1, (int) l.getHeight()+1, // l.getStartAngle()-1, l.getSweep()); } g.setColor(Color.BLACK); }
protected void paintRoundedBottomTabBorder( int tabIndex, Graphics g, int x1, int y1, int x2, int y2, boolean isSelected) { Graphics2D g2D = (Graphics2D) g; Object savedRederingHint = g2D.getRenderingHint(RenderingHints.KEY_ANTIALIASING); g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int d = 2 * GAP; if (isSelected) { g.setColor(AbstractLookAndFeel.getTheme().getFrameColor()); } else { g.setColor(ColorHelper.brighter(AbstractLookAndFeel.getTheme().getFrameColor(), 40)); } g.drawLine(x1 + GAP, y2, x2 - GAP, y2); g.drawArc(x1, y2 - d, d, d, 180, 90); g.drawArc(x2 - d, y2 - d, d, d, -90, 90); g.drawLine(x1, y1, x1, y2 - GAP - 1); g.drawLine(x2, y1, x2, y2 - GAP - 1); g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, savedRederingHint); }
private void drawCluster(Graphics g, List<ClusterVM> cvms) { Color cache = g.getColor(); for (int i = 0; i < cvms.size(); i++) { ClusterVM cvm = cvms.get(i); Observation loc = cvm.getCluster().getCentroid(); int cx = (int) loc.x, cy = (int) loc.y; int r = clusterRadius; Color color = cvm.getClusterColor(); g.setColor(color); g.fillArc(cx - r, cy - r, 1 + 2 * r, 1 + 2 * r, 0, 360); g.setColor(Color.WHITE); g.drawArc(cx - r, cy - r, 1 + 2 * r, 1 + 2 * r, 0, 360); g.setColor(Color.BLACK); g.drawArc(cx - r - 1, cy - r - 1, 1 + 2 * r + 2, 1 + 2 * r + 2, 0, 360); } g.setColor(cache); }
public void paint(Graphics g) { g.drawString("Hello", 40, 40); setBackground(Color.white); g.fillRect(130, 30, 100, 80); g.drawOval(30, 130, 50, 60); setForeground(Color.red); g.fillOval(130, 130, 50, 60); g.drawArc(30, 200, 40, 50, 90, 60); g.fillArc(50, 200, 40, 20, 180, 40); }
public void drawSegment(Point p1, Point p2, Color color) { g.setColor(color); double t = Math.atan2(p2.x - p1.x, p2.y - p1.y); double cosT = Math.cos(t); double sinT = Math.sin(t); int deg = (int) Math.toDegrees(t); if (selected) { int[] x = new int[] { (int) (p1.x + 5 * cosT), (int) (p2.x + 5 * cosT), (int) (p2.x - 5 * cosT), (int) (p1.x - 5 * cosT) }; int[] y = new int[] { (int) (p1.y - 5 * sinT), (int) (p2.y - 5 * sinT), (int) (p2.y + 5 * sinT), (int) (p1.y + 5 * sinT) }; g.fillPolygon(x, y, 4); g.fillArc(p1.x - 5, p1.y - 5, 10, 10, deg, 180); g.fillArc(p2.x - 5, p2.y - 5, 10, 10, deg, -180); } else { g.drawLine( (int) (p1.x + 5 * cosT), (int) (p1.y - 5 * sinT), (int) (p2.x + 5 * cosT), (int) (p2.y - 5 * sinT)); g.drawLine( (int) (p1.x - 5 * cosT), (int) (p1.y + 5 * sinT), (int) (p2.x - 5 * cosT), (int) (p2.y + 5 * sinT)); g.drawArc(p1.x - 5, p1.y - 5, 10, 10, deg, 180); g.drawArc(p2.x - 5, p2.y - 5, 10, 10, deg, -180); } }
/** paints the Spinner */ public void paint(Graphics g) { int start_angle = 90; int done_angle = (int) (percentDone * 360); g.setColor(getBackground()); g.fillArc(3, 3, getSize().width - 8, getSize().height - 8, 0, 360); g.setColor(getForeground()); g.fillArc(3, 3, getSize().width - 8, getSize().height - 8, start_angle, done_angle); g.setColor(Color.black); g.drawArc(3, 3, getSize().width - 8, getSize().height - 8, 0, 360); }
/** * Draws and arc which looks like a curve.<br> * An ARC is a "piece" of an OVAL.<br> * The first 5 parameters (g and 4 ints) are the same as drawOval.<br> * There are 2 additional parameters for the starting degree value and finishing degree of the * arc. <br> * 0 degrees is at the 12:00 position and the degrees progress in a CLOCKWISE fashion. <br> * (90 degrees is at 3:00, 180 degrees is at 6:00, 270 degrees is at 9:00, 360 degrees is back at * 12:00). */ public static void drawArc( Graphics g, int centerX, int centerY, int hRadius, int vRadius, int start, int finish) { int hDiameter = 2 * hRadius; int vDiameter = 2 * vRadius; if (finish < start) finish += 360; int newStart = 90 - start; // shifts starting position from 3:00 to 12:00 int newFinish = start - finish; // as opposed to finish-start. Subtracting backwards changes from // counter-clockwise to clockwise. g.drawArc(centerX - hRadius, centerY - vRadius, hDiameter, vDiameter, newStart, newFinish); }
/* public void draw_visualization_2(Graphics g) { g.setColor(new Color(230, 140, 170)); if (flag_2 == true) { g.setColor(new Color(250, 20, 5)); } else { g.setColor(new Color(5, 250, 20)); } g.drawArc(120, 140, 40, 40, 0, 360); g.drawLine(140, 180, 140, 230); g.drawLine(140, 230, 100, 260); g.drawLine(140, 230, 180, 260); g.drawLine(140, 180, 100, 200); g.drawLine(140, 180, 180, 200); } */ public void draw_a(Graphics g) { int p = -35, r = -50; g.translate(p, r); p = p + 10; r = r + 12; g.setColor(new Color(250, 0, 0)); g.drawPolyline(a_x, a_y, 6); g.setColor(new Color(0, 250, 0)); g.drawPolyline(a_x_1, a_y_1, 6); g.setColor(new Color(0, 0, 250)); g.drawPolyline(a_x_2, a_y_2, 6); g.setColor(new Color(74, 124, 197)); g.drawPolyline(a_x_3, a_y_3, 6); g.translate(p, r); p = p + 10; r = r + 12; g.setColor(new Color(250, 0, 0)); g.drawArc(a_x[5] - 20, a_y[5] - 20, 20, 20, 0, 360); g.fillArc(a_x[5] - 20, a_y[5] - 20, 20, 20, 0, 360); g.setColor(new Color(0, 250, 0)); g.drawArc(a_x_1[5] - 20, a_y_1[5] - 20, 20, 20, 0, 360); g.fillArc(a_x_1[5] - 20, a_y_1[5] - 20, 20, 20, 0, 360); g.setColor(new Color(0, 0, 250)); g.drawArc(a_x_2[5] - 20, a_y_2[5] - 20, 20, 20, 0, 360); g.fillArc(a_x_2[5] - 20, a_y_2[5] - 20, 20, 20, 0, 360); g.setColor(new Color(74, 124, 197)); g.drawArc(a_x_3[5] - 20, a_y_3[5] - 20, 20, 20, 0, 360); g.fillArc(a_x_3[5] - 20, a_y_3[5] - 20, 20, 20, 0, 360); g.translate(p, r); p = p + 10; r = r + 12; // drawetc(g); }
@Override public void paintComponent(Graphics g) { super.paintComponent(g); int midX = getWidth() / 2; // Draw a big eye right in the middle of the face. int eyeRadius = (int) (0.05 * SIZE); g.fillOval(midX - eyeRadius, headRadius - eyeRadius * 2, 2 * eyeRadius, 2 * eyeRadius); // And give him a creepy smile. int smileRadius = (int) (0.5 * headRadius); g.drawArc( midX - smileRadius, (int) (0.8 * headRadius), smileRadius * 2, smileRadius * 2, 0, -180); }
@Override public void paint(Graphics g) { super.paint(g); g.drawLine(150, 75, 150, 375); g.drawLine(120, 375, 400, 375); g.drawLine(150, 75, 250, 75); g.drawLine(250, 75, 250, 125); g.setColor(Color.blue); g.drawLine(250, 175, 250, 250); g.drawArc(225, 125, 50, 50, 0, 360); g.drawLine(250, 200, 225, 175); g.drawLine(250, 200, 275, 175); g.drawLine(250, 250, 225, 275); g.drawLine(250, 250, 275, 275); g.drawString("You have won the game", 300, 225); }
public void paint(Graphics g) { int x1 = 30; int y1 = 30; int x2 = 60; int y2 = 50; g.drawRect(x1, y1, x2, y2); x1 = 80; y1 = 80; x2 = 100; y2 = 100; g.drawOval(x1, y1, x2, y2); x1 = 200; y1 = 60; x2 = 60; y2 = 60; g.drawArc(x1, y1, x2, y2, 0, 180); }
protected void test1(Graphics g) { double a = 100; double b = 100; // a = 200; // b = 200; double c = 200; double d = 200; // c = 100; // d = 100; double alpha = (60.0 / 360.0) * 2 * Math.PI; double s = Math.sqrt((c - a) * (c - a) + (d - b) * (d - b)); double r = s / (2 * Math.sin(alpha)); System.out.println("Radius is " + r + "."); double p1 = (a + c) / 2; double p2 = (b + d) / 2; double h = s / 2 * Math.cos(alpha) / Math.sin(alpha); double z1 = -1; double z2 = -(a - c) * z1 / (b - d); System.out.println("Z is (" + z1 + "," + z2 + ")."); double zb = Math.sqrt(z1 * z1 + z2 * z2); z1 = z1 / zb; z2 = z2 / zb; double m1 = p1 + h * z1; double m2 = p2 + h * z2; g.drawOval((int) a - 1, (int) b - 1, 2, 2); g.drawString("1", (int) a, (int) b); g.drawOval((int) c - 1, (int) d - 1, 2, 2); g.drawString("2", (int) c, (int) d); g.drawOval((int) m1 - 1, (int) m2 - 1, 2, 2); g.drawString("M", (int) m1, (int) m2); double phi1 = Math.atan((-b + m2) / (a - m1)) * 360 / (2 * Math.PI) + ((a - m1 < 0) ? 180 : 0); double phi2 = Math.atan((-d + m2) / (c - m1)) * 360 / (2 * Math.PI) + ((c - m1 < 0) ? 180 : 0); System.out.println("phi is (" + phi1 + "," + phi2 + ")."); g.drawArc( (int) (m1 - r), (int) (m2 - r), (int) (2 * r), (int) (2 * r), (int) (phi1), (int) (phi2 - phi1)); }
public void paint(Graphics canvas) { canvas.setColor(Color.RED); canvas.drawRect(A_FACE, B_FACE, FACE_LENGTH, FACE_LENGTH); canvas.fillRect(A_FACE, B_FACE, FACE_LENGTH, FACE_LENGTH); canvas.setColor(Color.GREEN); canvas.fillRect(10, 20, 30, 40); canvas.setColor(Color.BLUE); canvas.fillOval(A_RIGHT_EYE, B_RIGHT_EYE, EYE_WIDTH, EYE_HEIGHT); canvas.setColor(Color.YELLOW); canvas.fillOval(A_LEFT_EYE, B_LEFT_EYE, EYE_WIDTH, EYE_HEIGHT); canvas.setColor(Color.ORANGE); canvas.drawArc( A_MOUTH, B_MOUTH, MOUTH_WIDTH, MOUTH_HEIGHT, MOUTH_START_ANGLE, -MOUTH_EXTENT_ANGLE); canvas.drawLine(150, 50, 0, 0); }
@Override public void paintComponent(Graphics g) { if (slices != null && !slices.isEmpty()) { Arc2D arc2D = null; double start = 0; int size = Math.min(getWidth(), getHeight()) - 10; int x = getWidth() / 2 - size / 2; int y = getHeight() / 2 - size / 2; if (g instanceof Graphics2D) { arc2D = new Arc2D.Double(Arc2D.PIE); arc2D.setFrame(x, y, size, size); ((Graphics2D) g) .setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); } for (PieSlice slice : slices) { double arc = (slice.cost / total) * 360.0; if (g instanceof Graphics2D) { arc2D.setAngleStart(start); arc2D.setAngleExtent(arc); Color c = ScenarioColorPalette.getColor(slice.toString()); g.setColor(slice.equals(highlighted) ? c.brighter() : c); ((Graphics2D) g).fill(arc2D); g.setColor(Color.BLACK); ((Graphics2D) g).draw(arc2D); } else { g.setColor(ScenarioColorPalette.getColor(slice.toString())); g.fillArc(x, y, size, size, (int) start, (int) arc); g.setColor(Color.BLACK); g.drawArc(x, y, size, size, (int) start, (int) arc); } start += arc; } g.setColor(ScenarioColorPalette.getColor("Untagged")); g.fillArc(x, y, size, size, (int) start, (int) (360.0 - start)); } }
private static void paintArc(Graphics g, RemoteArc arc, boolean fill) { try { Rectangle bounds = arc.getBounds(); if (fill) g.fillArc( bounds.x, bounds.y, bounds.width, bounds.height, arc.getStartAngle(), arc.getEndAngle()); else g.drawArc( bounds.x, bounds.y, bounds.width, bounds.height, arc.getStartAngle(), arc.getEndAngle()); } catch (Exception e) { e.printStackTrace(); // System.out.println(e); } }
/** * @param g * @param col * @param row * @param iDir */ void DrawBoundary(Graphics g, int col, int row, int iDir) { int x, y; x = col * 16; y = row * 16; switch (iDir) { case ctables.LEFT: // draw lower half segment if (iMaze[row + 1][col] != WALL) // down empty if (iMaze[row + 1][col - 1] != WALL) // left-down empty { // arc(x-8,y+8,270,0,6); g.drawArc(x - 8 - 6, y + 8 - 6, 12, 12, 270, 100); } else { g.drawLine(x - 2, y + 8, x - 2, y + 16); } else { g.drawLine(x - 2, y + 8, x - 2, y + 17); g.drawLine(x - 2, y + 17, x + 7, y + 17); } // Draw upper half segment if (iMaze[row - 1][col] != WALL) // upper empty if (iMaze[row - 1][col - 1] != WALL) // upper-left empty { // arc(x-8,y+7,0,90,6); g.drawArc(x - 8 - 6, y + 7 - 6, 12, 12, 0, 100); } else { g.drawLine(x - 2, y, x - 2, y + 7); } else { g.drawLine(x - 2, y - 2, x - 2, y + 7); g.drawLine(x - 2, y - 2, x + 7, y - 2); } break; case ctables.RIGHT: // draw lower half segment if (iMaze[row + 1][col] != WALL) // down empty if (iMaze[row + 1][col + 1] != WALL) // down-right empty { // arc(x+16+7,y+8,180,270,6); g.drawArc(x + 16 + 7 - 6, y + 8 - 6, 12, 12, 180, 100); } else { g.drawLine(x + 17, y + 8, x + 17, y + 15); } else { g.drawLine(x + 8, y + 17, x + 17, y + 17); g.drawLine(x + 17, y + 8, x + 17, y + 17); } // Draw upper half segment if (iMaze[row - 1][col] != WALL) // upper empty if (iMaze[row - 1][col + 1] != WALL) // upper-right empty { // arc(x+16+7,y+7,90,180,6); g.drawArc(x + 16 + 7 - 6, y + 7 - 6, 12, 12, 90, 100); } else { g.drawLine(x + 17, y, x + 17, y + 7); } else { g.drawLine(x + 8, y - 2, x + 17, y - 2); g.drawLine(x + 17, y - 2, x + 17, y + 7); } break; case ctables.UP: // draw left half segment if (iMaze[row][col - 1] != WALL) // left empty if (iMaze[row - 1][col - 1] != WALL) // left-upper empty { // arc(x+7,y-8,180,270,6); g.drawArc(x + 7 - 6, y - 8 - 6, 12, 12, 180, 100); } else { g.drawLine(x, y - 2, x + 7, y - 2); } // Draw right half segment if (iMaze[row][col + 1] != WALL) // right empty if (iMaze[row - 1][col + 1] != WALL) // right-upper empty { // arc(x+8,y-8,270,0,6); g.drawArc(x + 8 - 6, y - 8 - 6, 12, 12, 270, 100); } else { g.drawLine(x + 8, y - 2, x + 16, y - 2); } break; case ctables.DOWN: // draw left half segment if (iMaze[row][col - 1] != WALL) // left empty if (iMaze[row + 1][col - 1] != WALL) // left-down empty { // arc(x+7,y+16+7,90,180,6); g.drawArc(x + 7 - 6, y + 16 + 7 - 6, 12, 12, 90, 100); } else { g.drawLine(x, y + 17, x + 7, y + 17); } // Draw right half segment if (iMaze[row][col + 1] != WALL) // right empty if (iMaze[row + 1][col + 1] != WALL) // right-down empty { // arc(x+8,y+16+7,0,90,6); g.drawArc(x + 8 - 6, y + 16 + 7 - 6, 12, 12, 0, 100); } else { g.drawLine(x + 8, y + 17, x + 15, y + 17); } break; } }
// ----------------------------------------------------------------- // Draws a snowman. // ----------------------------------------------------------------- public void paintComponent(Graphics page) { super.paintComponent(page); final int MID = 170; final int TOP = 50; // constants for snow body final int head = 40; final int UP_T[] = {70, 50}; final int LOW_T[] = {100, 60}; // coordinates for shadow hat polygon final int hatX[] = {MID - 70, MID - 50, MID - 65, MID - 85}; final int hatY[] = {TOP + 168, TOP + 173, TOP + 193, TOP + 188}; // coordinates for sun rays final int ray1X[] = {250, 255, -100, -110}; final int ray1Y[] = {5, 15, 95, 45}; final int ray2X[] = {260, 280, 170, -130}; final int ray2Y[] = {30, 45, 360, 220}; final char name[] = {'E', '.', 'Z', '.'}; setBackground(Color.blue); page.setColor(Color.yellow); page.fillOval(260, -40, 80, 80); // sun page.fillPolygon(ray1X, ray1Y, 4); // upper sun ray page.fillPolygon(ray2X, ray2Y, 4); // lower sun ray // ground changed to white page.setColor(Color.white); page.fillRect(0, 175, 300, 50); // ground // shadow body added page.setColor(Color.lightGray); page.fillOval(MID - 60, TOP + 120, LOW_T[0], LOW_T[1] / 2); // lower torso shadow page.fillOval(MID - 65, TOP + 140, UP_T[0], UP_T[1] / 2); // upper torso shadow page.fillOval(MID - 70, TOP + 155, head, head / 2); // head shadow page.drawLine(MID - 75, TOP + 165, MID - 45, TOP + 180); // hat brim shadow page.drawLine(MID - 75, TOP + 166, MID - 45, TOP + 181); // thicker brim shadow page.fillPolygon(hatX, hatY, 4); // had shadow page.setColor(Color.white); page.fillOval(MID - 20, TOP, 40, 40); // head page.fillOval(MID - 35, TOP + 35, UP_T[0], UP_T[1]); // upper torso page.fillOval(MID - 50, TOP + 80, LOW_T[0], LOW_T[1]); // lower torso page.setColor(Color.red); page.fillOval(MID - 5, TOP + 45, 10, 10); // 1st button page.fillOval(MID - 5, TOP + 65, 10, 10); // 2nd button page.setColor(Color.black); page.fillOval(MID - 10, TOP + 10, 5, 5); // left eye page.fillOval(MID + 5, TOP + 10, 5, 5); // right eye page.drawArc(MID - 10, TOP + 25, 20, 10, 10, 160); // frown, was smile page.drawLine(MID - 25, TOP + 60, MID - 50, TOP + 40); // left arm page.drawLine(MID + 25, TOP + 60, MID + 55, TOP + 60); // right arm page.drawLine(MID - 20, TOP + 5, MID + 20, TOP + 5); // brim of hat page.drawLine(MID - 20, TOP + 4, MID + 20, TOP + 4); // thicker brim page.fillRect(MID - 15, TOP - 20, 30, 25); // top of hat page.setColor(Color.white); page.drawChars(name, 0, 4, 10, 20); // display name }
public void paintComponent(Graphics g) { super.paintComponent(g); g.setColor(Color.WHITE); // Draws a white arrow and the principal axis g.drawLine(0, 200, 700, 200); g.drawLine(arrow_x, 200, arrow_x, arrow_y2); // Show coordinates of arrow tip arrowCoordinate_x = arrow_x - startingPosition; arrowCoordinate_x /= 10; arrowCoordinate_y = 200 - arrow_y2; arrowCoordinate_y /= 10; // Coordinates Optics.lbl_arrowCoordinates.setText( "<html>(d<sub>o</sub>, h<sub>o</sub>) = (" + arrowCoordinate_x + ", " + arrowCoordinate_y + ")</html>"); if (arrow_y2 < 200) // if arrow is above principal axis { g.drawLine(arrow_x, arrow_y2, arrow_x - 7, arrow_y2 + 7); g.drawLine(arrow_x, arrow_y2, arrow_x + 7, arrow_y2 + 7); } else if (arrow_y2 > 200) // if arrow is below principal axis { g.drawLine(arrow_x, arrow_y2, arrow_x - 7, arrow_y2 - 7); g.drawLine(arrow_x, arrow_y2, arrow_x + 7, arrow_y2 - 7); } // Draws lines for the grid if (lenses) startingPosition = 350; else { radiusOfCurvature = 20 * focalLength; if (type == 0) startingPosition = 500; else startingPosition = 350; } { for (int i = startingPosition; i <= 700; i += 10) { if ((i - startingPosition) % (10 * focalLength) == 0) { g.setColor(Color.ORANGE); g.drawLine(i, 195, i, 205); } else { g.setColor(Color.WHITE); g.drawLine(i, 197, i, 203); } } for (int i = startingPosition; i >= 0; i -= 10) { if ((i - startingPosition) % (10 * focalLength) == 0 && i != 0) { g.setColor(Color.ORANGE); g.drawLine(i, 195, i, 205); } else { g.setColor(Color.WHITE); g.drawLine(i, 197, i, 203); } } } g.setColor(Color.WHITE); if (lenses) { if (type == 0) // If Converging { // Draws a converging lens g.drawArc(340, 50, 40, 300, 120, 120); g.drawArc(320, 50, 40, 300, 60, -120); // draws horizontal line from the tip of the arrow to the lens (line 1/3) g.setColor(Color.RED); g.drawLine(arrow_x, arrow_y2, 350, arrow_y2); // calculates necessary information to form equation of line from lens to focal point (line // 2/3) dy_1 = 200 - arrow_y2; if (arrow_x > 350) dx_1 = -10 * focalLength; else dx_1 = 10 * focalLength; slope_1 = dy_1 / dx_1; if (arrow_x > 350) y_intercept_1 = 200 - slope_1 * (350 - 10 * focalLength); else y_intercept_1 = 200 - slope_1 * (10 * focalLength + 350); // Calculates coordinates of points on the edge of screen (endpoints) if (arrow_x <= 350) y_screenIntersection_1 = (int) (Math.round(slope_1 * 700 + y_intercept_1)); else y_screenIntersection_1 = (int) (Math.round(y_intercept_1)); if (slope_1 != 0) if (arrow_y2 <= 200) x_screenIntersection_1 = (int) (Math.round((400 - y_intercept_1) / slope_1)); else x_screenIntersection_1 = (int) (Math.round(-y_intercept_1 / slope_1)); if (x_screenIntersection_1 >= 0 && x_screenIntersection_1 <= 700) // If endpoint is on the x-edge if (arrow_y2 <= 200) g.drawLine(350, arrow_y2, x_screenIntersection_1, 400); else g.drawLine(350, arrow_y2, x_screenIntersection_1, 0); else if (arrow_x > 350) g.drawLine(350, arrow_y2, 0, y_screenIntersection_1); else g.drawLine(350, arrow_y2, 700, y_screenIntersection_1); // Else: endpoint is on the y-edge } else // Else: Diverging { // Draws a diverging lens g.drawArc(360, 50, 40, 300, 120, 120); g.drawArc(300, 50, 40, 300, 60, -120); g.drawLine(330, 68, 370, 68); g.drawLine(330, 330, 370, 330); // draws horizontal line from the tip of the arrow to the lens (line 1/3) g.setColor(Color.RED); g.drawLine(arrow_x, arrow_y2, 350, arrow_y2); // calculates necessary information to form equation of line from lens to focal point (line // 2/3) dy_1 = arrow_y2 - 200; if (arrow_x > 350) dx_1 = -10 * focalLength; else dx_1 = 10 * focalLength; slope_1 = dy_1 / dx_1; if (arrow_x > 350) y_intercept_1 = 200 - slope_1 * (10 * focalLength + 350); else y_intercept_1 = 200 - slope_1 * (350 - 10 * focalLength); // Calculates coordinates of points on the edge of screen (endpoints) if (arrow_x <= 350) y_screenIntersection_1 = (int) (Math.round(slope_1 * 700 + y_intercept_1)); else y_screenIntersection_1 = (int) (Math.round(y_intercept_1)); if (slope_1 != 0) if (arrow_y2 <= 200) x_screenIntersection_1 = (int) (Math.round(-y_intercept_1 / slope_1)); else x_screenIntersection_1 = (int) (Math.round((400 - y_intercept_1) / slope_1)); if (x_screenIntersection_1 >= 0 && x_screenIntersection_1 <= 700) // If endpoint is on the x-edge if (arrow_y2 <= 200) g.drawLine(350, arrow_y2, x_screenIntersection_1, 0); else g.drawLine(350, arrow_y2, x_screenIntersection_1, 400); else // Else: endpoint is on the y-edge if (arrow_x > 350) g.drawLine(350, arrow_y2, 0, y_screenIntersection_1); else g.drawLine(350, arrow_y2, 700, y_screenIntersection_1); } // Line 3/3 dy_2 = 200 - arrow_y2; dx_2 = 350 - arrow_x; slope_2 = dy_2 / dx_2; y_intercept_2 = 200 - slope_2 * 350; if (arrow_x <= 350) y_screenIntersection_2 = (int) (Math.round(slope_2 * 700 + y_intercept_2)); else y_screenIntersection_2 = (int) (Math.round(y_intercept_2)); if (slope_2 != 0) if (arrow_y2 <= 200) x_screenIntersection_2 = (int) (Math.round((400 - y_intercept_2) / slope_2)); else x_screenIntersection_2 = (int) (Math.round(-y_intercept_2 / slope_2)); if (x_screenIntersection_2 >= 0 && x_screenIntersection_2 <= 700) // If endpoint is on the x-edge if (arrow_y2 <= 200) g.drawLine(arrow_x, arrow_y2, x_screenIntersection_2, 400); else g.drawLine(arrow_x, arrow_y2, x_screenIntersection_2, 0); else if (arrow_x <= 350) g.drawLine( arrow_x, arrow_y2, 700, y_screenIntersection_2); // Else: endpoint is on the y-edge else g.drawLine(arrow_x, arrow_y2, 0, y_screenIntersection_2); // POI between Line 2 & Line 3 x_pointOfIntersection = (int) ((y_intercept_2 - y_intercept_1) / (slope_1 - slope_2)); y_pointOfIntersection = (int) (slope_1 * x_pointOfIntersection + y_intercept_1); // Draw image g.setColor(Color.ORANGE); g.drawLine(x_pointOfIntersection, 200, x_pointOfIntersection, y_pointOfIntersection); if (y_pointOfIntersection < 200) { g.drawLine( x_pointOfIntersection, y_pointOfIntersection, x_pointOfIntersection - 7, y_pointOfIntersection + 7); g.drawLine( x_pointOfIntersection, y_pointOfIntersection, x_pointOfIntersection + 7, y_pointOfIntersection + 7); } else { g.drawLine( x_pointOfIntersection, y_pointOfIntersection, x_pointOfIntersection - 7, y_pointOfIntersection - 7); g.drawLine( x_pointOfIntersection, y_pointOfIntersection, x_pointOfIntersection + 7, y_pointOfIntersection - 7); } // Same side image line continuation if (((x_pointOfIntersection > 350 && arrow_x > 350) || (x_pointOfIntersection < 350 && arrow_x < 350)) && (arrow_x != 350 - 10 * focalLength && arrow_x != 350 + 10 * focalLength || type == 1)) { g.setColor(Color.YELLOW); g.drawLine(x_pointOfIntersection, y_pointOfIntersection, 350, arrow_y2); if (type == 0) g.drawLine(x_pointOfIntersection, y_pointOfIntersection, arrow_x, arrow_y2); } // Mag calculations height_image = 200 - y_pointOfIntersection; height_object = 200 - arrow_y2; if (height_object != 0) magnification = height_image / height_object; if (magnification <= 9999 && magnification >= -9999) Optics.txt_magnification.setText("" + roundTwoDecimals(magnification)); else if (magnification > 9999) { magnification = Double.POSITIVE_INFINITY; Optics.txt_magnification.setText("N/A"); } else { magnification = Double.NEGATIVE_INFINITY; Optics.txt_magnification.setText("N/A"); } // Characteristics g.setColor(Color.ORANGE); g.drawString("Image Characteristics:", 20, 300); if (type == 0) { if ((Math.abs(magnification) > 1 && Math.abs(magnification) < 9999)) g.drawString("Magnification: Enlarged", 20, 320); else if (arrow_x == 350 - 20 * focalLength || arrow_x == 350 + 20 * focalLength || (int) (Math.abs(magnification)) == 1) g.drawString("Magnification: None", 20, 320); else if (Math.abs(magnification) < 1 && Math.abs(magnification) > 0) g.drawString("Magnification: Diminished", 20, 320); else g.drawString("Magnification: N/A", 20, 320); if (arrow_x == 350 - 10 * focalLength || arrow_x == 350 + 10 * focalLength) g.drawString("Orientation: N/A", 20, 335); else if ((arrow_y2 < 200 && y_pointOfIntersection < 200) || (arrow_y2 > 200 && y_pointOfIntersection > 200)) g.drawString("Orientation: Upright", 20, 335); else g.drawString("Orientation: Inverted", 20, 335); if (arrow_x == 350 - 10 * focalLength || arrow_x == 350 + 10 * focalLength) g.drawString("Type: N/A", 20, 350); else if ((x_pointOfIntersection < 350 && arrow_x < 350) || (x_pointOfIntersection > 350 && arrow_x > 350)) g.drawString("Type: Virtual", 20, 350); else g.drawString("Type: Real", 20, 350); } else { g.drawString("Magnification: Diminished", 20, 320); g.drawString("Orientation: Upright", 20, 335); g.drawString("Type: Virtual", 20, 350); } height_image /= 10; if (height_image > 9999 || height_image < -9999) Optics.lbl_heightImage.setText("<html>h<sub>i</sub>= N/A</html>"); else Optics.lbl_heightImage.setText("<html>h<sub>i</sub>= " + height_image + "</html>"); distance_image = x_pointOfIntersection - 350; distance_image /= 10; if (distance_image > 9999 || distance_image < -9999) Optics.lbl_distanceImage.setText("<html>d<sub>i</sub>= N/A</html>"); else Optics.lbl_distanceImage.setText("<html>d<sub>i</sub>= " + distance_image + "</html>"); } else // Else: mirrors { if (type == 0) // If converging { // draws converging mirror g.drawArc( 500 - 2 * radiusOfCurvature, 200 - radiusOfCurvature, 2 * radiusOfCurvature, 2 * radiusOfCurvature, 60, -120); // draws horizontal line from the tip of the arrow to the lens (line 1/4) g.setColor(Color.RED); x_arcIntersection_1 = (int) ((Math.sqrt(Math.abs(Math.pow(radiusOfCurvature, 2) - Math.pow(arrow_y2 - 200, 2)))) + (500 - radiusOfCurvature)); g.drawLine(arrow_x, arrow_y2, x_arcIntersection_1, arrow_y2); // line 2/4 dy_1 = arrow_y2 - 200; dx_1 = x_arcIntersection_1 - (500 - focalLength * 10); slope_1 = dy_1 / dx_1; y_intercept_1 = 200 - slope_1 * (500 - focalLength * 10); // Calculates coordinates of points on the edge of screen (endpoints) y_screenIntersection_1 = (int) (Math.round(y_intercept_1)); if (slope_1 != 0) if (arrow_y2 <= 200) x_screenIntersection_1 = (int) (Math.round((400 - y_intercept_1) / slope_1)); else x_screenIntersection_1 = (int) (Math.round(-y_intercept_1 / slope_1)); if (x_screenIntersection_1 >= 0 && x_screenIntersection_1 <= 700) // If endpoint is on the x-edge if (arrow_y2 <= 200) g.drawLine(x_arcIntersection_1, arrow_y2, x_screenIntersection_1, 400); else g.drawLine(x_arcIntersection_1, arrow_y2, x_screenIntersection_1, 0); else g.drawLine( x_arcIntersection_1, arrow_y2, 0, y_screenIntersection_1); // Else: endpoint is on the y-edge // line 3/4 if (!(arrow_x > 495 - focalLength * 10 && arrow_x < 505 - focalLength * 10)) { dy_2 = 200 - arrow_y2; dx_2 = (500 - 10 * focalLength) - arrow_x; slope_2 = dy_2 / dx_2; y_intercept_2 = arrow_y2 - slope_2 * arrow_x; quadratic_a = (float) (Math.pow(slope_2, 2) + 1); quadratic_b = (float) (((2 * slope_2 * y_intercept_2) - (400 * slope_2) + ((radiusOfCurvature - 500) * 2))); quadratic_c = (float) ((Math.pow(y_intercept_2, 2) - Math.pow(radiusOfCurvature, 2) - (400 * y_intercept_2) + 40000 + Math.pow((radiusOfCurvature - 500), 2))); discriminant = (float) (Math.pow(quadratic_b, 2) - (4 * quadratic_a * quadratic_c)); if (discriminant >= 0) x_arcIntersection_2 = (int) (Math.max( ((-quadratic_b + Math.sqrt(discriminant)) / (2 * quadratic_a)), ((-quadratic_b - Math.sqrt(discriminant)) / (2 * quadratic_a)))); else System.out.println("Error, imaginary root!"); y_arcIntersection_2 = (int) (slope_2 * x_arcIntersection_2 + y_intercept_2); g.drawLine(arrow_x, arrow_y2, x_arcIntersection_2, y_arcIntersection_2); // System.out.println ("slope: " + slope_2 + "\n yintercept: " + y_intercept_2 + "\n // quadratic-a: " + quadratic_a + "\n quadratic-b: " + quadratic_b + "\n quadratic_c: " + // quadratic_c + "\n discriminant: " + discriminant + "\n xarcintersection2: " + // x_arcIntersection_2 + "\n yarcintersection2: " + y_arcIntersection_2); // line 4/4 g.drawLine(x_arcIntersection_2, y_arcIntersection_2, 0, y_arcIntersection_2); // POI between line 2 and line 4 x_pointOfIntersection = (int) ((y_arcIntersection_2 - y_intercept_1) / slope_1); y_pointOfIntersection = y_arcIntersection_2; g.setColor(Color.ORANGE); g.drawLine(x_pointOfIntersection, y_pointOfIntersection, x_pointOfIntersection, 200); if (y_pointOfIntersection < 200) { g.drawLine( x_pointOfIntersection, y_pointOfIntersection, x_pointOfIntersection - 7, y_pointOfIntersection + 7); g.drawLine( x_pointOfIntersection, y_pointOfIntersection, x_pointOfIntersection + 7, y_pointOfIntersection + 7); } else { g.drawLine( x_pointOfIntersection, y_pointOfIntersection, x_pointOfIntersection - 7, y_pointOfIntersection - 7); g.drawLine( x_pointOfIntersection, y_pointOfIntersection, x_pointOfIntersection + 7, y_pointOfIntersection - 7); } // Same side image line continuation if (arrow_x > 500 - 10 * focalLength) { g.setColor(Color.YELLOW); g.drawLine(x_pointOfIntersection, y_pointOfIntersection, x_arcIntersection_1, arrow_y2); g.drawLine( x_pointOfIntersection, y_pointOfIntersection, x_arcIntersection_2, y_arcIntersection_2); } } } else // Diverging { // draws converging mirror g.drawArc( 350, 200 - radiusOfCurvature, 2 * radiusOfCurvature, 2 * radiusOfCurvature, 120, 120); // draws horizontal line from the tip of the arrow to the lens (line 1/4) g.setColor(Color.RED); x_arcIntersection_1 = (int) (-(Math.sqrt(Math.pow(radiusOfCurvature, 2) - Math.pow(arrow_y2 - 200, 2))) + (350 + radiusOfCurvature)); g.drawLine(arrow_x, arrow_y2, x_arcIntersection_1, arrow_y2); // line 2/4 dy_1 = arrow_y2 - 200; dx_1 = x_arcIntersection_1 - (350 + focalLength * 10); slope_1 = dy_1 / dx_1; y_intercept_1 = 200 - slope_1 * (350 + focalLength * 10); // Calculates coordinates of points on the edge of screen (endpoints) y_screenIntersection_1 = (int) (Math.round(y_intercept_1)); if (slope_1 != 0) if (arrow_y2 <= 200) x_screenIntersection_1 = (int) (Math.round(-y_intercept_1 / slope_1)); else if (arrow_y2 > 200) x_screenIntersection_1 = (int) (Math.round(400 - y_intercept_1 / slope_1)); if (x_screenIntersection_1 >= 0 && x_screenIntersection_1 <= 700) // If endpoint is on the x-edge if (arrow_y2 <= 200) g.drawLine(x_arcIntersection_1, arrow_y2, x_screenIntersection_1, 0); else g.drawLine(x_arcIntersection_1, arrow_y2, x_screenIntersection_1, 400); else g.drawLine( x_arcIntersection_1, arrow_y2, 0, y_screenIntersection_1); // Else: endpoint is on the y-edge // line 3/4 dy_2 = 200 - arrow_y2; dx_2 = (350 + 10 * focalLength) - arrow_x; slope_2 = dy_2 / dx_2; y_intercept_2 = arrow_y2 - slope_2 * arrow_x; quadratic_a = (float) (Math.pow(slope_2, 2) + 1); quadratic_b = (float) ((2 * slope_2 * y_intercept_2) - (400 * slope_2) - (2 * radiusOfCurvature + 700)); quadratic_c = (float) ((Math.pow(y_intercept_2, 2) - Math.pow(radiusOfCurvature, 2) - (400 * y_intercept_2) + 40000 + Math.pow((radiusOfCurvature + 350), 2))); discriminant = (float) (Math.pow(quadratic_b, 2) - (4 * quadratic_a * quadratic_c)); if (discriminant >= 0) x_arcIntersection_2 = (int) (Math.min( ((-quadratic_b + Math.sqrt(discriminant)) / (2 * quadratic_a)), ((-quadratic_b - Math.sqrt(discriminant)) / (2 * quadratic_a)))); else System.out.println("Error, imaginary root!"); y_arcIntersection_2 = (int) (slope_2 * x_arcIntersection_2 + y_intercept_2); g.drawLine(arrow_x, arrow_y2, x_arcIntersection_2, y_arcIntersection_2); // System.out.println ("slope: " + slope_2 + "\n yintercept: " + y_intercept_2 + "\n // quadratic-a: " + quadratic_a + "\n quadratic-b: " + quadratic_b + "\n quadratic_c: " + // quadratic_c + "\n discriminant: " + discriminant + "\n xarcintersection2: " + // x_arcIntersection_2 + "\n yarcintersection2: " + y_arcIntersection_2); // line 4/4 g.drawLine(x_arcIntersection_2, y_arcIntersection_2, 0, y_arcIntersection_2); // POI between line 2 and line 4 x_pointOfIntersection = (int) ((y_arcIntersection_2 - y_intercept_1) / slope_1); y_pointOfIntersection = y_arcIntersection_2; g.setColor(Color.ORANGE); g.drawLine(x_pointOfIntersection, y_pointOfIntersection, x_pointOfIntersection, 200); if (y_pointOfIntersection < 200) { g.drawLine( x_pointOfIntersection, y_pointOfIntersection, x_pointOfIntersection - 7, y_pointOfIntersection + 7); g.drawLine( x_pointOfIntersection, y_pointOfIntersection, x_pointOfIntersection + 7, y_pointOfIntersection + 7); } else { g.drawLine( x_pointOfIntersection, y_pointOfIntersection, x_pointOfIntersection - 7, y_pointOfIntersection - 7); g.drawLine( x_pointOfIntersection, y_pointOfIntersection, x_pointOfIntersection + 7, y_pointOfIntersection - 7); } // Same side image line continuation g.setColor(Color.YELLOW); g.drawLine(x_pointOfIntersection, y_pointOfIntersection, x_arcIntersection_1, arrow_y2); g.drawLine( x_pointOfIntersection, y_pointOfIntersection, x_arcIntersection_2, y_arcIntersection_2); } // Mag calculations height_image = 200 - y_pointOfIntersection; height_object = 200 - arrow_y2; if (height_object != 0) magnification = height_image / height_object; if (magnification <= 9999 && magnification >= -9999) Optics.txt_magnification.setText("" + roundTwoDecimals(magnification)); else if (magnification > 9999) { magnification = Double.POSITIVE_INFINITY; Optics.txt_magnification.setText("N/A"); } else { magnification = Double.NEGATIVE_INFINITY; Optics.txt_magnification.setText("N/A"); } // Characteristics g.setColor(Color.ORANGE); g.drawString("Image Characteristics:", 20, 300); if (type == 0) { if ((Math.abs(magnification) > 1 && Math.abs(magnification) < 9999) && arrow_x != 500 - 10 * focalLength) g.drawString("Magnification: Enlarged", 20, 320); else if ((int) (Math.abs(magnification)) == 1) g.drawString("Magnification: None", 20, 320); else if (Math.abs(magnification) < 1 && Math.abs(magnification) > 0) g.drawString("Magnification: Diminished", 20, 320); else { g.drawString("Magnification: N/A", 20, 320); Optics.txt_magnification.setText("N/A"); Optics.lbl_distanceImage.setText("<html>d<sub>i</sub>= N/A</html>"); Optics.lbl_heightImage.setText("<html>h<sub>i</sub>= N/A</html>"); } if (arrow_x == 500 - 10 * focalLength) g.drawString("Orientation: N/A", 20, 335); else if ((arrow_y2 < 200 && y_pointOfIntersection < 200) || (arrow_y2 > 200 && y_pointOfIntersection > 200)) g.drawString("Orientation: Upright", 20, 335); else g.drawString("Orientation: Inverted", 20, 335); if (arrow_x == 500 - 10 * focalLength) g.drawString("Type: N/A", 20, 350); else if (x_pointOfIntersection < 500 && arrow_x < 500) g.drawString("Type: Real", 20, 350); else if (x_pointOfIntersection > 500 && arrow_x < 500) g.drawString("Type: Virtual", 20, 350); } else { g.drawString("Magnification: Diminished", 20, 320); g.drawString("Orientation: Upright", 20, 335); g.drawString("Type: Virtual", 20, 350); } height_image /= 10; if (height_image > 9999 || height_image < -9999 || arrow_x == 500 - 10 * focalLength) Optics.lbl_heightImage.setText("<html>h<sub>i</sub>= N/A</html>"); else Optics.lbl_heightImage.setText("<html>h<sub>i</sub>= " + height_image + "</html>"); if (type == 0) distance_image = x_pointOfIntersection - 500; else distance_image = x_pointOfIntersection - 350; distance_image /= 10; if (distance_image > 9999 || distance_image < -9999 || arrow_x == 500 - 10 * focalLength) Optics.lbl_distanceImage.setText("<html>d<sub>i</sub>= N/A</html>"); else Optics.lbl_distanceImage.setText("<html>d<sub>i</sub>= " + distance_image + "</html>"); } }
public void paintHighlight(Graphics g, int x, int y) { g.setColor(Color.black); g.drawArc(x, y, pixel_size, pixel_size, 0, 360); // g.drawImage(imgLoader.getSprite(ImageLoader.SpriteName.HIGHLIGHT.ordinal()), x, y, null); }
/** * _more_ * * @param graphics */ public void drawNext(Graphics graphics) { Rectangle r = getBounds(); graphics.drawArc(r.x, r.y, r.width, r.height, startAngle, endAngle); }
public void onDraw(Graphics g, int viewX, int viewY) { if ((status & World.ST_INVISIBLE) != 0) { return; } int offs = x % 8; if (!done) { // x+=move; g.drawArc(((x - 2) - viewX) * 3, ((y - 10) - viewY) * 3, 4, 4, 0, 360); g.drawLine( ((x) - viewX) * 3, ((y - 6) - viewY) * 3, ((x) - viewX) * 3, ((y - 3) - viewY) * 3); g.drawLine( ((x - 2) - viewX) * 3, ((y - 4) - viewY) * 3, ((x + 2) - viewX) * 3, ((y - 4) - viewY) * 3); g.drawLine( ((x) - viewX) * 3, ((y - 3) - viewY) * 3, ((x + offs - 2) - viewX) * 3, ((y) - viewY) * 3); g.drawLine( ((x) - viewX) * 3, ((y - 3) - viewY) * 3, ((x + 2 - offs) - viewX) * 3, ((y) - viewY) * 3); } else { int yUp = 20; if (Integer.signum(move) == -1) { left = -1; } if (Integer.signum(move) == 1) { left = 1; } Graphics2D g2 = (Graphics2D) g; g2.scale(left, 1); g2.drawImage( bodyParts[0], (x - viewX) * 3 * left + (left < 0 ? -18 : 0), (y - yUp - 6 - viewY) * 3, null); g2.drawImage( bodyParts[1], (int) (x + 2 - ((bodyParts[1].getWidth(null) - 23) / 5) - viewX) * 3 * left + (left < 0 ? -(6 + (bodyParts[1].getWidth(null) - 23)) : 0), ((y - yUp - 16 - ((bodyParts[1].getHeight(null) - 31)) / 3) - viewY) * 3, null); double ffs = Math.toRadians(((4 - offs) * 6)); AffineTransform previousAT = g2.getTransform(); g2.translate((x - 3 - viewX) * 3 * left, ((y - yUp - 6) - viewY) * 3); g2.rotate(Math.toRadians(leftArmAngle - 90), 4 * (left + 1), 2); g2.drawImage(bodyParts[2], 0, 0, null); g2.setTransform(previousAT); g2.translate( (((x - 3 - viewX) + lengthdir_x(6 * left, leftArmAngle * left))) * left * 3, (((y - yUp - 6) - this.lengthdir_y(6 * left, leftArmAngle * left)) - viewY) * 3); g2.rotate(Math.toRadians(leftArmAngle - 90), 4 * (left + 1), 2); g2.drawImage(bodyParts[3], 0, 0, null); g2.setTransform(previousAT); g2.translate((x + 9 - viewX) * 3 * left, ((y - yUp - 6) - viewY) * 3); g2.rotate(Math.toRadians(rightArmAngle - 90), 8 - left * 4, 4); g2.drawImage(bodyParts[2], 0, 0, null); g2.setTransform(previousAT); g2.translate( (((x + 9 - viewX) + this.lengthdir_x(6 * left, rightArmAngle * left)) * 3) * left, (((y - yUp - 6) - this.lengthdir_y(6 * left, rightArmAngle * left)) - viewY) * 3); g2.rotate(Math.toRadians(rightArmAngle - 90), 8 - left * 4, 4); g2.drawImage(bodyParts[3], 0, 0, null); g2.setTransform(previousAT); g2.drawImage(bodyParts[4], (x + 1 - viewX) * 3 * left, ((y - yUp + 7) - viewY) * 3, null); g2.drawImage(bodyParts[4], (x + 5 - viewX) * 3 * left, ((y - yUp + 7) - viewY) * 3, null); g2.translate((x + 5 - viewX) * 3 * left, ((y + 13) - viewY - yUp) * 3); g2.rotate(ffs); g2.drawImage(bodyParts[5], 0, 0, null); g2.setTransform(previousAT); g2.translate((x + 1 - viewX) * 3 * left, ((y + 13) - viewY - yUp) * 3); g2.rotate(-ffs); g2.drawImage(bodyParts[5], 0, 0, null); g2.setTransform(previousAT); g2.scale(left, 1); } g.setColor(myTeam ? Color.GREEN : Color.MAGENTA); g.drawString(username, ((x - (username.length())) - viewX) * 3, (y - 40 - viewY) * 3); }
public void draw(Graphics graphics) { // tilted eye // Graphics2D g2d = (Graphics2D) graphics; // g2d.rotate(Math.toRadians(45)); // g2d.fillOval(x + 150, y - 200, width / 2, height / 2); // g2d.rotate(Math.toRadians(-45)); // // graphics.setColor(Color.BLACK); // graphics.fillOval(x + (width * 10 / 100), y + (height * 20 / 100), width / 2, height / 2); // int[] xS = new int[3]; // xS[0] = x + (width / 2); // xS[1] = x; // xS[2] = x + width; // // int[] yS = new int[3]; // yS[0] = y; // yS[1] = y + (height * 2 / 3); // yS[2] = y + (height); // // graphics.fillPolygon(xS, yS, 3); graphics.setColor(Color.BLACK); graphics.drawRect(x, y, width, height); // fluffy bits graphics.setColor(SHADOW); graphics.fillOval(x, y + (height * 55 / 100), width * 10 / 100, height * 10 / 100); graphics.fillOval( x + (width * 5 / 100), y + (height * 58 / 100), width * 15 / 100, height * 15 / 100); graphics.fillOval( x + (width * 8 / 100), y + (height * 55 / 100), width * 15 / 100, height * 15 / 100); graphics.fillOval( x + (width * 13 / 100), y + (height * 56 / 100), width * 20 / 100, height * 20 / 100); // graphics.fillOval graphics.setColor(CREAM); graphics.fillOval(x, y + (height * 40 / 100), width * 20 / 100, height * 20 / 100); graphics.fillOval( x + (width * 10 / 100), y + (height * 30 / 100), width * 20 / 100, height * 20 / 100); graphics.fillOval( x + (width * 20 / 100), y + (height * 25 / 100), width * 20 / 100, height * 20 / 100); graphics.fillOval( x + (width * 15 / 100), y + (height * 40 / 100), width * 20 / 100, height * 20 / 100); // outlines - shadow graphics.setColor(Color.BLACK); graphics.drawArc(x, y + (height * 55 / 100), width * 10 / 100, height * 10 / 100, 130, 140); graphics.drawArc( x + (width * 5 / 100), y + (height * 58 / 100), width * 15 / 100, height * 15 / 100, 160, 130); graphics.drawArc( x + (width * 13 / 100), y + (height * 56 / 100), width * 20 / 100, height * 20 / 100, 160, 160); graphics.drawArc( x + (width * 110 / 1000), y + (height * 62 / 100), width * 5 / 100, height * 5 / 100, 150, 105); // outlines - cream graphics.setColor(Color.BLACK); graphics.drawArc(x, y + (height * 40 / 100), width * 20 / 100, height * 20 / 100, 90, 150); graphics.drawArc( x + (width * 10 / 100), y + (height * 30 / 100), width * 20 / 100, height * 20 / 100, 83, 110); graphics.drawArc( x + (width * 20 / 100), y + (height * 25 / 100), width * 20 / 100, height * 20 / 100, 90, 110); // face graphics.drawArc( x + (width * 41 / 100), y + (height * 17 / 100), width * 28 / 100, height * 30 / 100, 137, 110); graphics.drawArc( x + (width * 30 / 100), y + (height * 98 / 1000), width * 40 / 100, height * 36 / 100, 269, 80); // eyes graphics.setColor(Color.black); graphics.fillOval( x + (width * 55 / 100), y + (height * 29 / 100), (width * 5 / 100), (height * 5 / 100)); graphics.fillOval( x + (width * 40 / 100), y + (height * 28 / 100), (width * 3 / 100), (height * 5 / 100)); graphics.setColor(Color.white); graphics.fillOval( x + (width * 558 / 1000), y + (height * 297 / 1000), (width * 26 / 1000), (height * 26 / 1000)); graphics.fillOval( x + (width * 405 / 1000), y + (height * 283 / 1000), (width * 2 / 100), (height * 2 / 100)); // tail graphics.setColor(tailOrange); graphics.fillOval( x + (width * 10 / 100), y + (height * 4 / 100), (width * 10 / 100), (height * 10 / 100)); graphics.setColor(Color.black); graphics.drawOval( x + (width * 10 / 100), y + (height * 4 / 100), (width * 10 / 100), (height * 10 / 100)); graphics.setColor(new Color(0, 0, 0, 50)); graphics.fillOval( x + (width * 115 / 1000), y + (height * 64 / 1000), (width * 7 / 100), (height * 7 / 100)); graphics.setColor(Color.WHITE); graphics.fillOval( x + (width * 125 / 1000), y + (height * 46 / 1000), (width * 31 / 1000), (height * 31 / 1000)); graphics.fillOval( x + (width * 107 / 1000), y + (height * 83 / 1000), (width * 17 / 1000), (height * 17 / 1000)); }
/** * 形成柱状图 并生成图片 此方法是生成不同时间段 不同客户的消费统计图片 * * @param money */ public void graphicsGeneration1( String imageName, double[][] money, String[] time, String[] vipLevels, String x) { // 对值进行截取前两位 NumberFormat doubleFormat = new DecimalFormat("0.00 "); String[][] moneyChange = new String[time.length][vipLevels.length]; for (int i = 0; i < money.length; i++) { for (int j = 0; j < money[i].length; j++) { moneyChange[i][j] = doubleFormat.format(money[i][j]); } } ChartGraphics chartGraphics = new ChartGraphics(); int[][] height = chartGraphics.changeValueTwo(money, vipLevels); final int X = 10; int imageWidth; if (money.length < 5) { imageWidth = 700; } else if (money.length >= 5 && money.length <= 9) { imageWidth = money.length * 150; // 图片的宽度 } else { imageWidth = money.length * 150; } int imageHeight = 400; // 图片的高度 int columnWidth = 30; // 柱的宽度 int columnHeight = 350; // 柱的最大高度 + 10 int columnSpace = 20; // 柱子之间的间隔 chartGraphics.image = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_RGB); Graphics graphics = chartGraphics.image.createGraphics(); // 返回一个与该图像相关的 // Graphics2D // 对象 graphics.setColor(Color.white); // 背景色 graphics.fillRect(0, 0, imageWidth, imageHeight); // 画坐标轴 graphics.setColor(Color.BLUE); graphics.drawLine(25, imageHeight - 40, 25, 20); // y 坐标 graphics.drawArc(0, 0, 2, 2, 2, 2); graphics.drawString("统 ", 5, 35); graphics.drawString("计 ", 5, 50); graphics.drawString("值 ", 5, 65); graphics.drawLine(25, imageHeight - 40, imageWidth - 15, imageHeight - 40); // x 坐标 graphics.drawString(x, imageWidth - 45, imageHeight - 25); List<Color> colors = new ArrayList<Color>(); colors.add(Color.red); colors.add(Color.blue); colors.add(Color.lightGray); colors.add(Color.GREEN); for (int i = 0; i < height.length; i++) { if (i == 0) { for (int j = 0; j < height[i].length; j++) { graphics.setColor(Color.BLUE); graphics.drawString( moneyChange[i][j] + "", 40 + j * columnWidth, columnHeight - height[i][j] - 4); graphics.setColor(colors.get(j)); graphics.drawRect( 40 + j * columnWidth, (imageHeight - 40) - height[i][j] - 1, columnWidth, height[i][j]); graphics.fillRect( 40 + j * columnWidth, (imageHeight - 40) - height[i][j] - 1, columnWidth, height[i][j]); } graphics.setColor(Color.BLUE); graphics.drawString(time[i], 40, imageHeight - 25); } for (int j = 0; j < height[i].length; j++) { graphics.setColor(Color.BLUE); graphics.drawString( moneyChange[i][j] + "", i * (columnWidth * 4 + columnSpace) + 40 + j * columnWidth, columnHeight - height[i][j] - 4); graphics.setColor(colors.get(j)); // 柱子颜色 graphics.drawRect( i * (columnWidth * 4 + columnSpace) + 40 + j * columnWidth, (imageHeight - 40) - height[i][j] - 1, columnWidth, height[i][j]); graphics.fillRect( i * (columnWidth * 4 + columnSpace) + 40 + j * columnWidth, (imageHeight - 40) - height[i][j] - 1, columnWidth, height[i][j]); } graphics.setColor(Color.BLUE); graphics.drawString(time[i], i * (columnWidth * 4 + columnSpace) + 40, imageHeight - 25); } chartGraphics.createImage(imageName); // chart.jpg应包含生成的jpg文件的路径 }
/** * 形成柱状图 并生成图片 * * @param money */ public void graphicsGeneration(String imageName, double[] money, String[] time, String x) { // 对值进行截取前两位 NumberFormat doubleFormat = new DecimalFormat("0.00 "); String[] moneyChange = new String[money.length]; for (int i = 0; i < money.length; i++) { moneyChange[i] = doubleFormat.format(money[i]); } ChartGraphics chartGraphics = new ChartGraphics(); int[] height = chartGraphics.changeValue(money); final int X = 10; int imageWidth; if (money.length < 5) { imageWidth = 350; } else if (money.length >= 5 && money.length <= 9) { imageWidth = money.length * 80; // 图片的宽度 } else { imageWidth = money.length * 70; } int imageHeight = 400; // 图片的高度 int columnWidth = 40; // 柱的宽度 int columnHeight = 350; // 柱的最大高度 + 10 int columnSpace = 20; // 柱子之间的间隔 chartGraphics.image = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_RGB); Graphics graphics = chartGraphics.image.createGraphics(); // 返回一个与该图像相关的 // Graphics2D // 对象 graphics.setColor(Color.white); // 背景色 graphics.fillRect(0, 0, imageWidth, imageHeight); // 画坐标轴 graphics.setColor(Color.BLUE); graphics.drawLine(25, imageHeight - 40, 25, 20); // y 坐标 graphics.drawArc(0, 0, 2, 2, 2, 2); graphics.drawString("统 ", 5, 35); graphics.drawString("计 ", 5, 50); graphics.drawString("值 ", 5, 65); graphics.drawLine(25, imageHeight - 40, imageWidth - 15, imageHeight - 40); // x 坐标 graphics.drawString(x, imageWidth - 45, imageHeight - 25); for (int i = 0; i < height.length; i++) { if (i == 0) { // 第一根柱子 // 柱子顶部显示 统计值 graphics.setColor(Color.BLUE); graphics.drawString(moneyChange[i] + "", 40, columnHeight - height[i] - 4); graphics.setColor(Color.red); graphics.drawRect(40, (imageHeight - 40) - height[i] - 1, columnWidth, height[i]); graphics.fillRect(40, (imageHeight - 40) - height[i] - 1, columnWidth, height[i]); graphics.setColor(Color.BLUE); graphics.drawString(time[i], 40, imageHeight - 25); } // graphics.drawRect(arg0, arg1, arg2, arg3); // arg0 :柱子最左顶点 x坐标 // arg1 :柱子最左顶点 y坐标 // 柱顶 = x坐标的‘y’值((imageHeight-40)) - 柱子高度(height[i]) // 柱子顶部显示 统计值 graphics.setColor(Color.BLUE); graphics.drawString( moneyChange[i] + "", i * (columnWidth + columnSpace) + 40, columnHeight - height[i] - 4); graphics.setColor(Color.red); // 柱子颜色 graphics.drawRect( i * (columnWidth + columnSpace) + 40, (imageHeight - 40) - height[i] - 1, columnWidth, height[i]); graphics.fillRect( i * (columnWidth + columnSpace) + 40, (imageHeight - 40) - height[i] - 1, columnWidth, height[i]); graphics.setColor(Color.BLUE); graphics.drawString(time[i], i * (columnWidth + columnSpace) + 40, imageHeight - 25); } chartGraphics.createImage(imageName); // chart.jpg应包含生成的jpg文件的路径 }