private void doCurrentMethodStep() { switch (type) { case 0: // bisectiei if (Math.abs(function.evaluate((Cn.lastElement()).x)) < err) { complete = true; theTimer.stop(); } else if (function.evaluate((An.lastElement()).x) * function.evaluate((Cn.lastElement()).x) < 0) { Bn.add(Cn.lastElement()); Cn.add(new PointDP(((An.lastElement()).x + (Bn.lastElement()).x) / 2, 0.0)); } else { An.add(Cn.lastElement()); Cn.add(new PointDP(((An.lastElement()).x + (Bn.lastElement()).x) / 2, 0.0)); } break; case 1: // coardei { double evn = function.evaluate((An.lastElement()).x); if (Math.abs(evn) < err) { complete = true; theTimer.stop(); } else { double ev0 = function.evaluate((An.firstElement()).x); double newVal = (An.firstElement().x * evn - An.lastElement().x * ev0) / (evn - ev0); An.add(new PointDP(newVal, 0.0)); } } break; case 2: // secantei { double exn = function.evaluate((An.lastElement()).x); if (Math.abs(exn) < err) { complete = true; theTimer.stop(); } else { double exn1 = function.evaluate((An.elementAt(An.size() - 2)).x); double newVal = (An.elementAt(An.size() - 2).x * exn - (An.lastElement()).x * exn1) / (exn - exn1); An.add(new PointDP(newVal, 0.0)); } } break; case 3: // newton double xn = An.lastElement().x; if (Math.abs(function.evaluate(xn)) < err) { complete = true; theTimer.stop(); } An.add(new PointDP(xn - function.evaluate(xn) / function.evaluate_1(xn), 0.0)); break; } }
public Point getEmptyPosition(Dimension spriteSize) { Rectangle trialSpaceOccupied = new Rectangle(0, 0, spriteSize.width, spriteSize.height); Random rand = new Random(System.currentTimeMillis()); boolean empty = false; int numTries = 0; // Search for an empty position while (!empty && numTries++ < 100) { // Get a trial position trialSpaceOccupied.x = Math.abs(rand.nextInt() % backgroundImage.getSize().width); trialSpaceOccupied.y = Math.abs(rand.nextInt() % backgroundImage.getSize().height); // Iterate through existing // sprites, checking if position // is empty boolean collision = false; for (int cnt = 0; cnt < size(); cnt++) { Rectangle testSpaceOccupied = ((Sprite) elementAt(cnt)).getSpaceOccupied(); if (trialSpaceOccupied.intersects(testSpaceOccupied)) { collision = true; } // end if } // end for loop empty = !collision; } // end while loop return new Point(trialSpaceOccupied.x, trialSpaceOccupied.y); } // end getEmptyPosition()
void MidpointLine(int x0, int y0, int x1, int y1, Graphics g) { if (x0 == x1) { for (int i = Math.min(y1, y0); i <= Math.max(y1, y0); i++) { WritePixel(x0, i, 10, g); } } else if (y0 == y1) { for (int i = Math.min(x1, x0); i <= Math.max(x1, x0); i++) { WritePixel(i, y0, 10, g); } } else { int dx = Math.abs(x1 - x0); int dy = Math.abs(y1 - y0); int d = dx - dy; int sx, sy, d2; if (x0 < x1) sx = 1; else sx = -1; if (y0 < y1) sy = 1; else sy = -1; do { WritePixel(x0, y0, 10, g); d2 = d * 2; if (d2 > -dy) { x0 += sx; d -= dy; } if (d2 < dx) { d += dx; y0 += sy; } } while (x0 != x1 && y0 != y1); } }
public void paint(Graphics g) { g.setColor(Color.black); super.paint(g); int h = Math.abs(y1 - y2) - 1, w = Math.abs(x1 - x2) - 1; // int x0=x1>x2?x2:x1, y0=y1>y2?y2:y1; int x0 = 0, y0 = 0; g.drawRect(x0, y0, w, h); }
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 }
public void setXY(double x, double y) { // not validated // x and y between -1 and 1 double sigmoidSteepness, sigmoidZero, baseLength; double sensitivity = 1.1; // evaluated with set to 1.1: a sensitivity of 1 means the complete space of the button // is used. 2 means only the middle part is used, making it more sensitive and more // easy to get to extreme arousal (from a CHI perspective). if (!down) { p = x * sensitivity; d = y * sensitivity; baseLength = Math.max(Math.abs(p), Math.abs(d)); // MAX (P, D) base // baseLength=Math.sqrt(Math.pow(p,2)+Math.pow(d,2))/Math.sqrt(2.0); //euclid P,D base // now do the mapping to arousal. // Arousal is controlled simple by using a Sigmoid function based on length of PD vector sigmoidSteepness = 11; sigmoidZero = 8; a = 2 / (1 + Math.exp(-(sigmoidSteepness * baseLength - sigmoidZero))) - 1; a_base = a; // Arousal is controlled simply by using a quadratic function that has 0,0,0 as middle point, // then drops to -1, then to 1 based MIN (P,D) length (mimics better original linear) // sigmoidSteepness=6; // sigmoidZero=0.35; // a=sigmoidSteepness*Math.pow(Math.max(Math.abs(p),Math.abs(d))-sigmoidZero, 2)-1; p = (p > 1 ? 1 : (p < -1 ? -1 : p)); d = (d > 1 ? 1 : (d < -1 ? -1 : d)); a = (a > 1 ? 1 : (a < -1 ? -1 : a)); } else { double tmp_p, tmp_d; tmp_p = x * sensitivity; tmp_d = y * sensitivity; baseLength = Math.max(Math.abs(tmp_p), Math.abs(tmp_d)); // MAX (P, D) base // baseLength=Math.sqrt(Math.pow(p,2)+Math.pow(d,2))/Math.sqrt(2.0); //euclid P,D base // now do the mapping to arousal. // Arousal is controlled simple by using a Sigmoid function based on length of PD vector sigmoidSteepness = 11; sigmoidZero = 8; // a=a_base-(d-tmp_d)+2/(1+Math.exp(-(sigmoidSteepness*baseLength-sigmoidZero)))-1; a = tmp_d; // Arousal is controlled simply by using a quadratic function that has 0,0,0 as middle point, // then drops to -1, then to 1 based MIN (P,D) length (mimics better original linear) // sigmoidSteepness=6; // sigmoidZero=0.35; // a=sigmoidSteepness*Math.pow(Math.max(Math.abs(p),Math.abs(d))-sigmoidZero, 2)-1; // p=(p>1?1:(p<-1?-1:p)); // d=(d>1?1:(d<-1?-1:d)); a = (a > 1 ? 1 : (a < -1 ? -1 : a)); } }
/** Called on mouse drag to reshape the current rectangle */ public void mouseDragged(MouseEvent e) { if (gobj != null) { gobj.move(e.getX() - lastX, e.getY() - lastY); lastX = e.getX(); lastY = e.getY(); } else { double x = Math.min(e.getX(), startX); double y = Math.min(e.getY(), startY); double width = Math.abs(e.getX() - startX); double height = Math.abs(e.getY() - startY); currentRect.setBounds(x, y, width, height); } }
private Line addLine(Point p1, Point p2) { if (Math.abs(p1.getX() - p2.getX()) < 5 || Math.abs(p1.getY() - p2.getY()) < 5) { return null; } Line line = null; if (p1 != null && p2 != null) { line = new Line(p1, p2); canvas.add(line); } repaint(); return line; }
/** * When the ERASE or SMUDGE tools are used and the mouse jumps from (x1,y1) to (x2,y2), the tool * has to be applied to a line of pixel positions between the two points in order to cover the * entire line that the mouse moves along. The change is made to the off-screen canvas, and * repaint() is called to copy the changes to the screen. */ void applyToolAlongLine(int x1, int y1, int x2, int y2) { Graphics g = OSC.getGraphics(); g.setColor(fillColor); // (for ERASE only) int w = OSC.getWidth(); // (for SMUDGE only) int h = OSC.getHeight(); // (for SMUDGE only) int dist = Math.max(Math.abs(x2 - x1), Math.abs(y2 - y1)); // dist is the number of points along the line from // (x1,y1) to (x2,y2) at which the tool will be applied. double dx = (double) (x2 - x1) / dist; double dy = (double) (y2 - y1) / dist; for (int d = 1; d <= dist; d++) { // Apply the tool at one of the points (x,y) along the // line from (x1,y1) to (x2,y2). int x = (int) Math.round(x1 + dx * d); int y = (int) Math.round(y1 + dy * d); if (currentTool == Tool.ERASE) { // Erase a 10-by-10 block of pixels around (x,y) g.fillRect(x - 5, y - 5, 10, 10); repaint(x - 5, y - 5, 10, 10); } else { // For the SMUDGE tool, blend some of the color from // the smudgeRed, smudgeGreen, and smudgeBlue arrays // into the pixels in a 7-by-7 block around (x,y), and // vice versa. The effect is to smear out the color // of pixels that are visited by the tool. for (int i = 0; i < 7; i++) { for (int j = 0; j < 7; j++) { int r = y + j - 3; int c = x + i - 3; if (!(r < 0 || r >= h || c < 0 || c >= w || smudgeRed[i][j] == -1)) { int curCol = OSC.getRGB(c, r); int curRed = (curCol >> 16) & 0xFF; int curGreen = (curCol >> 8) & 0xFF; int curBlue = curCol & 0xFF; int newRed = (int) (curRed * 0.7 + smudgeRed[i][j] * 0.3); int newGreen = (int) (curGreen * 0.7 + smudgeGreen[i][j] * 0.3); int newBlue = (int) (curBlue * 0.7 + smudgeBlue[i][j] * 0.3); int newCol = newRed << 16 | newGreen << 8 | newBlue; OSC.setRGB(c, r, newCol); smudgeRed[i][j] = curRed * 0.3 + smudgeRed[i][j] * 0.7; smudgeGreen[i][j] = curGreen * 0.3 + smudgeGreen[i][j] * 0.7; smudgeBlue[i][j] = curBlue * 0.3 + smudgeBlue[i][j] * 0.7; } } } repaint(x - 3, y - 3, 7, 7); } } g.dispose(); }
/** *****************************Connected Component Recursive ***************************** */ void connect(int y, int x) { if (conect_output[y][x] == 0) { conect_output[y][x] = 175; obj_size++; // System.out.println("Size :" +obj_size); s = x + 1; t = y; if (boundary_check(t, s) && (Math.abs(conect_input[t][s] - intensity) < 20)) { // conect_output[s][t] = 175; connect(t, s); } s = x; t = y - 1; if (boundary_check(t, s) && (Math.abs(conect_input[t][s] - intensity) < 20)) { // conect_output[s][t] = 175; connect(t, s); } s = x + 1; t = y - 1; if (boundary_check(t, s) && (Math.abs(conect_input[t][s] - intensity) < 20)) { // conect_output[s][t] = 175; connect(t, s); } s = x + 1; t = y + 1; if (boundary_check(t, s) && (Math.abs(conect_input[t][s] - intensity) < 20)) { // conect_output[s][t] = 175; connect(t, s); } s = x - 1; t = y - 1; if (boundary_check(t, s) && (Math.abs(conect_input[t][s] - intensity) < 20)) { // conect_output[s][t] = 175; connect(t, s); } s = x - 1; t = y + 1; if (boundary_check(t, s) && (Math.abs(conect_input[t][s] - intensity) < 20)) { // conect_output[s][t] = 175; connect(t, s); } s = x + 1; t = y; if (boundary_check(t, s) && (Math.abs(conect_input[t][s] - intensity) < 20)) { // conect_output[s][t] = 175; connect(t, s); } s = x - 1; t = y; if (boundary_check(t, s) && (Math.abs(conect_input[t][s] - intensity) < 20)) { // conect_output[s][t] = 175; connect(t, s); } } }
protected void drawImageMosaic(Graphics2D g2) { // Break the image up into tiles. Draw each // tile with its own transparency, allowing // the background to show through to varying // degrees. int side = 36; int width = mImage.getWidth(); int height = mImage.getHeight(); for (int y = 0; y < height; y += side) { for (int x = 0; x < width; x += side) { // Calculate an appropriate transparency value. float xBias = (float) x / (float) width; float yBias = (float) y / (float) height; float alpha = 1.0f - Math.abs(xBias - yBias); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha)); // Draw the subimage. int w = Math.min(side, width - x); int h = Math.min(side, height - y); BufferedImage tile = mImage.getSubimage(x, y, w, h); g2.drawImage(tile, x, y, null); } } // Reset the composite. g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER)); }
/** Generate the hierarchical cluster and display it as a denogram in the graph */ public TreeNode makeTree(ClutoSolution cs) { int[] tsize = cs.getTreeCounts(); int[][] ftree = cs.getForwardTree(); int nnrows = tsize.length; int nrows = cs.getMatrix().getRowCount(); // for (int i = 0; i < nnrows-1; i++) { // String s = "ftree" + "\t" + i + "\t" + ftree[i][0] + "\t" + ftree[i][1] + "\t" + tsize[i]; // System.out.println(s); // } Cluster[] ca = new Cluster[nnrows]; for (int i = 0; i < nnrows - 1; i++) { if (!true) { String s = "ftree" + "\t" + i + "\t" + ftree[i][0] + "\t" + ftree[i][1] + "\t" + tsize[i]; System.out.println(s); } Cluster cn = i < nrows ? (Cluster) new RowCluster(tm, i, null) : new CompositeCluster(); cn.setSimilarity(Math.abs(tsize[i])); ca[i] = cn; if (ftree[i][0] > -1) { cn.add(ca[ftree[i][0]]); } if (ftree[i][0] > -1) { cn.add(ca[ftree[i][1]]); } rootNode = cn; } return rootNode; }
public static int HashCode(String input) { int hCode = 0; int len = input.length(); for (int i = 0; i < len; i++) { hCode = 31 * hCode + input.charAt(i); } return Math.abs(hCode % 256); }
/** * Zooms out by making the source rectangle (srcRect) larger and centering it on (x,y). If we * can't make it larger, then make the window smaller. */ public void zoomOut(int x, int y) { if (magnification <= 0.03125) return; double oldMag = magnification; double newMag = getLowerZoomLevel(magnification); double srcRatio = (double) srcRect.width / srcRect.height; double imageRatio = (double) imageWidth / imageHeight; double initialMag = imp.getWindow().getInitialMagnification(); if (Math.abs(srcRatio - imageRatio) > 0.05) { double scale = oldMag / newMag; int newSrcWidth = (int) Math.round(srcRect.width * scale); int newSrcHeight = (int) Math.round(srcRect.height * scale); if (newSrcWidth > imageWidth) newSrcWidth = imageWidth; if (newSrcHeight > imageHeight) newSrcHeight = imageHeight; int newSrcX = srcRect.x - (newSrcWidth - srcRect.width) / 2; int newSrcY = srcRect.y - (newSrcHeight - srcRect.height) / 2; if (newSrcX < 0) newSrcX = 0; if (newSrcY < 0) newSrcY = 0; srcRect = new Rectangle(newSrcX, newSrcY, newSrcWidth, newSrcHeight); // IJ.log(newMag+" "+srcRect+" "+dstWidth+" "+dstHeight); int newDstWidth = (int) (srcRect.width * newMag); int newDstHeight = (int) (srcRect.height * newMag); setMagnification(newMag); setMaxBounds(); // IJ.log(newDstWidth+" "+dstWidth+" "+newDstHeight+" "+dstHeight); if (newDstWidth < dstWidth || newDstHeight < dstHeight) { // IJ.log("pack"); setDrawingSize(newDstWidth, newDstHeight); imp.getWindow().pack(); } else repaint(); return; } if (imageWidth * newMag > dstWidth) { int w = (int) Math.round(dstWidth / newMag); if (w * newMag < dstWidth) w++; int h = (int) Math.round(dstHeight / newMag); if (h * newMag < dstHeight) h++; x = offScreenX(x); y = offScreenY(y); Rectangle r = new Rectangle(x - w / 2, y - h / 2, w, h); if (r.x < 0) r.x = 0; if (r.y < 0) r.y = 0; if (r.x + w > imageWidth) r.x = imageWidth - w; if (r.y + h > imageHeight) r.y = imageHeight - h; srcRect = r; } else { srcRect = new Rectangle(0, 0, imageWidth, imageHeight); setDrawingSize((int) (imageWidth * newMag), (int) (imageHeight * newMag)); // setDrawingSize(dstWidth/2, dstHeight/2); imp.getWindow().pack(); } // IJ.write(newMag + " " + srcRect.x+" "+srcRect.y+" "+srcRect.width+" "+srcRect.height+" // "+dstWidth + " " + dstHeight); setMagnification(newMag); // IJ.write(srcRect.x + " " + srcRect.width + " " + dstWidth); setMaxBounds(); repaint(); }
/** * Called by the paint method to draw the graph and its graph items. * * @param g the graphics context. */ public void paintComponent(Graphics g) { Dimension dim = getSize(); Insets insets = getInsets(); dataArea = new Rectangle( insets.left, insets.top, dim.width - insets.left - insets.right - 1, dim.height - insets.top - insets.bottom - 1); // background if (isOpaque()) { g.setColor(getBackground()); g.fillRect(0, 0, dim.width, dim.height); } g.setColor(getForeground()); // get axis tickmarks double xticks[] = xAxis.getTicks(); double yticks[] = yAxis.getTicks(); int yb = dataArea.y + dataArea.height; // draw grid if (showGrid) { g.setColor(gridColor != null ? gridColor : getBackground().darker()); // vertical x grid lines for (int i = 0; i < xticks.length; i += 2) { int x = dataArea.x + (int) Math.round(xticks[i]); g.drawLine(x, dataArea.y, x, dataArea.y + dataArea.height); } // horizontal y grid lines for (int i = 0; i < yticks.length; i += 2) { int y = yb - (int) Math.round(yticks[i]); g.drawLine(dataArea.x, y, dataArea.x + dataArea.width, y); } } for (int i = 0; i < graphItems.size(); i++) { ((GraphItem) graphItems.elementAt(i)).draw(this, g, dataArea, xAxis, yAxis); } if (sPt != null && ePt != null) { g.setColor(getForeground()); g.drawRect( Math.min(sPt.x, ePt.x), Math.min(sPt.y, ePt.y), Math.abs(ePt.x - sPt.x), Math.abs(ePt.y - sPt.y)); } }
@Override public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = ((Graphics2D) g); g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); g2d.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); g2d.setRenderingHint( RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_OFF); g2d.setRenderingHint( RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_SPEED); g2d.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE); g2d.setColor(Color.BLACK); g2d.fillRect(0, 0, getWidth(), getHeight()); if (bufferedImage != null) { synchronized (LOCKER) { g2d.drawImage(bufferedImage, transformCells, null); } } // draw struct preview if (structurePreview != null) { Composite composite = g2d.getComposite(); g2d.setComposite(compositeStructPreview); g2d.drawImage(structurePreview, previewTransform, null); g2d.setComposite(composite); } // draw grid if (transformCells.getScaleX() > SHOW_GRID_MIN_SCALE) { Composite composite = g2d.getComposite(); g2d.setComposite(compositeGrid); g2d.drawImage(bufferedImageGrid, transformGrid, null); g2d.setComposite(composite); } // draw border for preview if (structurePreview != null && Math.abs(transformCells.getScaleX()) >= 0.95) { Shape shape = new Rectangle(0, 0, structurePreview.getWidth(), structurePreview.getHeight()); shape = previewTransform.createTransformedShape(shape); g2d.setColor(Color.RED); g2d.draw(shape); } // draw border double x = transformCells.getTranslateX(); double y = transformCells.getTranslateY(); g2d.setColor(BORDER_COLOR); g2d.setStroke(new BasicStroke(BORDER_WIDTH)); g2d.drawRect( round(x - BORDER_WIDTH), round(y - BORDER_WIDTH), round(getAutomatonWidth() * transformCells.getScaleX() + 2 * BORDER_WIDTH), round(getAutomatonHeight() * transformCells.getScaleY() + 2 * BORDER_WIDTH)); }
public void drawbranch(Graphics g, float width, int x0, int y0, int x1, int y1) { if (width < 1.5f) { g.drawLine(x0, y0, x1, y1); return; } int h = (int) (width); int x[] = new int[4]; int y[] = new int[4]; if (Math.abs(x1 - x0) < Math.abs(y1 - y0)) { x[0] = x0 - h; x[1] = x0 + h; x[2] = x1 + h; x[3] = x1 - h; if (y0 < y1) { y[0] = y0 - h; y[1] = y0 - h; y[2] = y1 + h; y[3] = y1 + h; } else { y[0] = y0 + h; y[1] = y0 + h; y[2] = y1 - h; y[3] = y1 - h; } } else { y[0] = y0 - h; y[1] = y0 + h; y[2] = y1 + h; y[3] = y1 - h; if (x0 < x1) { x[0] = x0 - h; x[1] = x0 - h; x[2] = x1 + h; x[3] = x1 + h; } else { x[0] = x0 + h; x[1] = x0 + h; x[2] = x1 - h; x[3] = x1 - h; } } g.fillPolygon(x, y, 4); }
public void nudge(int i) { x[i] += (double) rand.nextInt(1000) / 8756; y[i] += (double) rand.nextInt(1000) / 5432; int tmpScale = (int) (Math.abs(Math.sin(x[i])) * 10); scale[i] = (double) tmpScale / 10; int nudgeX = (int) (((double) getWidth() / 2) * .8); int nudgeY = (int) (((double) getHeight() / 2) * .60); xh[i] = (int) (Math.sin(x[i]) * nudgeX) + nudgeX; yh[i] = (int) (Math.sin(y[i]) * nudgeY) + nudgeY; }
private boolean doubleJumpProcess(GameObj obj, int xtrans, int ytrans) { if (xtrans >= 8 || xtrans < 0 || ytrans >= 8 || ytrans < 0) { return false; } int x = obj.getX(); int y = obj.getY(); if (Math.abs(x - xtrans) != 2 && Math.abs(y - ytrans) != 2) { return false; } int medx = (x + xtrans) / 2; int medy = (y + ytrans) / 2; if (BOARD[xtrans][ytrans].isTile() && BOARD[medx][medy].isChecker() && !BOARD[medx][medy].getColor().equals(turn)) { doubleJumpSpots.add(new Tuple<Integer, Integer>(xtrans, ytrans)); return true; } else { return false; } }
public void mouseEntered(MouseEvent e) { if (!readOnly) { if (lastMouseExitTime > 0 && lastInsertTime > 0) { long waitTime = Math.abs(lastMouseExitTime - lastInsertTime); lastInsertTime = System.currentTimeMillis() - waitTime; lastMouseExitTime = -1; } else { lastInsertTime = System.currentTimeMillis(); } } }
public void shuffle() { for (int i = 0; i < 3; i++) { for (int j = 0; j < num_cards; j++) { int k = Math.abs(rand.nextInt() % num_cards); /* swap */ int temp = deck[j]; deck[j] = deck[k]; deck[k] = temp; } } current = 0; }
public void run() { try { while (true) { combo.showPopup(); int i = Math.abs(generator.nextInt()); if (i % 2 == 0) combo.insertItemAt(new Integer(i), 0); else if (combo.getItemCount() > 0) combo.removeItemAt(i % combo.getItemCount()); Thread.sleep(1); } } catch (InterruptedException e) { } }
// override me public void doZoomIn(Rectangle rbRect) { int x = rbRect.x - mLeft - 5; int y = rbRect.y - mTop - 5; // zoom in double xInc = getXZoomIncrement(); double yInc = getYZoomIncrement(); // get coordinates of new view center // correct the x value if necessary double xx = correctX((double) x); // correct the Y coordinate if necessary double yy = correctY((double) y); double newXCtr = (xx / winXScale) + winXOrigin; double newYCtr = (yy / winYScale) + winYOrigin; // compute the deltas for current range double xDelta = Math.abs(getMaxXVal() - getMinXVal()) / 2.0; double yDelta = Math.abs(getMaxYVal() - getMinYVal()) / 2.0; // compute the aspect ratio of the few double aspect = xDelta / yDelta; // if (aspect > 1.0) // xInc *= aspect; // else // yInc *= aspect; double newXMin = newXCtr < 0 ? newXCtr - xDelta + xInc : newXCtr - xDelta + xInc; double newXMax = newXCtr < 0 ? newXCtr + xDelta - xInc : newXCtr + xDelta - xInc; double newYMin = newYCtr < 0 ? newYCtr - yDelta + yInc : newYCtr - yDelta + yInc; double newYMax = newYCtr < 0 ? newYCtr + yDelta - yInc : newYCtr + yDelta - yInc; double[] oldYs = {getMinYVal(), getMaxYVal()}; double[] newYs = {newYMin, newYMax}; double[] oldXs = {getMinXVal(), getMaxXVal()}; double[] newXs = {newXMin, newXMax}; this.zoomDomain(oldYs, newYs, oldXs, newXs); }
public void sobel() { sobel = new BufferedImage(width, height, filtered.getType()); Graphics2D g = sobel.createGraphics(); g.setColor(new Color(0, 0, 0, 0)); g.fillRect(0, 0, width, height); g.dispose(); int[] tmp = new int[1]; sX = new double[height][width]; sY = new double[height][width]; double maxX = 0; double maxY = 0; for (int y = 1; y < height - 1; ++y) for (int x = 1; x < width - 1; ++x) { double Xvalue = 0; double Yvalue = 0; for (int j = -1; j <= 1; ++j) for (int i = -1; i <= 1; ++i) { Xvalue += GX[1 + j][1 + i] * filtered.getRaster().getPixel(x + i, y + j, tmp)[0]; Yvalue += GY[1 + j][1 + i] * filtered.getRaster().getPixel(x + i, y + j, tmp)[0]; } if (Xvalue > maxX) maxX = Xvalue; if (Yvalue > maxY) maxY = Yvalue; sX[y][x] = Xvalue; sY[y][x] = Yvalue; } for (int y = 1; y < height - 1; ++y) for (int x = 1; x < width - 1; ++x) { double[] a = {(Math.abs((sX[y][x] / maxX * 255)) + Math.abs((sY[y][x] / maxY) * 255))}; // if (a[0] > 0) binary[y][x] = 1; // if (a[0] <= 0) binary[y][x] = 0; sobel.getRaster().setPixel(x, y, a); } ImageIcon icon2 = new ImageIcon(sobel); lbl2.setIcon(icon2); }
public void findWidth() { max = new float[3]; min = new float[3]; max[0] = (float) -1e30; max[1] = (float) -1e30; max[2] = (float) -1e30; min[0] = (float) 1e30; min[1] = (float) 1e30; min[2] = (float) 1e30; for (int i = 0; i < 3; i++) { for (int j = 0; j < npoint; j++) { SequencePoint sp = (SequencePoint) points.elementAt(j); if (sp.coord[i] >= max[i]) { max[i] = sp.coord[i]; } if (sp.coord[i] <= min[i]) { min[i] = sp.coord[i]; } } } // System.out.println("xmax " + max[0] + " min " + min[0]); // System.out.println("ymax " + max[1] + " min " + min[1]); // System.out.println("zmax " + max[2] + " min " + min[2]); width[0] = Math.abs(max[0] - min[0]); width[1] = Math.abs(max[1] - min[1]); width[2] = Math.abs(max[2] - min[2]); maxwidth = width[0]; if (width[1] > width[0]) maxwidth = width[1]; if (width[2] > width[1]) maxwidth = width[2]; // System.out.println("Maxwidth = " + maxwidth); }
public void actionPerformed(ActionEvent event) { String filename = new String(); Random g = new Random(); switch (difficulty.getSelectedIndex()) { case 0: filename = "easy" + Math.abs(g.nextInt() % 5) + ".sudoku"; break; case 1: filename = "medium" + Math.abs(g.nextInt() % 5) + ".sudoku"; break; case 2: filename = "hard" + Math.abs(g.nextInt() % 5) + ".sudoku"; break; case 3: filename = "evil" + Math.abs(g.nextInt() % 5) + ".sudoku"; break; } openFile( "C:\\Users\\ncp1300\\Documents\\Computer Science\\Java\\cs153\\cs153\\sudoku\\src\\sudoku\\games\\" + filename); }
public AlignSequenceI findPoint(int x, int y) { int halfwidth = size().width / 2; int halfheight = size().height / 2; int found = -1; for (int i = 0; i < npoint; i++) { SequencePoint sp = (SequencePoint) points.elementAt(i); int px = (int) ((float) (sp.coord[0] - centre[0]) * scale) + halfwidth; int py = (int) ((float) (sp.coord[1] - centre[1]) * scale) + halfheight; if (Math.abs(px - x) < 3 && Math.abs(py - y) < 3) { found = i; } } if (found != -1) { return ((SequencePoint) points.elementAt(found)).sequence; } else { return null; } }
public void run() { try { if (myPreviousThread != null) myPreviousThread.join(); Thread.sleep(delay); log("> run MouseWheelThread " + amount); while (!hasFocus()) { Thread.sleep(1000); } int dir = 1; if (System.getProperty("os.name").toUpperCase().indexOf("MAC") != -1) { // yay for Apple dir = -1; } robot.setAutoDelay(Math.max(duration / Math.abs(amount), 1)); for (int i = 0; i < Math.abs(amount); i++) { robot.mouseWheel(amount > 0 ? dir : -dir); } robot.setAutoDelay(1); } catch (Exception e) { log("Bad parameters passed to mouseWheel"); e.printStackTrace(); } log("< run MouseWheelThread "); }
private GObject checkCorner(double x, double y) { GObject obj = getElementAt(x, y); // check the corner for GObject if (obj == paddle) { vy = -Math.abs(vy); PrecisionPaddle(); } else if (obj != null && obj != lifeCount) { // check if the ball hits a brick remove(obj); vy = -1.05 * vy; vx = 1.05 * vx; brickCount--; AudioClip bounceClip = MediaTools.loadAudioClip("bounce.au"); bounceClip.play(); } return obj; }
public void setFontSize(float size) { // FONT_SIZE.basicSet(this, new Double(size)); Point2D.Double p = new Point2D.Double(0, size); AffineTransform tx = TRANSFORM.get(this); if (tx != null) { try { tx.inverseTransform(p, p); Point2D.Double p0 = new Point2D.Double(0, 0); tx.inverseTransform(p0, p0); p.y -= p0.y; } catch (NoninvertibleTransformException ex) { ex.printStackTrace(); } } FONT_SIZE.set(this, Math.abs(p.y)); }