void generateBackground(int size) { backgroundWidth = 100; int spacing = backgroundWidth; int id = 0; for (int i = 0; i < bounds.getWidth() / spacing; i++) { background[id][0] = spacing * (i + 1) - bounds.getWidth() / 2; background[id][1] = -bounds.getHeight() / 2; background[id][2] = spacing * (i + 1) - bounds.getWidth() / 2; background[id][3] = 0; background[id][4] = spacing * (i + 1) - bounds.getWidth() / 2; background[id][5] = bounds.getHeight(); background[id][6] = rand.nextInt(3) - 1; background[id][7] = rand.nextInt(3) - 1; background[id][8] = 1; id++; } for (int i = 0; i < bounds.getHeight() / spacing; i++) { background[id][0] = -bounds.getHeight() / 2; background[id][1] = spacing * (i + 1) - bounds.getHeight() / 2; background[id][2] = 0; background[id][3] = spacing * (i + 1) - bounds.getWidth() / 2; background[id][4] = bounds.getWidth(); background[id][5] = spacing * (i + 1) - bounds.getHeight() / 2; background[id][6] = rand.nextInt(3) - 1; background[id][7] = rand.nextInt(3) - 1; background[id][8] = 1; id++; } }
void enemieHandeler() { int ran = (int) ((70 - difficulty) * delta); if (ran <= 0) return; if (rand.nextInt(ran) == 1) { int x = rand.nextInt(2); int y = rand.nextInt(2); int size = rand.nextInt(1000) + 50; if (x == 0 && y == 0) if (rand.nextBoolean()) x = rand.nextInt(4) + 1; else y = rand.nextInt(4) + 1; if (rand.nextBoolean()) x = -x; if (rand.nextBoolean()) y = -y; size = size * (rand.nextInt(difficulty) + 1); x = (int) (x * 400 + player.body.getCenterX()); y = (int) (y * 400 + player.body.getCenterY()); int type = 0; if (rand.nextInt(60 / difficulty) <= 1) type = rand.nextInt(3) + 1; spawnEnemie(x, y, size, type); } }
void itemHandeler(Graphics2D map) { boolean tmp = false; if (rand.nextInt((int) (300 * delta + difficulty * 40)) <= 1 && tmp) { int x = rand.nextInt(4) - 2; int y = rand.nextInt(4) - 2; int type = 1; if (x == 0 && y == 0) { x = 0; y = 1; } if (rand.nextInt(10) == 1) { type = 2; } if (rand.nextInt(5) == 1) for (int i = 0; i < player.weapon.length; i++) if (player.weapon[i][11] != null && (Boolean) player.weapon[i][11] == true) if ((Integer) player.weapon[i][10] < 5) type = 3; spawnItem(player.body.getCenterX() + 200 * x, player.body.getCenterY() + 200 * y, type); } for (int i = 1; i < items.length; i++) { if (items[i] != null) { if (items[i].body == null) { items[i] = null; } else { items[i].Runtime(map, player, delta); } } } }
public BufferedImage filter(BufferedImage src, BufferedImage dst) { if (dst == null) dst = createCompatibleDestImage(src, null); int width = src.getWidth(); int height = src.getHeight(); int numScratches = (int) (density * width * height / 100); ArrayList<Line2D> lines = new ArrayList<Line2D>(); { float l = length * width; Random random = new Random(seed); Graphics2D g = dst.createGraphics(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setColor(new Color(color)); g.setStroke(new BasicStroke(this.width)); for (int i = 0; i < numScratches; i++) { float x = width * random.nextFloat(); float y = height * random.nextFloat(); float a = angle + ImageMath.TWO_PI * (angleVariation * (random.nextFloat() - 0.5f)); float s = (float) Math.sin(a) * l; float c = (float) Math.cos(a) * l; float x1 = x - c; float y1 = y - s; float x2 = x + c; float y2 = y + s; g.drawLine((int) x1, (int) y1, (int) x2, (int) y2); lines.add(new Line2D.Float(x1, y1, x2, y2)); } g.dispose(); } if (false) { // int[] inPixels = getRGB( src, 0, 0, width, height, null ); int[] inPixels = new int[width * height]; int index = 0; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { float sx = x, sy = y; for (int i = 0; i < numScratches; i++) { Line2D.Float l = (Line2D.Float) lines.get(i); float dot = (l.x2 - l.x1) * (sx - l.x1) + (l.y2 - l.y1) * (sy - l.y1); if (dot > 0) inPixels[index] |= (1 << i); } index++; } } Colormap colormap = new LinearColormap(); index = 0; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { float f = (float) (inPixels[index] & 0x7fffffff) / 0x7fffffff; inPixels[index] = colormap.getColor(f); index++; } } setRGB(dst, 0, 0, width, height, inPixels); } return dst; }
public void setRandom(Random random) /* Sets all the scalars in 'this' to random values uniformly distributed * over (0.0, 1.0) using the pseudo-random generator 'random'. */ { // setZero(); for (int k = 0; k < size; ++k) f[k] = random.nextFloat(); }
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); } } } } }
public ScalarImage(int width, int height, Random random) /* Constructs a new ScalarImage = < width, height, zero-buffer > */ { this.width = width; this.height = height; size = width * height; f = new float[size]; offset = new int[height]; for (int j = 0; j < height; ++j) offset[j] = width * j; for (int k = 0; k < size; ++k) f[k] = random.nextFloat(); }
// private void colorSCC (ArrayList<Position> vertexSet, Color color) private void colorSCC() { /* for (Position p:vertexSet) { setVertexColor (p, color); }*/ java.util.List<Set<Position>> sccs = new ConnectivityInspector<Position, DefaultEdge>(graph).connectedSets(); for (Set<Position> s : sccs) { Color color = new Color(randGen.nextInt()); for (Position p : s) { setVertexColor(p, color); } } }
public boolean dialogItemChanged(GenericDialog gd, AWTEvent e) { int width = imp.getWidth(); int height = imp.getHeight(); type = gd.getNextChoice(); areaPerPoint = gd.getNextNumber(); color = gd.getNextChoice(); randomOffset = gd.getNextBoolean(); double minArea = (width * height) / 50000.0; if (type.equals(types[1]) && minArea < 144.0) minArea = 144.0; else if (minArea < 16) minArea = 16.0; if (areaPerPoint / (pixelWidth * pixelHeight) < minArea) { String err = "\"Area per Point\" too small"; if (gd.wasOKed()) IJ.error("Grid", err); else IJ.showStatus(err); return true; } double tileSize = Math.sqrt(areaPerPoint); tileWidth = tileSize / pixelWidth; tileHeight = tileSize / pixelHeight; if (randomOffset) { xstart = (int) (random.nextDouble() * tileWidth); ystart = (int) (random.nextDouble() * tileHeight); } else { xstart = (int) (tileWidth / 2.0 + 0.5); ystart = (int) (tileHeight / 2.0 + 0.5); } linesV = (int) ((width - xstart) / tileWidth) + 1; linesH = (int) ((height - ystart) / tileHeight) + 1; if (gd.invalidNumber()) return true; if (type.equals(types[0])) drawLines(); else if (type.equals(types[1])) drawCrosses(); else if (type.equals(types[2])) drawPoints(); else showGrid(null); return true; }
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); } } }