public void paint(Graphics g) { super.paint(g); Graphics2D g2D = (Graphics2D) g; int x = this.getWidth(); int y = this.getHeight(); int z = 4; if (orientation.equals(DesktopBar.WEST)) { int[] X = {x - z, x - z, 2 * x / 5, x / 2, z, x / 2, 2 * x / 5}; int[] Y = {2 * y / 5, 3 * y / 5, 3 * y / 5, y - z, y / 2, z, 2 * y / 5}; g2D.draw(new Polygon(X, Y, 7)); } if (orientation.equals(DesktopBar.EAST)) { int[] X = {z, z, 2 * x / 3, x / 2, x - z, x / 2, 2 * x / 3}; int[] Y = {2 * y / 5, 3 * y / 5, 3 * y / 5, y - z, y / 2, z, 2 * y / 5}; g2D.draw(new Polygon(X, Y, 7)); } if (orientation.equals(DesktopBar.NORTH)) { int[] X = {2 * x / 5, 3 * x / 5, 3 * x / 5, x - z, x / 2, z, 2 * x / 5}; int[] Y = {y - z, y - z, 2 * y / 5, y / 2, z, y / 2, 2 * y / 5}; g2D.draw(new Polygon(X, Y, 7)); } if (orientation.equals(DesktopBar.SOUTH)) { int[] X = {2 * x / 5, 3 * x / 5, 3 * x / 5, x - z, x / 2, z, 2 * x / 5}; int[] Y = {z, z, 2 * y / 3, y / 2, y - z, y / 2, 2 * y / 3}; g2D.draw(new Polygon(X, Y, 7)); } }
/** * Render the View to the given graphic context. This implementation render the interior first, * then the outline. */ public void paint(Graphics2D g, Rectangle2D a) { if (!a.intersects(getBounds())) return; if (image != null) { // paint bitmap g.drawImage(image, text2ModelTr, null); // debug: g.setPaint(Color.red); g.draw(this.bounds); super.paint(g, a); // possibly paint framebox if non-null } else { // paint textlayout super.paint(g, a); // possibly paint framebox if non-null AffineTransform oldAT = g.getTransform(); // paint text in black g.setPaint(Color.black); // from now on, we work in Y-direct (<0) coordinates to avoid inextricable problems with font // being mirrored... g.transform(text2ModelTr); // also include rotation textLayout.draw(g, 0.0f, 0.0f); // [pending] ajouter un cadre si areDimensionsComputed (wysiwyg du pauvre) // get back to previous transform g.setTransform(oldAT); if (DEBUG) { g.setPaint(Color.red); g.draw(bounds); } } }
public void paint(Graphics g) { super.paint(g); Graphics2D g2 = (Graphics2D) g; int size = Math.min( MAX_SIZE, Math.min( getWidth() - imagePadding.left - imagePadding.right, getHeight() - imagePadding.top - imagePadding.bottom)); g2.translate(getWidth() / 2 - size / 2, getHeight() / 2 - size / 2); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Shape shape; if (mode == ColorPicker.SAT || mode == ColorPicker.BRI) { shape = new Ellipse2D.Float(0, 0, size, size); } else { Rectangle r = new Rectangle(0, 0, size, size); shape = r; } if (hasFocus()) { PaintUtils.paintFocus(g2, shape, 5); } if (!(shape instanceof Rectangle)) { // paint a circular shadow g2.translate(2, 2); g2.setColor(new Color(0, 0, 0, 20)); g2.fill(new Ellipse2D.Float(-2, -2, size + 4, size + 4)); g2.setColor(new Color(0, 0, 0, 40)); g2.fill(new Ellipse2D.Float(-1, -1, size + 2, size + 2)); g2.setColor(new Color(0, 0, 0, 80)); g2.fill(new Ellipse2D.Float(0, 0, size, size)); g2.translate(-2, -2); } g2.drawImage(image, 0, 0, size, size, 0, 0, size, size, null); if (shape instanceof Rectangle) { Rectangle r = (Rectangle) shape; PaintUtils.drawBevel(g2, r); } else { g2.setColor(new Color(0, 0, 0, 120)); g2.draw(shape); } g2.setColor(Color.white); g2.setStroke(new BasicStroke(1)); g2.draw(new Ellipse2D.Float(point.x - 3, point.y - 3, 6, 6)); g2.setColor(Color.black); g2.draw(new Ellipse2D.Float(point.x - 4, point.y - 4, 8, 8)); g.translate(-imagePadding.left, -imagePadding.top); }
public void paint(Graphics g) { System.out.println("paint"); Graphics2D g2d = (Graphics2D) g; Point1 p1, p2; n = paintInfo.size(); if (toolFlag == 2) g2d.clearRect(0, 0, getSize().width - 100, getSize().height - 100); // 清除 for (int i = 0; i < n - 1; i++) { p1 = (Point1) paintInfo.elementAt(i); p2 = (Point1) paintInfo.elementAt(i + 1); size = new BasicStroke(p1.boarder, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL); g2d.setColor(p1.col); g2d.setStroke(size); if (p1.tool == p2.tool) { switch (p1.tool) { case 0: // 画笔 Line2D line1 = new Line2D.Double(p1.x, p1.y, p2.x, p2.y); g2d.draw(line1); break; case 1: // 橡皮 g.clearRect(p1.x, p1.y, p1.boarder, p1.boarder); break; case 3: // 画直线 Line2D line2 = new Line2D.Double(p1.x, p1.y, p2.x, p2.y); g2d.draw(line2); break; case 4: // 画圆 Ellipse2D ellipse = new Ellipse2D.Double(p1.x, p1.y, Math.abs(p2.x - p1.x), Math.abs(p2.y - p1.y)); g2d.draw(ellipse); break; case 5: // 画矩形 Rectangle2D rect = new Rectangle2D.Double(p1.x, p1.y, Math.abs(p2.x - p1.x), Math.abs(p2.y - p1.y)); g2d.draw(rect); break; case 6: // 截断,跳过 i = i + 1; break; default: } // end switch } // end if } // end for }
/** Draws the game */ @Override protected void paintComponent(Graphics g) { super.paintComponent(g); final Graphics2D g2 = (Graphics2D) g; /** Draw all the non-falling blocks on the board. Non-OUTSIDE blocks have rounded corners. */ for (int row = 0; row < board.getHeight(); row++) { for (int column = 0; column < board.getWidth(); column++) { if (board.getSquareType(row, column) != SquareType.OUTSIDE) { Shape tetrominoBlock = new RoundRectangle2D.Double( column * SQUARE_WIDTH, row * SQUARE_HEIGHT, SQUARE_WIDTH, SQUARE_HEIGHT, 5, 5); g2.setColor(SQUARE_COLOR.get(board.getSquareType(row, column))); g2.fill(tetrominoBlock); g2.draw(tetrominoBlock); } else { Shape tetrominoBlock = new Rectangle2D.Double( column * SQUARE_WIDTH, row * SQUARE_HEIGHT, SQUARE_WIDTH, SQUARE_HEIGHT); g2.setColor(SQUARE_COLOR.get(board.getSquareType(row, column))); g2.fill(tetrominoBlock); g2.draw(tetrominoBlock); } } } Poly tempPoly = board.getFalling(); if (tempPoly != null) { for (int row = 0; row < tempPoly.getSize(); row++) { for (int column = 0; column < tempPoly.getSize(); column++) { if (tempPoly.getSquareType(row, column) != SquareType.EMPTY) { Shape tetrominoBlock = new RoundRectangle2D.Double( (column + board.getFallingPosX()) * SQUARE_WIDTH, (row + board.getFallingPosY()) * SQUARE_HEIGHT, SQUARE_WIDTH, SQUARE_HEIGHT, 5, 5); g2.setColor(SQUARE_COLOR.get(tempPoly.getSquareType(row, column))); g2.fill(tetrominoBlock); g2.draw(tetrominoBlock); } } } } }
@Override protected void drawStroke(Graphics2D g) { if (isClosed()) { double grow = AttributeKeys.getPerpendicularDrawGrowth(this); if (grow == 0d) { g.draw(path); } else { GrowStroke gs = new GrowStroke(grow, AttributeKeys.getStrokeTotalWidth(this) * get(STROKE_MITER_LIMIT)); g.draw(gs.createStrokedShape(path)); } } else { g.draw(getCappedPath()); } drawCaps(g); }
/** Draws the edge structure of the tree */ public void drawEdges(Graphics2D gg) { gg.setPaint(Color.black); Enumeration nodeList = argument.getBreadthFirstTraversal().elements(); // For each vertex... while (nodeList.hasMoreElements()) { // Get its edge list... TreeVertex vertex = (TreeVertex) nodeList.nextElement(); Enumeration edges = vertex.getEdgeList().elements(); // For each edge in the list... while (edges.hasMoreElements()) { TreeEdge edge = (TreeEdge) edges.nextElement(); // If we have several vertices on layer 0, only draw // edges for layers below that if (!(argument.isMultiRoots() && vertex.getLayer() == 0)) { // If the edge has been selected with the mouse, // use a thick line if (edge.isSelected()) { gg.setStroke(selectStroke); } gg.draw(edge.getShape(this)); // If we used a thick line, reset the stroke to normal // line for next edge. if (edge.isSelected()) { gg.setStroke(solidStroke); } TreeVertex edgeSource = edge.getDestVertex(); } } } }
// draws the tree, starting from the given node, in the region with x values // ranging // from minX to maxX, with y value beginning at y, and next level at y + // yIncr. private void drawTree(Graphics2D g2, TreeNode<E> t, int minX, int maxX, int y, int yIncr) { // skip if empty if (t == null) return; // compute useful coordinates int x = (minX + maxX) / 2; int nextY = y + yIncr; // draw black lines g2.setPaint(Color.black); if (t.left != null) { int nextX = (minX + x) / 2; g2.draw(new Line2D.Double(x, y, nextX, nextY)); } if (t.right != null) { int nextX = (x + maxX) / 2; g2.draw(new Line2D.Double(x, y, nextX, nextY)); } // measure text FontMetrics font = g2.getFontMetrics(); String text = t.data + ""; int textHeight = font.getHeight(); int textWidth = font.stringWidth(text); // draw the box around the node Rectangle2D.Double box = new Rectangle2D.Double( x - textWidth / 2 - ARC_PAD, y - textHeight / 2 - ARC_PAD, textWidth + 2 * ARC_PAD, textHeight + 2 * ARC_PAD); Color c = new Color(187, 224, 227); g2.setPaint(c); g2.fill(box); // draw black border g2.setPaint(Color.black); g2.draw(box); // draw text g2.drawString(text, x - textWidth / 2, y + textHeight / 2); // draw children drawTree(g2, t.left, minX, x, nextY, yIncr); drawTree(g2, t.right, x, maxX, nextY, yIncr); }
public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; Rectangle2D rect = new Rectangle2D.Double(0, 0, getWidth() - 1, getHeight() - 1); g2.setPaint(Color.YELLOW); g2.fill(rect); g2.setPaint(Color.BLUE); g2.draw(rect); }
private void drawArrow(Graphics2D g, double fx, double fy, double tx, double ty) { double d = Point2D.distance(fx, fy, tx, ty); if (d == 0) return; double t = arrow_size / d; double cx0 = tx + 2 * t * (fx - tx); double cy0 = ty + 2 * t * (fy - ty); double cx1 = cx0 + t * (fy - ty); double cy1 = cy0 - t * (fx - tx); double cx2 = cx0 - t * (fy - ty); double cy2 = cy0 + t * (fx - tx); g.setStroke(arrow_stroke); Line2D.Double l2 = new Line2D.Double(cx1, cy1, tx, ty); g.draw(l2); l2.setLine(cx2, cy2, tx, ty); g.draw(l2); }
/** * method to draw the tail of the balloon * * @param ellipseHeight the height of the ellipse * @param fillColor the color to bill the balloon with * @param outlineColor the color to outline the balloon with * @param g2 the 2d graphics context */ protected void drawTail(int ellipseHeight, Color fillColor, Color outlineColor, Graphics2D g2) { Point tailEnd = getTailEnd(); Point upperLeft = getUpperLeft(); int margin = getMargin(); int halfWidth = getWidth() / 2; int topY = upperLeft.y + ellipseHeight; int startX = upperLeft.x + halfWidth - margin; int endX = upperLeft.x + halfWidth + margin; GeneralPath triangle = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 3); triangle.moveTo(startX, topY); triangle.lineTo(endX, topY); triangle.lineTo(tailEnd.x, tailEnd.y); triangle.lineTo(startX, topY); g2.setColor(fillColor); g2.fill(triangle); g2.setColor(outlineColor); g2.draw(new Line2D.Double(tailEnd.x, tailEnd.y, startX, topY)); g2.draw(new Line2D.Double(tailEnd.x, tailEnd.y, endX, topY)); }
/** * Draws the edge. * * @param graphics the graphics context */ public void draw(Graphics2D graphics) { updateContactPoints(); Color oldColor = graphics.getColor(); Stroke oldStroke = graphics.getStroke(); graphics.setColor(getBorderColor()); graphics.setStroke(getLineStyle()); graphics.draw(getPath()); graphics.setStroke(oldStroke); graphics.setColor(oldColor); }
public synchronized void paintComponent(Graphics g) // Called on the event dispatch thread { if (values == null) return; Graphics2D g2 = (Graphics2D) g; int width = getWidth() / values.length; for (int i = 0; i < values.length; i++) { double height = values[i] * getHeight(); Rectangle2D bar = new Rectangle2D.Double(width * i, 0, width, height); if (values[i] == marked1 || values[i] == marked2) g2.fill(bar); else g2.draw(bar); } }
public void draw(Graphics2D g) { g.setColor(fillColor); g.fill(gp); g.setColor(Color.black); g.draw(gp); for (int i = 0; i < points.size(); i++) { GlyphPoint p = points.get(i); g.setColor(Color.red); g.draw(p.gp); g.setColor(Color.blue); g.setFont(gfont); g.drawString(String.valueOf(i), p.x + 3, p.y + 3); } g.setColor(Color.black); // System.out.println("Advance: "+advance); g.draw(advp); if (name != null) { g.setFont(gfont); g.drawString(name, 0, -40); } }
public void alpaCut(Graphics g, double alfa, int val) { Graphics2D g2d = (Graphics2D) g; double Xawal = X_AXIS_FIRST_X_COORD; double Yawal = Y_AXIS_SECOND_Y_COORD; Point2D.Double point = new Point2D.Double(Xawal, Yawal); int xLength = (X_AXIS_SECOND_X_COORD - X_AXIS_FIRST_X_COORD) / xCoordNumbers; int yLength = (Y_AXIS_SECOND_Y_COORD - Y_AXIS_FIRST_Y_COORD) / yCoordNumbers; // g2d.setStroke(new BasicStroke(3)); Stroke dashed = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] {9}, 0); g2d.setStroke(dashed); g2d.setColor(Color.black); g2d.draw( new Line2D.Double( X_AXIS_FIRST_X_COORD, Y_AXIS_SECOND_Y_COORD - ((alfa * 10) * yLength), X_AXIS_FIRST_X_COORD + (xCoordNumbers * xLength) - 3, Y_AXIS_SECOND_Y_COORD - ((alfa * 10) * yLength))); // double BA, BB; double BB, BA; BB = sig[val] * 2 - (sig[val] + (std[val] * Math.sqrt(Math.log(1 / alfa)))); BA = sig[val] + (std[val] * Math.sqrt(Math.log(1 / alfa))); // System.out.println(BB+"\n"+BA); System.out.println("Batas Atas Gambar " + (val + 1) + " = " + BA); System.out.println("Batas Bawah Gambar " + (val + 1) + " = " + BB); g2d.draw( new Line2D.Double( X_AXIS_FIRST_X_COORD + (BA * xLength) - 3, Y_AXIS_SECOND_Y_COORD, X_AXIS_FIRST_X_COORD + (BA * xLength) - 3, Y_AXIS_SECOND_Y_COORD - ((alfa * 10) * yLength))); g2d.draw( new Line2D.Double( X_AXIS_FIRST_X_COORD + (BB * xLength) - 3, Y_AXIS_SECOND_Y_COORD, X_AXIS_FIRST_X_COORD + (BB * xLength) - 3, Y_AXIS_SECOND_Y_COORD - ((alfa * 10) * yLength))); }
void draw(Graphics2D g) { // toX/toY is tip of arrow and fx/fy is a point on the line - // fx/fy is used to determine direction & angle AffineTransform at = AffineTransform.getTranslateInstance(toX, toY); int b = 9; double theta = Math.toRadians(20); // The idea of using a GeneralPath is so we can // create the (three lines that make up the) arrow // (only) one time and then use AffineTransform to // place it anywhere we want. GeneralPath path = new GeneralPath(); // distance between line and the arrow mark <** not ** // Start a new line segment from the position of (0,0). path.moveTo(0, 0); // Create one of the two arrow head lines. int x = (int) (-b * Math.cos(theta)); int y = (int) (b * Math.sin(theta)); path.lineTo(x, y); // distance between line and the arrow mark <** not ** // Make the other arrow head line. int x2 = (int) (-b * Math.cos(-theta)); int y2 = (int) (b * Math.sin(-theta)); // path.moveTo(0,0); path.lineTo(x2, y2); path.closePath(); // theta is in radians double s, t; s = toY - fy; // calculate slopes. t = toX - fx; if (t != 0) { s = s / t; theta = Math.atan(s); if (t < 0) theta += Math.PI; } else if (s < 0) theta = -(Math.PI / 2); else theta = Math.PI / 2; at.rotate(theta); // at.rotate(theta,toX,toY); Shape shape = at.createTransformedShape(path); if (checkStatus == Status.UNCHECKED) g.setColor(Color.BLACK); else if (checkStatus == Status.COMPATIBLE) g.setColor(FOREST_GREEN); else g.setColor(ORANGE_RED); g.fill(shape); g.draw(shape); }
void renderer(Graphics2D g2d) { height = window.getHeight() - 20; width = window.getWidth(); lastTime = curTime; curTime = System.currentTimeMillis(); totalTime += curTime - lastTime; if (totalTime > 1000) { totalTime -= 1000; fps = frames; frames = 0; } ++frames; delta = 16.0 / (curTime - lastTime); if (delta < 0) delta = 0; g2d.setColor(Color.white); if (removeMode) g2d.fill(new Rectangle(0, 0, width, height)); if (eventHandeler(g2d)) { renderBackground(g2d); return; } Graphics2D map = (Graphics2D) g2d.create(); playerHandeler(); xOffset = -player.body.getCenterX() + width / 2; yOffset = -player.body.getCenterY() + height / 2; if (-xOffset < bounds.getBounds2D().getX()) xOffset = -bounds.getBounds2D().getX(); else if (-xOffset > bounds.getBounds2D().getMaxX() - width) xOffset = -bounds.getBounds2D().getMaxX() + width; if (-yOffset < bounds.getBounds2D().getY()) yOffset = -bounds.getBounds2D().getY(); else if (-yOffset > bounds.getBounds2D().getMaxY() - height + 3) yOffset = -bounds.getBounds2D().getMaxY() + height - 3; map.translate(xOffset, yOffset); renderBackground(map); itemHandeler(map); enemieHandeler(); characterHandeler(map); map.setColor(Color.black); map.draw(bounds); renderUI(g2d); }
private void drawObject(Graphics2D g, int idx, GraphObject go) { double x0 = left_right_margin + (object_width + object_hspacing) * idx; Rectangle2D r = new Rectangle2D.Double(x0, top_bottom_margin, object_width, object_height); graph_locations.put(go, x0 + object_width / 2); g.setColor(Color.WHITE); g.fill(r); g.setColor(Color.BLACK); g.draw(r); g.setColor(Color.RED); SwingText.drawText(go.getName(), g, r); double x1 = x0 + object_width / 2; double y1 = top_bottom_margin + object_height; double y2 = time_end; Line2D tl = new Line2D.Double(x1, y1, x1, y2); g.setColor(Color.BLACK); g.draw(tl); for (GraphBlock gb : go.getBlocks()) { drawBlock(g, x1, gb); } }
/** * Draws this without refreshing steps. * * @param panel the drawing panel requesting the drawing * @param _g the graphics context on which to draw */ public void drawMe(DrawingPanel panel, Graphics _g) { // position and show inspector if requested during loading if (inspectorX != Integer.MIN_VALUE && trackerPanel != null && trackerPanel.getTFrame() != null) { positionInspector(); Runnable runner = new Runnable() { public void run() { showInspector = false; inspector.setVisible(true); } }; if (showInspector) SwingUtilities.invokeLater(runner); } if (isVisible() && isTraceVisible()) { // draw trace only if fixed coords & (non-worldview or no ref frame) TrackerPanel tPanel = (TrackerPanel) panel; ImageCoordSystem coords = tPanel.getCoords(); // get active coords boolean isRefFrame = coords instanceof ReferenceFrame; if (isRefFrame) { coords = ((ReferenceFrame) coords).getCoords(); } boolean fixed = coords.isFixedAngle() && coords.isFixedOrigin() && coords.isFixedScale(); if (fixed && (!(tPanel instanceof WorldTView) || !isRefFrame)) { trace.reset(); for (int i = 0; i < traceX.length; i++) { if (Double.isNaN(traceX[i])) continue; tracePt.setLocation(traceX[i], traceY[i]); java.awt.Point p = tracePt.getScreenPosition(tPanel); if (trace.getCurrentPoint() == null) trace.moveTo((float) p.getX(), (float) p.getY()); else trace.lineTo((float) p.getX(), (float) p.getY()); } Graphics2D g2 = (Graphics2D) _g; Color color = g2.getColor(); Stroke stroke = g2.getStroke(); g2.setColor(getFootprint().getColor()); g2.setStroke(traceStroke); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); g2.draw(trace); // restore original color and stroke g2.setColor(color); g2.setStroke(stroke); } } super.draw(panel, _g); }
boolean render(Graphics2D map) { double diff = (System.nanoTime() - created) / 1000 / 1000; if (diff > timeAlive) return true; map.setColor(new Color(100, 100, 100, (int) (255 - (diff / timeAlive * 250)))); for (int i = 0; i < particles.length; i++) { RectangularShape tmp = (RectangularShape) particles[i][0]; double xD = (Double) particles[i][1]; double yD = (Double) particles[i][2]; tmp.setFrame( (double) tmp.getX() + xD / delta, (double) tmp.getY() + yD / delta, tmp.getWidth(), tmp.getHeight()); map.draw(tmp); } return false; }
/** Draw vertices on top of the edge structure */ public void drawNodes(Graphics2D gg) { Enumeration nodeList = argument.getBreadthFirstTraversal().elements(); // Run through the traversal and draw each vertex // using an Ellipse2D // The draw point has been determined previously in // calcNodeCoords() while (nodeList.hasMoreElements()) { TreeVertex vertex = (TreeVertex) nodeList.nextElement(); // Don't draw virtual nodes if (vertex.isVirtual()) continue; // If tree is incomplete and we're on the top layer, skip it if (argument.isMultiRoots() && vertex.getLayer() == 0) continue; Point corner = vertex.getDrawPoint(); Shape node = new Ellipse2D.Float(corner.x, corner.y, NODE_DIAM, NODE_DIAM); vertex.setShape(node, this); // Fill the interior of the node with vertex's fillPaint gg.setPaint(vertex.fillPaint); gg.fill(node); // Draw the outline with vertex's outlinePaint; bold if selected gg.setPaint(vertex.outlinePaint); if (vertex.isSelected()) { gg.setStroke(selectStroke); } else { gg.setStroke(solidStroke); } gg.draw(node); // Draw the short label on top of the vertex gg.setPaint(vertex.textPaint); String shortLabelString = new String(vertex.getShortLabel()); if (shortLabelString.length() == 1) { gg.setFont(labelFont1); gg.drawString(shortLabelString, corner.x + NODE_DIAM / 4, corner.y + 3 * NODE_DIAM / 4); } else if (shortLabelString.length() == 2) { gg.setFont(labelFont2); gg.drawString(shortLabelString, corner.x + NODE_DIAM / 5, corner.y + 3 * NODE_DIAM / 4); } } }
void characterHandeler(Graphics2D map) { for (int i = 0; i < characterExplosions.length; i++) { if (characterExplosions[i] != null) { if (characterExplosions[i].render(map)) characterExplosions[i] = null; } } for (int i = 0; i < characters.length; i++) { if (characters[i] != null) { if (characters[i].isDead == true) { newCExplosion(characters[i].body.getCenterX(), characters[i].body.getCenterY()); if (rand.nextInt(5) == 1) { int type = 1; if (rand.nextInt(10) == 1) { type = 2; } if (rand.nextInt(4) == 1) for (int j = 0; j < player.weapon.length; j++) if (player.weapon[j][11] != null && (Boolean) player.weapon[j][11] == true) if ((Integer) player.weapon[j][10] < 5) type = 3; spawnItem(characters[i].body.getCenterX(), characters[i].body.getCenterY(), type); } characters[i] = null; } else { if (characters[i].id != "player") { characters[i].Folow(player); double[] pos = checkIfInsideBounds(characters[i]); characters[i].body.setFrame( pos[0], pos[1], characters[i].body.getWidth(), characters[i].body.getHeight()); characters[i].Update(xOffset, yOffset, delta); } characters[i].Render(map, characters); if (Math.pow(characters[i].body.getCenterX() - characters[i].body.getCenterX(), 2) + Math.pow(player.body.getCenterY() - player.body.getCenterY(), 2) < Math.pow(width * 1.5, 2)) { map.setColor(Color.darkGray); map.draw(characters[i].body); } } } } }
private void doDrawing(Graphics g, double std, int sig, int val) { double gaus; Graphics2D g2d = (Graphics2D) g; double Xawal = X_AXIS_FIRST_X_COORD; double Yawal = Y_AXIS_SECOND_Y_COORD; Point2D.Double point = new Point2D.Double(Xawal, Yawal); double xLength = (X_AXIS_SECOND_X_COORD - X_AXIS_FIRST_X_COORD) / xCoordNumbers; double yLength = (Y_AXIS_SECOND_Y_COORD - Y_AXIS_FIRST_Y_COORD) / yCoordNumbers; if (val == 0) { g2d.setColor(Color.blue); } else if (val == 1) { g2d.setColor(Color.red); } else if (val == 2) { g2d.setColor(Color.black); } double tempX = 0.0, tempY = 0.0; double i = (double) nilaiAwal[val]; while (i <= nilaiAkhir[val]) { gaus = Math.exp(-((Math.pow((i - sig) / std, 2)))); // System.out.println(gaus); if (gaus > 1.0) { gaus = 0.0; } Xawal = X_AXIS_FIRST_X_COORD + (i * xLength) - 3; Yawal = Y_AXIS_SECOND_Y_COORD - ((gaus * 10) * yLength); if (i == nilaiAwal[val]) { tempX = X_AXIS_FIRST_X_COORD + (i * xLength) - 3; ; tempY = Y_AXIS_SECOND_Y_COORD - ((gaus * 10) * yLength); } g2d.draw(new Line2D.Double(tempX, tempY, Xawal, Yawal)); tempX = X_AXIS_FIRST_X_COORD + (i * xLength) - 3; tempY = Y_AXIS_SECOND_Y_COORD - ((gaus * 10) * yLength); i = i + 0.1; } // for(int i=nilaiAwal;i<=xCoordNumbers;i++){ // } }
void renderBackground(Graphics2D g2d) { g2d.setColor(new Color(0, 0, 0, 30)); for (int i = 0; i < background.length; i++) { if (background[i][8] == 1) { if (Math.round(rand.nextInt(200) * delta) == 1) background[i][6] = (rand.nextInt(3) - 1); if (Math.round(rand.nextInt(200) * delta) == 1) background[i][7] = (rand.nextInt(3) - 1); if (background[i][6] < 0) background[i][6] = background[i][6] - 0.01; else if (background[i][6] > 0) background[i][6] = background[i][6] + 0.01; if (background[i][7] < 0) background[i][7] = background[i][7] - 0.01; else if (background[i][7] > 0) background[i][7] = background[i][7] + 0.01; if (background[i][2] < background[i][0] - backgroundWidth * 3) background[i][6] = rand.nextInt(2); if (background[i][2] > background[i][0] + backgroundWidth * 3) background[i][6] = -rand.nextInt(2); if (background[i][3] < background[i][1] - backgroundWidth * 3) background[i][7] = rand.nextInt(2); if (background[i][3] > background[i][1] + backgroundWidth * 3) background[i][7] = -rand.nextInt(2); background[i][2] = background[i][2] + background[i][6] / delta / 10; background[i][3] = background[i][3] + background[i][7] / delta / 10; Path2D tmp = new Path2D.Double(); tmp.moveTo(background[i][0], background[i][1]); tmp.curveTo( background[i][0], background[i][1], background[i][2], background[i][3], background[i][4], background[i][5]); g2d.draw(tmp); } } }
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; Dimension asz = this.getSize(); if (fullRefresh) { g2.clearRect(0, 0, asz.width, asz.height); fullRefresh = false; } g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); big.setColor(Color.black); offset.x = (int) (asz.width - iw) / 2; offset.y = (int) (asz.height - ih) / 2; big.drawImage(img, 0, 0, this); big.setPaint(Color.red); if ((rect.width > 0) && (rect.height > 0)) big.draw(rect); if (selected == 1) shadeExt(big, 0, 0, 0, 64); else if (selected == 2) { shadeExt(big, 0, 0, 0, 255); selected = 1; } g2.drawImage(bi, offset.x, offset.y, this); }
/** Paints the <tt>visualEdge</tt>. No arrowhead is drawn. */ public void paint(VisualGraphComponent component, Graphics2D g2d) { VisualEdge vEdge = (VisualEdge) component; Rectangle fromvertexBounds; Rectangle tovertexBounds; GeneralPath drawPath; VisualVertex visualVertexA = vEdge.getVisualVertexA(); VisualVertex visualVertexB = vEdge.getVisualVertexB(); GraphLayoutManager layoutmanager = vEdge.getVisualGraph().getGraphLayoutManager(); drawPath = vEdge.getGeneralPath(); // If there is no layoutmanager or there is one but the layout has not // been initialised, by default, let us route edges as straight lines. if (layoutmanager == null || (layoutmanager != null && !layoutmanager.isInitialized())) { fromvertexBounds = visualVertexA.getBounds(); tovertexBounds = visualVertexB.getBounds(); // Make sure to clear the GeneralPath() first. Otherwise, the edge's previous // path will be redrawn as well. drawPath.reset(); // Start the line from the center of the vEdgertex drawPath.moveTo((float) fromvertexBounds.getCenterX(), (float) fromvertexBounds.getCenterY()); drawPath.lineTo((float) tovertexBounds.getCenterX(), (float) tovertexBounds.getCenterY()); } else { // Let the layout manager determine how the edge will be routed. layoutmanager.routeEdge(g2d, vEdge); } // Draw the line g2d.setColor(vEdge.getOutlinecolor()); g2d.draw(drawPath); // Draw the edge label this.paintText(vEdge, g2d); }
private void drawLinks(Graphics2D g, GraphObject go) { double x0 = graph_locations.get(go); for (GraphLink gl : go.getLinks()) { GraphObject got = gl.getToObject(); double x1 = graph_locations.get(got); double y0 = getTimeY(gl.getTime()); double x3, x4; if (x0 < x1) { x3 = x0 + active_width / 2; x4 = x1 - active_width / 2; } else { x3 = x0 - active_width / 2; x4 = x1 + active_width / 2; } Stroke sk = type_strokes.get(gl.getType()); Color c = getThreadBlockColor(gl.getThread()); g.setColor(c); g.setStroke(sk); Line2D ln = new Line2D.Double(x3, y0, x4, y0); g.draw(ln); drawArrow(g, x3, y0, x4, y0); } }
boolean eventHandeler(Graphics2D g2d) { if (keyboard.keyDownOnce(KeyEvent.VK_Q)) { window.setState(Frame.ICONIFIED); paused = true; } if (firstStartup) { g2d.setColor(Color.white); g2d.fill(new Rectangle(0, 0, width, height)); g2d.setFont(new Font("Courier New", Font.PLAIN, 20)); g2d.setColor(Color.black); switch (startupPage) { case 1: if (keyboard.keyDownOnce(KeyEvent.VK_SPACE)) startupPage = 2; g2d.drawString("The goal of this game is to kill as", 100, 170); g2d.drawString("many *zombies* as possible. You are", 100, 200); g2d.drawString("given weapons and power-ups to help", 100, 230); g2d.drawString("you succeed. Good luck.", 100, 260); g2d.setColor(Color.gray); g2d.drawString("Press SPACE to continue", 150, 330); g2d.drawString("Ø O O", 280, 290); g2d.setColor(Color.black); g2d.setFont(new Font("Courier New", Font.PLAIN, 34)); g2d.drawString("Story", 265, 110); break; case 2: if (keyboard.keyDownOnce(KeyEvent.VK_SPACE)) startupPage = 3; g2d.drawString("Use A,S,D,W to stear", 100, 170); g2d.drawString("Use 1,2,3,4 to change weapon", 100, 200); g2d.drawString("Use the MOUSE to aim", 100, 230); g2d.drawString("Use the LEFT MOUSE BUTTON to fire", 100, 260); g2d.setColor(Color.gray); g2d.drawString("Press SPACE to continue", 150, 330); g2d.drawString("O Ø O", 280, 290); g2d.setColor(Color.black); g2d.setFont(new Font("Courier New", Font.PLAIN, 34)); g2d.drawString("Controlls", 230, 110); break; case 3: if (keyboard.keyDownOnce(KeyEvent.VK_SPACE)) firstStartup = false; g2d.setColor(Color.black); g2d.draw(new Ellipse2D.Double(100, 170 - 15, 20, 20)); g2d.setColor(Color.red); g2d.draw(new Ellipse2D.Double(100, 200 - 15, 20, 20)); g2d.setColor(Color.blue); g2d.draw(new Ellipse2D.Double(100, 230 - 15, 20, 20)); g2d.setColor(Color.green); g2d.draw(new Ellipse2D.Double(100, 260 - 15, 20, 20)); g2d.setColor(Color.black); g2d.drawString("Is you", 130, 170); g2d.drawString("Heals you", 130, 200); g2d.drawString("Unlocks / upgrades a weapon", 130, 230); g2d.drawString("Causes an explosion around you", 130, 260); g2d.setColor(Color.gray); g2d.drawString("Press SPACE to start", 150, 330); g2d.drawString("O O Ø", 280, 290); g2d.setColor(Color.black); g2d.setFont(new Font("Courier New", Font.PLAIN, 34)); g2d.drawString("Power-ups", 230, 110); break; } return true; } if (player.isDead) { g2d.setColor(Color.white); g2d.fill(new Rectangle(0, 0, width, height)); if (keyboard.keyDownOnce(KeyEvent.VK_R)) restart(); if (newHighscore) { int x = 20; int y = 130; g2d.rotate(-.4, x, y); g2d.setFont(new Font("Comic Sans MS", Font.PLAIN, 40)); g2d.setColor(Color.black); Stroke oldStroke = g2d.getStroke(); float dash[] = {40.0f}; g2d.setStroke( new BasicStroke( 4.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0.0f, dash, 40.0f)); g2d.drawRoundRect(x, y, 320, 75, 20, 20); g2d.setColor(Color.red); g2d.drawString(String.format("New Highscore"), x + 20, y + 50); g2d.rotate(.4, x, y); g2d.setStroke(oldStroke); g2d.setColor(Color.lightGray); g2d.setFont(new Font("Courier", Font.PLAIN, 20)); g2d.drawString("Your record was " + oldHighScore + " kills", 210, 260); } else if (cheated) { int x = 20; int y = 130; g2d.rotate(-.4, x, y); g2d.setFont(new Font("Comic Sans MS", Font.PLAIN, 40)); g2d.setColor(Color.black); Stroke oldStroke = g2d.getStroke(); float dash[] = {40.0f}; g2d.setStroke( new BasicStroke( 4.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0.0f, dash, 40.0f)); g2d.drawRoundRect(x, y, 270, 75, 20, 20); g2d.setColor(Color.red); g2d.drawString(String.format("You cheated"), x + 20, y + 50); g2d.rotate(.4, x, y); g2d.setStroke(oldStroke); g2d.setColor(Color.lightGray); g2d.setFont(new Font("Courier", Font.PLAIN, 20)); g2d.drawString("Highscore not saved", 210, 260); } else { g2d.setColor(Color.lightGray); g2d.setFont(new Font("Courier", Font.PLAIN, 20)); g2d.drawString("Your record is " + oldHighScore + " kills", 210, 260); } g2d.setColor(Color.black); g2d.setFont(new Font("Courier", Font.PLAIN, 50)); if (player.score == 1) g2d.drawString(String.format(player.score + " kill"), 200, 230); else g2d.drawString(String.format(player.score + " kills"), 200, 230); g2d.setFont(new Font("Courier New", Font.PLAIN, 30)); g2d.setColor(Color.gray); g2d.drawString(String.format("Press R to restart"), 150, 330); return true; } if (window.isFocused() == false) paused = true; if (paused) { g2d.setColor(Color.white); g2d.fill(new Rectangle(0, 0, width, height)); if (keyboard.keyDownOnce(KeyEvent.VK_ESCAPE)) paused = false; g2d.setColor(Color.black); g2d.setFont(new Font("Courier", Font.PLAIN, 50)); g2d.drawString("Paused", 200, 230); g2d.setFont(new Font("Courier New", Font.PLAIN, 30)); g2d.setColor(Color.gray); g2d.drawString(String.format("Press ESC to resume"), 150, 330); return true; } return false; }
void draw(Graphics2D g) { int endX, endY; Block from = null; if (fromId > -1) from = diag.blocks.get(new Integer(fromId)); Block to = null; if (!endsAtLine && toId > -1) to = diag.blocks.get(new Integer(toId)); if (toX == -1) endX = diag.xa; else endX = toX; if (toY == -1) endY = diag.ya; else endY = toY; g.setColor(Color.GRAY); Stroke stroke = g.getStroke(); ZigzagStroke zzstroke = new ZigzagStroke(stroke, 2, 4); if (toX == -1) { g.drawRect(fromX - 3, fromY - 3, 6, 6); return; } if (from != null) { if (fromSide == Side.TOP) fromY = from.cy - from.height / 2; else if (fromSide == Side.BOTTOM) fromY = from.cy + from.height / 2; else if (fromSide == Side.LEFT) fromX = from.cx - from.width / 2; else if (fromSide == Side.RIGHT) fromX = from.cx + from.width / 2; } if (to != null) { if (toSide == Side.TOP) toY = to.cy - to.height / 2; else if (toSide == Side.BOTTOM) toY = to.cy + to.height / 2; else if (toSide == Side.LEFT) toX = to.cx - to.width / 2; else if (toSide == Side.RIGHT) toX = to.cx + to.width / 2; } if (driver.selArrowP == this) g.setColor(Color.BLUE); else if ((from instanceof ComponentBlock || from instanceof ExtPortBlock || from instanceof Enclosure) && (to instanceof ComponentBlock || to instanceof ExtPortBlock || to instanceof Enclosure || endsAtLine)) if (checkStatus == Status.UNCHECKED) g.setColor(Color.BLACK); else if (checkStatus == Status.COMPATIBLE) g.setColor(FOREST_GREEN); else g.setColor(ORANGE_RED); else if (from instanceof LegendBlock || to instanceof LegendBlock) g.setColor(Color.GRAY); int fx, fy, tx, ty; fx = fromX; fy = fromY; // tx = toX; // ty = toY; // int autoX = -1, autoY = -1; // only used for automatic ports if (bends != null) { for (Bend bend : bends) { tx = bend.x; ty = bend.y; if (!dropOldest) g.drawLine(fx, fy, tx, ty); else { Shape shape = new Line2D.Double(fx, fy, tx, ty); shape = zzstroke.createStrokedShape(shape); g.draw(shape); // g.setStroke(stroke); } if (bend.marked) { Color col = g.getColor(); g.setColor(Color.RED); g.drawOval(tx - 5, ty - 5, 10, 10); g.setColor(col); } calcLimits(fx, tx, fy, ty); fx = tx; fy = ty; } } tx = endX; ty = endY; int x = endX; if (to != null && endsAtBlock && to.multiplex) { String s = to.mpxfactor; if (s == null) s = " "; int i = s.length() * driver.fontWidth + 10; x -= i; } if (headMarked) { Color col = g.getColor(); g.setColor(Color.RED); g.drawOval(x - 5, toY - 5, 10, 10); g.setColor(col); } if (!dropOldest) g.drawLine(fx, fy, tx, ty); else { Shape shape = new Line2D.Double(fx, fy, tx, ty); shape = zzstroke.createStrokedShape(shape); g.draw(shape); // g.setStroke(stroke); } if (tailMarked) { Color col = g.getColor(); g.setColor(Color.RED); g.drawOval(fromX - 5, fromY - 5, 10, 10); g.setColor(col); } calcLimits(fx, x, fy, toY); if (!endsAtBlock && !endsAtLine) { g.drawRect(fromX - 3, fromY - 3, 6, 6); g.drawRect(x - 3, toY - 3, 6, 6); } else if (endsAtBlock) { if ((from instanceof ComponentBlock || from instanceof ExtPortBlock || from instanceof Enclosure) && (to instanceof ComponentBlock || to instanceof ExtPortBlock || to instanceof Enclosure)) { Arrowhead ah = new Arrowhead(fx, fy, toX, toY); ah.draw(g); } } else if (endsAtLine) { drawCircleTo(g, fx, fy, x, toY, Color.BLACK, 4); // g.drawOval(toX - 2, toY - 2, 4, 4); // g.fillOval(toX - 2, toY - 2, 4, 4); } if (toX != -1 && (endsAtBlock || endsAtLine)) { if (upStreamPort != null && (from instanceof ComponentBlock || from instanceof Enclosure)) { if (upStreamPort.equals("*")) { drawCircleFrom(g, fromX, fromY, endX, endY, Color.BLUE, 8); // g.setColor(Color.BLUE); // g.drawOval(fromX, fromY - 4, 8, 8); // g.fillOval(fromX, fromY - 4, 8, 8); } else if (from.visible) { g.setColor(Color.BLUE); int y = fromY + driver.fontHeight; int x2 = fromX + driver.fontWidth; g.drawString(upStreamPort, x2, y); } g.setColor(Color.BLACK); } if (downStreamPort != null && !endsAtLine && to != null && (to instanceof ComponentBlock || to instanceof Enclosure)) { if (downStreamPort.equals("*")) { drawCircleTo(g, fx, fy, toX, toY, Color.BLUE, 8); // g.setColor(Color.BLUE); // g.drawOval(x - 8, toY - 4, 8, 8); // g.fillOval(x - 8, toY - 4, 8, 8); } else if (to.visible) { g.setColor(Color.BLUE); int y = toY - driver.fontHeight / 2; x = toX - driver.fontWidth * (downStreamPort.length() + 1); if (!endsAtLine && to != null && to.multiplex) x -= 20; g.drawString(downStreamPort, x, y); } g.setColor(Color.BLACK); } } if (extraArrowhead != null) extraArrowhead.draw(g); }
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; line.setLine(); g2.draw(line.getLine()); } // end paint method