// This is where the shit really goes down public static void moveThroughMaze(Room room, Robot robby, Picture pic) { while (!(robby.get_xpos() == destX) || !(robby.get_ypos() == destY)) { if (destX > robby.get_xpos()) { robby.face_right(); if (robby.ahead_is_colour(room, Room.WHITE)) { robby.move(); pic.draw(room, robby); } else { if (destY > robby.get_ypos()) { robby.face_up(); if (!robby.ahead_is_colour(room, Room.WHITE)) { robby.face_left(); if (!robby.ahead_is_colour(room, Room.WHITE)) { robby.face_down(); robby.move(); pic.draw(room, robby); } else { robby.move(); pic.draw(room, robby); } } else { robby.move(); pic.draw(room, robby); } } } } else { if (destY > robby.get_ypos()) { robby.face_up(); } } } System.out.println("Success!"); }
@Override public String toXML() { StringBuffer buffer = new StringBuffer(); buffer.append("<event>"); buffer.append(super.toXML()); buffer.append("<name>" + name + "</name>"); buffer.append("<location>" + location + "</location>"); buffer.append("<type>" + type + "</type>"); buffer.append("<other>" + other + "</other>"); buffer.append("<description>" + description + "</description>"); buffer.append("<dateTime>" + Utilities.getISODate(this.dateTime) + "</dateTime>"); buffer.append("<pictures>"); for (Picture picture : pictures) { buffer.append(picture.toXML()); } buffer.append("</pictures>"); buffer.append("<children>"); for (Person child : children) { buffer.append(child.toXML("child")); } buffer.append("</children>"); buffer.append("</event>"); return buffer.toString(); }
/** Test Main. It will explore Splatoon! */ public static void main(String args[]) { // Picture pix = new Picture("snowman.jpg"); Picture pix = new Picture("splatoon.jpg"); Picture smallPic = pix.scale(.5, .48); smallPic.explore(); smallPic.write("smallSplatoon.jpg"); }
public static void main(String[] a) { Picture p = new Picture("/home/seth/black.jpg"); p.vignette(); p.show(); Scanner sc = new Scanner(System.in); String n = sc.next(); System.exit(0); }
@Override public String toString() { if (picture.getName() == null) { return "picture is going to be retrieved..."; } else { return picture.getFormat() + " " + picture.getName() + " " + new String(picture.getImage()); } }
/** Return all the pictures with a given resolution on width. @ param List<Picture> */ public List<Picture> getAll(int wResolution) { List result = new ArrayList(); for (Picture p : pictures) { if (p.getWResolution() == wResolution) { result.add(p); } } return result; }
/** Method to test the collage method */ public static void testCollage() { Picture canvas = new Picture(850, 1300); // Picture beach = new Picture("beach.jpg"); // beach.sepia(); // beach.explore(); canvas.createCollage(); canvas.explore(); canvas.write("rarePepes.jpg"); }
public static void main(String[] args) { FileChooser.setMediaPath("/home/linux/ieng6/cs8w/cs8wfs/Desktop/mediasources/"); Picture input1 = new Picture("bird1.jpg"); input1.explore(); Picture redBird = input1.greenToRed(); redBird.show(); }
public static void main(String[] args) { Picture p = new Picture(FileChooser.getMediaPath("horse.jpg")); Graphics g = p.getGraphics(); Point ul = new Point(68, 24); Point te = new Point(182, 123); String message = "This is a test." + " Of a message with more than one line in it."; SpeechBalloon balloon = new SpeechBalloon(ul, 200, te, message); balloon.draw(g); p.show(); }
public SeamCarver(Picture picture) { this.picture = new Picture(picture); energy = new double[picture.width()][picture.height()]; parent = new int[picture.width()][picture.height()]; for (int y = 0; y < height(); y++) { for (int x = 0; x < width(); x++) { energy[x][y] = energy(x, y); } } }
public Picture getPicture(Picture picture) { for (Picture p : this.pictures) { if (p.equals(picture)) { return p; } } return null; }
public Picture getMainPic() { for (Picture p : this.pictures) { if (p.getMain()) { return p; } } return null; }
public static void showGallery(Long id, String name) { notFoundIfNull(id); Gallery gallery = Gallery.findById(id); notFoundIfNull(gallery); List<Picture> pictures = gallery.getPictures(); List<ImageView> images = new ArrayList<ImageView>(); for (Picture picture : pictures) images.add(picture.toImageView()); render("Application/gallery.html", images, gallery); }
public SampleView(Context context) { super(context); setFocusable(true); setFocusableInTouchMode(true); mPicture = new Picture(); drawSomething(mPicture.beginRecording(200, 100)); mPicture.endRecording(); mDrawable = new PictureDrawable(mPicture); }
/** * The energy of pixel (x, y) is Δx^2(x, y) + Δy^2(x, y) * * @param x The pixel at column x * @param y The pixel at column y * @return The energy of pixel at column x and row y in current picture */ public double energy(int x, int y) { if (x < 0 || x > width() - 1 || y < 0 || y > height() - 1) { throw new IndexOutOfBoundsException(); } if (x == 0 || x == width() - 1 || y == 0 || y == height() - 1) { return MAX_ENERGY; } double xDiff = gradient(picture.get(x - 1, y), picture.get(x + 1, y)); double yDiff = gradient(picture.get(x, y - 1), picture.get(x, y + 1)); return xDiff + yDiff; }
public static void main(String[] args) { System.out.println("Test3: "); Picture pic = new Picture(); pic.loadFromFile("in.txt"); pic.setValue(0, 0, 123); if (pic.getValue(0, 0) == 123) System.out.println("OK"); else System.out.println("Fail"); }
public static void main(String[] args) { Picture inputImg = new Picture(args[0]); System.out.printf("image is %d columns by %d rows\n", inputImg.width(), inputImg.height()); inputImg.show(); SeamCarver sc = new SeamCarver(inputImg); System.out.printf("Displaying horizontal seam calculated.\n"); showHorizontalSeam(sc); System.out.printf("Displaying vertical seam calculated.\n"); showVerticalSeam(sc); }
public SeamCarver(Picture picture) { // create a seam carver object based on the given picture int picWidth = picture.width(); int picHeight = picture.height(); currentPicture = picture; pixelColor = new Color[picWidth][picHeight]; for (int i = 0; i < picHeight; i++) { for (int j = 0; j < picWidth; j++) { pixelColor[j][i] = picture.get(j, i); } } }
public static void main(String[] args) { Room room = new Room(8); Robot robby = new Robot(); Picture pic = new Picture(room, robby); pic.draw(room, robby); printCoords(robby); // Set end point setDestination(room); // Start solving // moveThroughMaze(room,robby,pic); aStar(room, robby, pic); }
/* Main method for testing - each class in Java can have a main * method */ public static void main(String[] args) { Picture desert = new Picture("Desert.jpg"); Picture koala = new Picture("Koala.jpg"); // beach.explore(); // beach.zeroBlue(); // desert.chromakey(koala); // desert.sepia(25, 3); koala.sepia(); // desert.encode("ABCDEFGHIJKLMNOPasdfgwe6"); // System.out.println(desert.decode()); // desert.explore(); koala.explore(); }
/** Method to create a collage of several pictures */ public void createCollage() { Picture flower1 = new Picture("flower1.jpg"); Picture flower2 = new Picture("flower2.jpg"); this.copy(flower1, 0, 0); this.copy(flower2, 100, 0); this.copy(flower1, 200, 0); Picture flowerNoBlue = new Picture(flower2); flowerNoBlue.zeroBlue(); this.copy(flowerNoBlue, 300, 0); this.copy(flower1, 400, 0); this.copy(flower2, 500, 0); this.mirrorVertical(); this.write("collage.jpg"); }
public void exportGraphic(Picture picture, OutputStream out) throws IOException { int width = picture.getPictureWidth(); int height = picture.getPictureHeight(); Document doc = new Document(new com.lowagie.text.Rectangle(width, height)); try { PdfWriter pWriter = PdfWriter.getInstance(doc, out); doc.open(); Graphics2D g = pWriter.getDirectContent().createGraphics(width, height); picture.paintPicture(g); g.dispose(); doc.close(); } catch (DocumentException e) { throw (IOException) new IOException(e.getMessage()).initCause(e); } }
/* Create a Picture object from image data * in a 2D array of ints. This is primarily * a helper method for show() and save(), * but is declared public because it is * useful in its own right. */ public static Picture getPicture(int[][] img) { if (img == null) return null; if (img.length == 0) return null; if (img[0].length == 0) return null; Picture p = new Picture(img[0].length, img.length); for (int row = 0; row < img.length; row++) { for (int col = 0; col < img[0].length; col++) { p.set(col, row, new java.awt.Color(img[row][col])); } } return p; }
public void cropAndCopy( Picture sourcePicture, int startSourceRow, int endSourceRow, int startSourceCol, int endSourceCol, int startDestRow, int startDestCol) { Pixel leftPixel = null; Pixel rightPixel = null; Pixel[][] pixels = this.getPixels2D(); Color rightColor = null; Pixel[][] fromPixels = sourcePicture.getPixels2D(); Pixel[][] toPixels = this.getPixels2D(); Pixel fromPixel = null; Pixel toPixel = null; for (int fromRow = startSourceRow, toRow = endSourceRow; fromRow < fromPixels.length && toRow < toPixels.length; fromRow++, toRow++) { for (int fromCol = startSourceCol, toCol = endSourceCol; fromCol < fromPixels[0].length && toCol < toPixels[0].length; fromCol++, toCol++) { fromPixel = fromPixels[fromRow][fromCol]; toPixel = toPixels[toRow][toCol]; toPixel.setColor(fromPixel.getColor()); } } }
/** * Method to replace blue pixels with pixels from the second picture. * * @param second picture to replace blue pixels with */ public void chromakey(Picture second) { Pixel[][] pixels = this.getPixels2D(); Pixel[][] pixels2 = second.getPixels2D(); for (int row = 0; row < pixels.length; row++) for (int col = 0; col < pixels[0].length; col++) if (pixels[row][col].getColor().getBlue() >= 200) pixels[row][col].setColor(pixels2[row][col].getColor()); }
/** * Method to create a new picture by scaling the current picture by the given x and y factors * * @param xFactor the amount to scale in x * @param yFactor the amount to scale in y * @return the resulting picture */ public Picture scale(double xFactor, double yFactor) { // set up the scale transform AffineTransform scaleTransform = new AffineTransform(); scaleTransform.scale(xFactor, yFactor); // create a new picture object that is the right size Picture result = new Picture((int) (getWidth() * xFactor), (int) (getHeight() * yFactor)); // get the graphics 2d object to draw on the result Graphics graphics = result.getGraphics(); Graphics2D g2 = (Graphics2D) graphics; // draw the current image onto the result image scaled g2.drawImage(this.getImage(), scaleTransform, null); return result; }
@Override protected void onDraw(Canvas canvas) { canvas.drawColor(Color.WHITE); canvas.drawPicture(mPicture); canvas.drawPicture(mPicture, new RectF(0, 100, getWidth(), 200)); mDrawable.setBounds(0, 200, getWidth(), 300); mDrawable.draw(canvas); ByteArrayOutputStream os = new ByteArrayOutputStream(); mPicture.writeToStream(os); InputStream is = new ByteArrayInputStream(os.toByteArray()); canvas.translate(0, 300); canvas.drawPicture(Picture.createFromStream(is)); }
private Picture initialImage() { pic2 = new Picture(500, 600); pic1 = new Picture(500, 600); for (int x = 0; x < pic2.width(); x++) for (int y = 0; y < pic2.height(); y++) { double dist = 1.0 - Math.sqrt((x - 300) * (x - 300) + (y - 200) * (y - 200)) / 500; int red = (int) (dist < 0.5 ? 0 : Math.min(Math.pow(dist, 0.4) + Math.pow(dist - 0.5, 0.1), 1.0) * 255); int green = (int) (dist * 255); int blue = 0; pic2.set(x, y, new Color(red, green, blue)); } return pic2; }
private static void handlePost(Post post) { Main.post_post_hash.put(post, post); for (Picture picture : post.pictures) { Helper.downloadFileFromURLToFileInTemp(picture.thumb_url, picture.thumb_name); picture.md5_id = Helper.createMD5FromFileInTemp(picture.thumb_name); Helper.moveTempImageToStore(picture.thumb_name, new File(Main.blogdir, picture.md5_id)); if (!Main.pic_pic_hash.containsKey(picture)) { Main.pic_pic_hash.put(picture, picture); Main.pic_post_hash.put(picture, post); Helper.downloadFileFromURLToFileInTemp(picture.media_url, picture.media_name); Helper.moveTempImageToStore(picture.media_name, new File(Main.blogdir, picture.md5_id)); } else { if (!post.equals(Main.pic_post_hash.get(picture))) { dup_post_list.put(post, Main.pic_post_hash.get(picture)); } } } }
public void putNewTagsInTagList() { List<String> tags = Picture.listtags(); Iterator<String> itr = tags.iterator(); while (itr.hasNext()) { String value = itr.next(); Tag tag = new Tag(value); tag.save(); } }