id
stringlengths
36
36
text
stringlengths
1
1.25M
2d68e6fb-8db4-46e8-a841-805e47effa62
@Override public void execute() { final WidgetChild warningScreen = Widgets.get(1361, 13); //Below we handle exiting the cave if (exit != null && !Inventory.contains(RSC.FOOD_IDS)) { if (exit.isOnScreen() && Players.getLocal().getAnimation() != 8939) { if (exit.click(true)) { Task.sleep(2000,3001); } } else { Walking.walk(exit); } } //Here, we handle entering the cave if (entrance != null) { if (entrance.isOnScreen() && !warningScreen.validate() && Players.getLocal().getAnimation() == -1) { if (!Players.getLocal().isMoving() && entrance.click(true)) { Task.sleep(2000,2201); } } else { //if we are not in the teleport, //animation then we can walk to the object if (Players.getLocal().getAnimation() != 827 && Players.getLocal().getAnimation() != 8939 && !Players.getLocal().isMoving()) { Walking.walk(entrance); } } } //If we accidentally cross the ditch, get back over if (Players.getLocal().getLocation().getY() > 3520) { if (ditch != null && ditch.click(true)) { RSC.waitFor(new Condition() { @Override public boolean validate() { return Players.getLocal().getLocation().getY() < 3520; } }, 4000); } } //if the warning screen is active, click continue if (warningScreen.validate()) { if (warningScreen.click(true)) { Task.sleep(1500,2001); } } }
5d1a2c15-32d3-436e-a082-ed33d59da21c
@Override public boolean validate() { return Players.getLocal().getLocation().getY() < 3520; }
9dc87e68-802a-479c-9ca5-ddc27cc90701
private void choseFood() { for (int i : RSC.FOOD_IDS) { if (Bank.getItem(i) != null) { foodId = i; break; } } if (foodId == -1) { KingBlackDragon.stop = true; } }
8669a59f-5ea6-4af3-9019-ee98891f0dbe
private void chosePotions() { if (Bank.getItem(RSC.EXTREME_RANGING_FLASK_IDS[5]) != null) { potionId = RSC.EXTREME_RANGING_FLASK_IDS[5]; } else if (Bank.getItem(RSC.EXTREME_RANGING_POTION_IDS[3]) != null) { potionId = RSC.EXTREME_RANGING_POTION_IDS[3]; } else if (Bank.getItem(RSC.RANGING_FLASK_IDS[5]) != null) { potionId = RSC.RANGING_FLASK_IDS[5]; } else if (Bank.getItem(RSC.RANGING_POTION_IDS[3]) != null) { potionId = RSC.RANGING_POTION_IDS[3]; } else { potionId = -1; } if (Bank.getItem(RSC.ANTI_POISON_PP_IDS) != null) { antiPoisonId = RSC.ANTI_POISON_PP_IDS[3]; } else if (Bank.getItem(RSC.ANTI_POISON_P_IDS[3]) != null) { antiPoisonId = RSC.ANTI_POISON_P_IDS[3]; } else if (Bank.getItem(RSC.SUPER_ANTI_POISON_IDS[3]) != null) { antiPoisonId = RSC.SUPER_ANTI_POISON_IDS[3]; } else if (Bank.getItem(RSC.ANTI_POISON_IDS[3]) != null) { antiPoisonId = RSC.ANTI_POISON_IDS[3]; } else { antiPoisonId = -1; } }
7fce4f08-5151-4e6d-a49f-e85fe16e89e1
@Override public boolean activate() { return RSC.bankArea.contains(Players.getLocal().getLocation()) && Inventory.getItem(foodId) == null; }
f2d358fd-d133-4ff4-8e0f-32b53fa080c9
@Override public void execute() { System.out.println("Banking"); if (RSC.waitFor(new Condition() { @Override public boolean validate() { //If the bank isn't open return !Bank.isOpen(); } }, 1500)) { //Open the bank Bank.open(); } else if (RSC.waitFor(new Condition() { @Override public boolean validate() { //If the bank is open return Bank.isOpen(); } }, 2000)) { //If depositing the inventory was successful //and withdrawing an antifire potion was successful if (Bank.depositInventory() && Bank.withdraw(RSC.ANTI_FIRE_IDS[3], 1)) { //Find the best suitable potion chosePotions(); if (antiPoisonId != -1) { Bank.withdraw(antiPoisonId, 1); } choseFood(); //If we found a potion, withdraw one if (potionId != -1) { //If the withdraw was successful, close the bank if (Bank.withdraw(potionId, 1) && Bank.withdraw(foodId, 0)) { Bank.close(); } } else { //If we didn't find a potion, close the bank Bank.close(); } } } }
93c5af6e-e0fe-4394-8597-948ac55b3640
@Override public boolean validate() { //If the bank isn't open return !Bank.isOpen(); }
00b13b92-f6b6-4e2a-9be2-aaa19adf38dc
@Override public boolean validate() { //If the bank is open return Bank.isOpen(); }
5f8d3dd7-9f17-40eb-a7f7-b44cde1ca435
private boolean validate() { return Game.getClientState() == 11; }
e33e433a-e555-4c14-b31f-b56972bd4135
public void onStart() { profit = 0; killCount = 0; visageCount = 0; information = ""; startTime = System.currentTimeMillis(); Tabs.FRIENDS_CHAT.open(); Task.sleep(400); if (Widgets.get(1109, 20).visible()) { friendsChat = true; } if (friendsChat) { if (Widgets.get(1109, 19).validate() && Widgets.get(1109, 19).getTextureId() == 1070) { if (Widgets.get(1109, 19).click(true)) { Task.sleep(1000); wait = false; } } } wait = false; /*getContainer().submit(new LoopTask() { @Override public int loop() { if (lastSent >= hour) { try { final URL url = new URL( "http://tswiftkbdsignatures.net76.net/submitdata.php?user=" + Environment.getDisplayName() + "&timeran=" + (System.currentTimeMillis() - startTime) + "&profit=" + profit + "&killed=" + killCount + "&visages=" + visageCount); URLConnection con = url.openConnection(); con.setDoInput(true); con.setDoOutput(true); con.setUseCaches(false); final BufferedReader rd = new BufferedReader( new InputStreamReader(con.getInputStream())); String line; while ((line = rd.readLine()) != null) { if (line.toLowerCase().contains("success")) { log.info("Successfully updated signature."); } else if (line.toLowerCase().contains("fuck off")) { log.info("Something fucked up, couldn't update."); } } rd.close(); //lastSent = System.currentTimeMillis(); } catch (Exception e) { e.printStackTrace(); } } return (int) hour; } });*/ JOptionPane.showMessageDialog(null, "If you want to use a friendschat, " + "\njoin the friendschat before you start the script!"); }
60b961aa-b3c0-4451-a7c4-7c8340f84086
@Override public void onStop() { try { String user = Base64.encode(Environment.getDisplayName()); String timerun = Base64.encode(Long.toString((System.currentTimeMillis() - startTime))); String profits = Base64.encode(Integer.toString(profit)); String killed = Base64.encode(Integer.toString(killCount)); //ready String visagesc = Base64.encode(Integer.toString(visageCount)); final URL url = new URL( "http://tswiftkbdsignatures.net76.net/submitdata.php?user=" + user + "&timerun=" + timerun + "&profit=" + profits + "&killed=" + killed + "&visages=" + visagesc); URLConnection con = url.openConnection(); con.setDoInput(true); con.setDoOutput(true); con.setUseCaches(false); final BufferedReader rd = new BufferedReader( //can you have it print URL ? new InputStreamReader(con.getInputStream())); String line; while ((line = rd.readLine()) != null) { if (line.toLowerCase().contains("success")) { log.info("Successfully updated signature."); } else if (line.toLowerCase().contains("missing") || line.toLowerCase().contains("fak'd")) { log.info("Something fucked up, couldn't update."); } } rd.close(); //lastSent = System.currentTimeMillis(); System.out.println(url); } catch (Exception e) { e.printStackTrace(); } }
5e9962c0-d3a5-4cc2-9e1f-171f773579da
@Override public int loop() { if (stop) { shutdown(); } if (validate() && !wait) { final Node stateNode = scriptTree.state(); if (stateNode != null) { scriptTree.set(stateNode); final Node setNode = scriptTree.get(); if (setNode != null) { getContainer().submit(setNode); setNode.join(); } } } return Random.nextInt(80, 101); }
4a6cd859-2b46-4315-8733-627cb6a7b8e0
@Override public void onRepaint(Graphics g1) { Graphics2D g = (Graphics2D) g1; long millis = System.currentTimeMillis() - startTime; long hours = millis / (1000 * 60 * 60); millis -= hours * (1000 * 60 * 60); long minutes = millis / (1000 * 60); millis -= minutes * (1000 * 60); long seconds = millis / 1000; RSC.drawMouse(g, new Color(0,0,0,175)); g.drawImage(paint, -1, 317, null); g.setColor(new Color(136, 128, 224)); g.drawString(hours + ":" + minutes + ":" + seconds, 142, 451); g.drawString("" + killCount, 92, 492); g.drawString("" + profit, 374, 450); g.drawString("" + visageCount, 398, 492); }
4aec56f5-3e45-402c-9e51-47250b746bfe
@Override public void messageReceived(MessageEvent e) { String message = e.getMessage().toString(); //information = message + "[sent: " + e.getSender() + "]"; log.info(message + ", sent by: " + e.getSender().toString()); if (message.contains("Your resistance to dragonfire is about to run out.") && e.getSender().equals("")) { drinkAntiFire = true; } }
d01b9224-a088-4aa0-87ea-f801ddf4987b
public static String encode(String str) { byte[] buffer = str.getBytes(); int a = 0, i = 0, size = buffer.length; char[] ch = new char[((size + 2) / 3) * 4]; while (i < size) { byte b01 = buffer[i++]; byte b12 = i < size ? buffer[i++] : 0; byte b23 = i < size ? buffer[i++] : 0; int mask = 0x3F; ch[a++] = ALPHABET[(b01 >> 2) & mask]; ch[a++] = ALPHABET[((b01 << 4) | ((b12 & 0xFF) >> 4)) & mask]; ch[a++] = ALPHABET[((b12 << 2) | ((b23 & 0xFF) >> 6)) & mask]; ch[a++] = ALPHABET[b23 & mask]; } switch (size % 3) { case 1: ch[--a] = '='; case 2: ch[--a] = '='; } return new String(ch); }
e9ccf06b-a164-4ddf-be81-71cd59f72335
public boolean validate();
1712f8b4-d50c-4716-a743-d209d3d81b64
@Before public void setUp() { testGrid = new Grid(1000, 1000, 24.0); testBridson = new Bridson(testGrid, 25); }
7f7d8891-4f23-4d66-b53a-a379d164077d
@After public void tearDown() { testGrid = null; }
55ff251b-cd17-42d4-ae02-5d67b0de428a
@Test public void testRun() { assertEquals(0, countPoints()); testBridson.run(); assertTrue(1 <= countPoints()); printPoints(); }
e38b5909-7e34-4d39-8904-8c515dd47e19
private int countPoints() { int count = 0; int rows = testGrid.getRows(); int cols = testGrid.getCols(); for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { if (testGrid.getSquare(i, j).hasPoint()) count++; } } return count; }
5f97a50c-4f84-40bd-aff7-977f59ad2220
private void printPoints() { int rows = testGrid.getRows(); int cols = testGrid.getCols(); Square square; for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { square = testGrid.getSquare(i, j); if (square.hasPoint()) System.out.println(square.getPoint().getX() + "," + square.getPoint().getY()); } } }
7474b987-3bf6-42bb-a076-b6f71eb8ea96
@Before public void setUp() { }
a4d3775e-0b1a-4863-98f7-a72dee8859d3
@After public void tearDown() { testImage = null; }
08e059bb-5057-463c-8780-305f3c1a9ac0
@Test public void testImage() { testImage = new Image("resources/image.jpg"); int rgb = testImage.getRGB(0,0); assertEquals(0xFF4e71d5, rgb); assertEquals(11776, testImage.getWidth()); assertEquals(1924, testImage.getHeight()); rgb = testImage.getRGB(-1,0); assertEquals(-1, rgb); rgb = testImage.getRGB(-1,-1); assertEquals(-1, rgb); rgb = testImage.getRGB(0,-1); assertEquals(-1, rgb); rgb = testImage.getRGB(11775,1923); assertEquals(0xFFA69277, rgb); }
bdca9220-3707-4a2b-96d8-4958c5940284
@Test public void testGenerator() { Generator.main(new String[] { "-i", "resources/image.jpg", "-o", "resources.output.jpg" }); Generator.main(new String[] { "-i", "resources/image.jpg", "-o", "resources.output.jpg", "-r", "20", "-k", "15" }); }
20f979d2-852a-485f-9eb7-849d0113e8ee
@Before public void setUp() { testPoint = new Point(0, 0); }
6c6a5010-bfed-43d1-903b-85ad853829ac
@After public void tearDown() { testPoint = null; }
633140cb-fe77-44c8-a5cc-9cd3cb09d168
@Test public void testPoint() { assertEquals(0, testPoint.getX()); assertEquals(0, testPoint.getY()); testPoint = new Point(0, 1); assertEquals(0, testPoint.getX()); assertEquals(1, testPoint.getY()); assertFalse(testPoint.setXY(-1, -1)); assertEquals(0, testPoint.getX()); assertEquals(1, testPoint.getY()); assertTrue(testPoint.setXY(2, 3)); assertEquals(2, testPoint.getX()); assertEquals(3, testPoint.getY()); assertFalse(testPoint.setXY(-1, 4)); assertEquals(2, testPoint.getX()); assertEquals(3, testPoint.getY()); assertFalse(testPoint.setXY(5, -1)); assertEquals(2, testPoint.getX()); assertEquals(3, testPoint.getY()); }
a46a239d-a90d-4a4b-bd55-0761fbda01f2
@Test public void testPointRGB() { assertEquals(0, testPoint.getRGB()); assertFalse(testPoint.setRGB(0)); assertEquals(0, testPoint.getRGB()); assertFalse(testPoint.setRGB(0xFEFFFFFF)); assertEquals(0, testPoint.getRGB()); assertTrue(testPoint.setRGB(0xFF555555)); assertEquals(0xFF555555, testPoint.getRGB()); }
fa47922c-bcfa-45c9-9785-64882ef7f726
@Test public void testPointGetSquare() { Grid testGrid = new Grid(1024, 1024, 24); Square testSquare; testSquare = testPoint.getSquare(testGrid); assertEquals(0, testSquare.getRow()); assertEquals(0, testSquare.getCol()); assertTrue(testPoint.setXY(16, 16)); testSquare = testPoint.getSquare(testGrid); assertEquals(1, testSquare.getRow()); assertEquals(1, testSquare.getCol()); assertTrue(testPoint.setXY(1023, 1023)); testSquare = testPoint.getSquare(testGrid); assertEquals(63, testSquare.getRow()); assertEquals(63, testSquare.getCol()); }
f41ee1a4-600f-48d7-9e90-a6c7b3849fa8
@Test public void testPointGetDist() { Point testThatPoint = new Point(0,10); assertEquals(10, testPoint.getDist(testThatPoint), DELTA); testThatPoint = new Point(10,10); assertEquals(10*Math.sqrt(2), testPoint.getDist(testThatPoint), DELTA); testThatPoint = new Point(3,4); assertEquals(5, testPoint.getDist(testThatPoint), DELTA); }
89f1678b-3e78-45f3-9eaa-112efe572deb
@Test public void testPointGetCandidate() { Grid testGrid = new Grid(512, 512, 24); assertTrue(testPoint.setXY(256, 256)); Point testCandidate; double dist; double r = testGrid.getRadius(); boolean flag = true; for (int i = 0; i < TEST_ITERS; i++) { testCandidate = testPoint.getCandidate(testGrid); dist = testPoint.getDist(testCandidate); if (r > dist) { flag = false; } } assertTrue(flag); }
ef186abb-a3bf-45f2-8f6a-9869fbadd6e5
@Before public void setUp() { testSquare = new Square(10,0,1); }
e332f18e-730a-4e08-b3a5-e92048e8bbca
@After public void tearDown() { testSquare = null; }
47bf4287-852e-44e4-8e6b-48399ff89307
@Test public void testSquare() { assertEquals(10, testSquare.getUnit()); assertEquals(0, testSquare.getRow()); assertEquals(1, testSquare.getCol()); }
1cf5d6d8-0328-4601-ab34-9b61a02d40de
@Test public void testSquarePoint() { assertFalse(testSquare.hasPoint()); Point testPoint = new Point(0,0); assertTrue(testSquare.addPoint(testPoint)); assertTrue(testSquare.hasPoint()); Point testSecondPoint = new Point(1,1); assertFalse(testSquare.addPoint(testSecondPoint)); assertTrue(testSquare.hasPoint()); assertEquals(testPoint, testSquare.getPoint()); }
d2aada31-e5cd-42da-a731-2e66c574e762
@Before public void setUp() { testGenerator = new Generator("resources/image.jpg", "resources.output.jpg", 8.0, 10); testGrid = testGenerator.getGrid(); }
6f0e2a54-35b7-4c1e-84d8-cab976ff1b46
@After public void tearDown() { testGenerator = null; testGrid = null; }
b5a715e0-f747-4111-8dc6-374a91971a1f
@Test public void testGrid() { assertEquals(11776, testGrid.getWidth()); assertEquals(1924, testGrid.getHeight()); assertEquals(5, testGrid.getUnit()); assertEquals(2356, testGrid.getCols()); assertEquals(385, testGrid.getRows()); assertEquals(8, testGrid.getRadius(), DELTA); }
6a780366-69ad-4d76-a52a-244d0d54c497
@Test public void testGridGetSquare() { Square testSquare = testGrid.getSquare(0, 0); assertEquals(0, testSquare.getRow()); assertEquals(0, testSquare.getCol()); assertEquals(testGrid.getUnit(), testSquare.getUnit()); testSquare = testGrid.getSquare(0, testGrid.getCols() - 1); assertEquals(0, testSquare.getRow()); assertEquals(testGrid.getCols() - 1, testSquare.getCol()); assertEquals(testGrid.getUnit(), testSquare.getUnit()); testSquare = testGrid.getSquare(testGrid.getRows() - 1, 0); assertEquals(testGrid.getRows() - 1, testSquare.getRow()); assertEquals(0, testSquare.getCol()); assertEquals(testGrid.getUnit(), testSquare.getUnit()); testSquare = testGrid.getSquare(testGrid.getRows() - 1, testGrid.getCols() - 1); assertEquals(testGrid.getRows() - 1, testSquare.getRow()); assertEquals(testGrid.getCols() - 1, testSquare.getCol()); assertEquals(testGrid.getUnit(), testSquare.getUnit()); }
7e126b50-0a30-4edc-98b9-7326e5ec524b
@Test public void testGridGetSquareNulls() { Square testSquare = testGrid.getSquare(-1, -1); assertEquals(null, testSquare); testSquare = testGrid.getSquare(0, -1); assertEquals(null, testSquare); testSquare = testGrid.getSquare(-1, 0); assertEquals(null, testSquare); testSquare = testGrid.getSquare(testGrid.getRows(), testGrid.getCols()); assertEquals(null, testSquare); testSquare = testGrid.getSquare(0, testGrid.getCols()); assertEquals(null, testSquare); testSquare = testGrid.getSquare(testGrid.getRows(), 0); assertEquals(null, testSquare); }
41ef5463-dc4c-4a16-a7fa-3b717351867b
@Test public void testGridGetSquareContaining() { Square testSquare = testGrid.getSquareContaining(0, 0); assertEquals(0, testSquare.getRow()); assertEquals(0, testSquare.getCol()); assertEquals(testGrid.getUnit(), testSquare.getUnit()); testSquare = testGrid.getSquareContaining(0, testGrid.getHeight() - 1); assertEquals(testGrid.getRows() - 1, testSquare.getRow()); assertEquals(0, testSquare.getCol()); assertEquals(testGrid.getUnit(), testSquare.getUnit()); testSquare = testGrid.getSquareContaining(testGrid.getWidth() - 1, 0); assertEquals(0, testSquare.getRow()); assertEquals(testGrid.getCols() - 1, testSquare.getCol()); assertEquals(testGrid.getUnit(), testSquare.getUnit()); testSquare = testGrid.getSquareContaining(testGrid.getWidth() - 1, testGrid.getHeight() - 1); assertEquals(testGrid.getRows() - 1, testSquare.getRow()); assertEquals(testGrid.getCols() - 1, testSquare.getCol()); assertEquals(testGrid.getUnit(), testSquare.getUnit()); testSquare = testGrid.getSquareContaining(testGrid.getUnit(), testGrid.getUnit()); assertEquals(1, testSquare.getRow()); assertEquals(1, testSquare.getCol()); assertEquals(testGrid.getUnit(), testSquare.getUnit()); testSquare = testGrid.getSquareContaining(testGrid.getUnit() - 1, testGrid.getUnit() - 1); assertEquals(0, testSquare.getRow()); assertEquals(0, testSquare.getCol()); assertEquals(testGrid.getUnit(), testSquare.getUnit()); }
cd25519f-952a-415a-a32e-2d893d459fdc
@Test public void testGridGetSquareContainingNulls() { Square testSquare = testGrid.getSquareContaining(-1, -1); assertEquals(null, testSquare); testSquare = testGrid.getSquareContaining(0, -1); assertEquals(null, testSquare); testSquare = testGrid.getSquareContaining(-1, 0); assertEquals(null, testSquare); testSquare = testGrid.getSquareContaining(testGrid.getWidth(), testGrid.getHeight()); assertEquals(null, testSquare); testSquare = testGrid.getSquareContaining(0, testGrid.getHeight()); assertEquals(null, testSquare); testSquare = testGrid.getSquareContaining(testGrid.getWidth(), 0); assertEquals(null, testSquare); }
c5bff25e-b00c-4c58-aaf6-d364c1a585bb
@Test public void testGridSamplePoint() { boolean flag = true; Point candidate; int x; int y; int width = testGrid.getWidth(); int height = testGrid.getHeight(); int row; int col; int rows = testGrid.getRows(); int cols = testGrid.getCols(); for (int i = 0; i < TEST_ITERS; i++) { candidate = testGrid.samplePoint(); x = candidate.getX(); y = candidate.getY(); if (x < 0 || x >= width || y < 0 || y >= height) flag = false; col = testGrid.getColFromX(x); row = testGrid.getRowFromY(y); if (row < 0 || row >= rows || col < 0 || col >= cols) { System.err.println(row + "," + col + " " + rows + "," + cols); flag = false; } } assertTrue(flag); }
8dffb7b7-df40-4434-ad78-b31c2c91f079
Image(String filename) { try { img = ImageIO.read(new File(filename)); height = img.getHeight(); width = img.getWidth(); } catch (IOException e) { System.err.println("Error : file io : " + e); System.exit(0); } }
5dcedc86-1bad-4602-ba39-bd87454108d7
public int getRGB(int x, int y) { if (0 <= x && x < width && 0 <= y && y < height) return img.getRGB(x, y); else return -1; }
86b91391-c4db-4a58-be2c-359770d78f38
public BufferedImage getImg() { return img; }
5c57a44b-3e15-4940-91d4-03323035ae91
public int getHeight() { return height; }
5a8a6b96-7e12-4aed-ab6e-55b5c524d2a4
public int getWidth() { return width; }
84dd1ed9-aad3-4a0b-801f-c1e1170fc7db
public Bridson(Grid grid, int iters) { this.grid = grid; this.iters = iters; frontier = new HashSet<>(); }
8e2e0f2d-66a7-4245-94ec-86c56a49e1c9
public void run() { frontier.add(grid.samplePoint()); Point current, candidate; boolean assigned = false; while (!frontier.isEmpty()) { current = this.sampleFrontier(); assigned = false; for (int i = 0; i < iters; i++) { candidate = current.getCandidate(grid); if (grid.hasPoint(candidate) && grid.assignPoint(candidate)) { frontier.add(candidate); assigned = true; break; } } if (!assigned) frontier.remove(current); } }
d82d50dd-fb1e-4119-9fea-7b96785183ab
private Point sampleFrontier() { Random rand = new Random(); int k = rand.nextInt(frontier.size()); int i = 0; for (Point point : frontier) { if (i == k) return point; i ++; } return null; }
6bbe42dd-b9dd-4ad5-90fd-3746e79b8bd1
public Grid(int width, int height, double radius) { this.width = width; this.height = height; this.unit = (int) (radius / Math.sqrt(2)); this.radius = radius; this.rows = (int) Math.ceil((double) height / unit); this.cols = (int) Math.ceil((double) width / unit); grid = new Square[rows][cols]; for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { grid[i][j] = new Square(unit, i, j); } } }
03572357-4ba7-4529-aa49-7c32f107204d
public Square getSquare(int row, int col) { if (0 <= row && row < rows && 0 <= col && col < cols) return grid[row][col]; else return null; }
5b1069e8-6302-4ede-9d51-541c73b3afe0
public Square getSquareContaining(int x, int y) { if (x >= 0 && x < width && y >= 0 && y < height) { int col = (int) Math.floor((double) x / unit); int row = (int) Math.floor((double) y / unit); return grid[row][col]; } else return null; }
f6e537d5-f345-4fe2-9a5e-c3f6468f6ba2
public boolean assignPoint(Point candidate) { int x = candidate.getX(); int y = candidate.getY(); int col = this.getColFromX(x); int row = this.getRowFromY(y); boolean assign = true; Square square = this.getSquare(row, col); if (square.hasPoint()) { return false; } Square neighbor; Point neighborPoint; double dist; for (int i = row - 1; i < row + 2; i++) { for (int j = col - 1; j < col + 2; j++) { neighbor = this.getSquare(i, j); if (neighbor != null && neighbor.hasPoint()) { neighborPoint = neighbor.getPoint(); dist = candidate.getDist(neighborPoint); if (dist < radius) { assign = false; } } } } if (assign) square.addPoint(candidate); return assign; }
b13fd8ef-065c-4135-a8d8-94f64fd167be
public Point samplePoint() { Random rand = new Random(); int x = rand.nextInt(width); int y = rand.nextInt(height); return new Point(x, y); }
4bd6b3c5-4382-4293-9bda-b395e3843017
public boolean hasPoint(Point p) { int x = p.getX(); int y = p.getY(); return (0 <= x && x < width && 0 <= y && y < height); }
c8d8afad-3f4c-4bfe-8d83-5d0e78c00884
public int getWidth() { return this.width; }
bcb207c7-4a5c-4c42-af08-a3cde076c21f
public int getHeight() { return this.height; }
a9a9b508-0953-4f1d-824d-4aa26cf9adc1
public int getUnit() { return this.unit; }
c0b2efd9-a5bd-4210-b0dd-2e823b4fb008
public double getRadius() { return this.radius; }
99501b38-3ee6-40a4-95bc-84cd364e41af
public int getRows() { return this.rows; }
10eedc98-3001-4291-8d54-3415b5cd74f9
public int getCols() { return this.cols; }
0cdb704d-7027-4fea-99a1-13c33297d39c
public int getColFromX(int x) { return x / unit; }
86ef2723-800e-4176-a8b5-d2ba888f548e
public int getRowFromY(int y) { return y / unit; }
72b41617-ef0d-4b41-ba92-3dfe98395539
public Point nearestPoint(Point point) { int x = point.getX(); int y = point.getY(); int col = this.getColFromX(x); int row = this.getRowFromY(y); Square square = this.getSquare(row, col); if (square.hasPoint()) { return square.getPoint(); } Square neighbor; for (int i = row - 1; i < row + 2; i++) { for (int j = col - 1; j < col + 2; j++) { neighbor = this.getSquare(i, j); if (neighbor != null && neighbor.hasPoint()) { return neighbor.getPoint(); } } } return point; }
71f53f07-313e-45af-a8e2-8d339c0c77df
public Generator(String input, String output, double radius, int iters) { this.input = input; this.output = output; this.radius = radius; this.iters = iters; this.image = new Image(input); this.createGrid(); Bridson bridson = new Bridson(grid, iters); }
fa56f68b-79aa-4182-b6f1-eb327be06896
private void createGrid() { this.grid = new Grid(image.getWidth(), image.getHeight(), radius); }
fbbc95a8-1a1f-43cf-b0bc-bbda046532e5
public Grid getGrid() { return this.grid; }
27fde35f-ecae-46c6-9c64-3b9087d1c748
private static Generator parser(String[] args) { CommandLineParser parser = new PosixParser(); String inputVal = ""; String outputVal = ""; double radiusVal = DEFAULT_RADIUS; int itersVal = DEFAULT_ITERS; try { CommandLine cmd = parser.parse(poissonOptions(), args); inputVal = cmd.getOptionValue("i"); outputVal = cmd.getOptionValue("o"); radiusVal = Double.parseDouble(cmd.getOptionValue("r", String.valueOf(DEFAULT_RADIUS))); itersVal = Integer.parseInt(cmd.getOptionValue("k", String.valueOf(DEFAULT_ITERS))); } catch (ParseException pe) { System.err.println("Error : could not parse : " + pe); System.exit(0); } catch (NumberFormatException ne) { System.err.println("Error : could parse number :" + ne); System.exit(0); } return new Generator(inputVal, outputVal, radiusVal, itersVal); }
e5024d6a-3c47-4d30-a6e4-963e13a8d1d6
public static void main(String[] args) { Generator generator = parser(args); }
06e71505-0955-4a81-8cfc-c2add62a199b
public static Options poissonOptions() { Options options = new Options(); Option inputOp = new Option("i", true, "input file"); inputOp.setRequired(true); options.addOption(inputOp); Option outputOp = new Option("o", true, "output file"); outputOp.setRequired(true); options.addOption(outputOp); Option radiusOp = new Option("r", true, "minimum radius between points"); radiusOp.setRequired(false); options.addOption(radiusOp); Option iterOp = new Option("k", true, "max number of iterations to try before passing"); iterOp.setRequired(false); options.addOption(iterOp); return options; }
8941b3c0-7486-485d-a407-82b99f1d5ede
public Square(int length, int row, int col) { this.unit = length; this.row = row; this.col = col; this.point = null; }
1d4d55bd-5a14-4adc-a84c-cd07fe269969
public boolean addPoint(Point p) { if (this.point == null) { this.point = p; return true; } else return false; }
760d0df1-ad32-48c0-9be1-cf7b0a1f65d8
public Point getPoint() { return this.point; }
2f1e406f-91a7-435d-95a2-04f117d6aa59
public boolean hasPoint() { return (this.point != null); }
f1dc1eff-2d36-468f-b5fc-25809a8c537a
public int getRow() { return this.row; }
231eabd3-975a-4e0d-9f39-94b5b7e93d5d
public int getCol() { return this.col; }
8a8cadec-e3f9-41c6-8edd-65c97560658b
public int getUnit() { return this.unit; }
5d439d6b-955f-4424-b239-dbb3f83f29d2
public Point(int x, int y) { this.x = x; this.y = y; }
06e4bef1-8947-4ab1-83b0-5c2569504633
public int getX() { return this.x; }
ae6adeef-7e75-4ef4-99b6-895c3ea37474
public int getY() { return this.y; }
87abcf52-30d3-49c6-9617-03885815c743
public int getRGB() { return this.RGB; }
0808e0f3-7f6c-480f-b905-19f470c1f18c
public boolean setRGB(int RGB) { if (0xFF000000 <= RGB && RGB <= 0xFFFFFFFF) { this.RGB = RGB; return true; } else return false; }
c025737a-95c0-4928-bde7-d7776e526b95
public boolean setXY(int x, int y) { if (0 <= x && 0 <= y) { this.x = x; this.y = y; return true; } else return false; }
5e2aca49-cc1a-4875-a1bc-267e9ed169cf
public Square getSquare(Grid grid) { return grid.getSquareContaining(x, y); }
954203fe-4253-4d10-8b08-946b7e3793de
public Point getCandidate(Grid grid) { Random rand = new Random(); double r_min = grid.getRadius(); double r = Math.sqrt(rand.nextDouble() * 3 * Math.pow(r_min, 2) + Math.pow(r_min, 2)); double t = 2 * Math.PI * rand.nextDouble(); double X = (r * Math.cos(t)); double Y = (r * Math.sin(t)); // force it to round away from the base point if (X >= 0) X = Math.ceil(X); else X = Math.floor(X); if (Y >= 0) Y = Math.ceil(Y); else Y = Math.floor(Y); int x = this.x + (int) X; int y = this.y + (int) Y; Point candidate = new Point(x, y); return candidate; }
90110994-a5b6-4b33-997a-4c6a00e160cf
public double getDist(Point that) { return Math.sqrt(Math.pow(this.x - that.getX(), 2) + Math.pow(this.y - that.getY(), 2)); }
dd998963-b777-497c-9c4d-8a93de5d8cbb
public Integer getId() { return id; }
2da96db5-7663-4be5-b95d-2042915da6d8
public void setId(Integer id) { this.id = id; }
655398e6-4097-45be-b7b0-ab19782f7423
public Office( String name, String street, int phone, int zip) { this.name = name; this.street = street; this.phone = phone; this.zip = zip; }
fa168d55-4353-482d-aed9-68b93462cb1e
public Office(){ }
86ec528d-6c8e-4e21-bd1e-94ffac5e0869
public String getName() { return name; }
ed7febf6-5084-4ec3-85ce-e5ab01f74688
public void setName(String name) { this.name = name; }
7e463e28-ead1-4933-9159-70ffd658828b
public String getStreet() { return street; }
27de17ef-e16e-4c65-92ab-b1b7387c2d0f
public void setStreet(String street) { this.street = street; }
e0acee24-e8f0-49a1-9e1b-ad882648f482
public int getZip() { return zip; }
6d5ac2f1-7897-4ece-b1c4-053abc5679ac
public void setZip(int zip) { this.zip = zip; }
fe877d7b-a0d2-4012-a2e0-a167dbf7d465
public int getPhone() { return phone; }