1 / 25

Mirror Horizontal

Mirror Horizontal. public void mirrorHorizontal() { Pixel topPixel=null; Pixel bottomPixel=null; Color colorObject=null; for (int y=0; y <(this.getHeight()/2); y++) { for (int x=0; x<this.getWidth(); x++) {

ava-huff
Télécharger la présentation

Mirror Horizontal

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Mirror Horizontal • public void mirrorHorizontal() • { • Pixel topPixel=null; • Pixel bottomPixel=null; • Color colorObject=null; • for (int y=0; • y <(this.getHeight()/2); • y++) • { • for (int x=0; x<this.getWidth(); x++) • { • topPixel=this.getPixel(x,y); • bottomPixel=this.getPixel(x, • this.getHeight()-1-y); • bottomPixel.setColor(topPixel.getColor()); • }//end the y loop • }//end the x loop • }// end the mirror method

  2. public void copyPicture() • { • String sourceFile= • FileChooser.getMediaPath("eiffel.jpg"); • Picture sourcePicture = new Picture(sourceFile); • Pixel sourcePixel=null; • Pixel targetPixel=null; • //loop through the columns • for (int sourceX=0, targetX=0; • sourceX < sourcePicture.getWidth(); • sourceX++, targetX++) • { • //loop through the rows • for (int sourceY=0, targetY=0; • sourceY < sourcePicture.getHeight(); • sourceY++, targetY++) • { • //set the target pixel color to the source pixel color • sourcePixel = sourcePicture.getPixel(sourceX, sourceY); • targetPixel = this.getPixel(targetX, targetY); • targetPixel.setColor(sourcePixel.getColor());

  3. public void createFlower2() { Picture source1Picture= new Picture(FileChooser.getMediaPath("butterfly.jpg")); Picture source2Picture= new Picture(FileChooser.getMediaPath("caterpillar.jpg")); int targetBottomY=this.getHeight()-5; //copy source1Picture to 0, targetBottomY - height this.copy(source1Picture,0,0, source1Picture.getWidth(), source1Picture.getHeight(), 0,targetBottomY- source1Picture.getHeight()); //copy source2Picture to 100, targetBottomY - height this.copy(source2Picture,0,0, source2Picture.getWidth(), source2Picture.getHeight(), 100,targetBottomY- source2Picture.getHeight()); //negate the source1Picture source1Picture.negate(); //copy negated source1Picture to 200 this.copy(source1Picture,0,0, source1Picture.getWidth(), source1Picture.getHeight(), 200,targetBottomY- source1Picture.getHeight()); //clear the blue from source 2 picture source2Picture.clearBlue(); //copy source2Picture to 300 this.copy(source2Picture,0,0, source2Picture.getWidth(), source2Picture.getHeight(), 300,targetBottomY- source2Picture.getHeight()); //copy negated source1Picture to 400 this.copy(source1Picture,0,0, source1Picture.getWidth(), source1Picture.getHeight(), 400,targetBottomY- source1Picture.getHeight()); this.mirrorHorizontal2(); }

  4. public void createFlower2() { Picture source1Picture= new Picture(FileChooser.getMediaPath("lightning.jpg")); Picture source2Picture= new Picture(FileChooser.getMediaPath("mater.jpg")); int targetBottomY=this.getHeight()-5; //copy source1Picture to 0, targetBottomY - height this.copy(source1Picture,0,0, source1Picture.getWidth(), source1Picture.getHeight(), 0,targetBottomY- source1Picture.getHeight()); //copy source2Picture to 100, targetBottomY - height this.copy(source2Picture,0,0, source2Picture.getWidth(), source2Picture.getHeight(), 100,targetBottomY- source2Picture.getHeight()); //negate the source1Picture source1Picture.negate(); //copy negated source1Picture to 200 this.copy(source1Picture,0,0, source1Picture.getWidth(), source1Picture.getHeight(), 200,targetBottomY- source1Picture.getHeight()); //clear the blue from source 2 picture source2Picture.clearBlue(); //copy source2Picture to 300 this.copy(source2Picture,0,0, source2Picture.getWidth(), source2Picture.getHeight(), 300,targetBottomY- source2Picture.getHeight()); //copy negated source1Picture to 400 /*this.copy(source1Picture,0,0, source1Picture.getWidth(), source1Picture.getHeight(), 400,targetBottomY- source1Picture.getHeight()); */ this.mirrorHorizontal2(); } Cars Collage

  5. public void createFlowerSmaller() { Picture source1Picture= new Picture(FileChooser.getMediaPath("lightning.jpg")); Picture source2Picture= new Picture(FileChooser.getMediaPath("mater.jpg")); int targetBottomY=this.getHeight()-5; //copy source1Picture to 0, targetBottomY - height this.copySmaller(source1Picture,0,0, source1Picture.getWidth(), source1Picture.getHeight(), 0,targetBottomY- source1Picture.getHeight()); //copy source2Picture to 100, targetBottomY - height this.copySmaller(source2Picture,0,0, source2Picture.getWidth(), source2Picture.getHeight(), 100,targetBottomY- source2Picture.getHeight()); //negate the source1Picture source1Picture.negate(); //copy negated source1Picture to 200 this.copySmaller(source1Picture,0,0, source1Picture.getWidth(), source1Picture.getHeight(), 200,targetBottomY- source1Picture.getHeight()); //clear the blue from source 2 picture source2Picture.clearBlue(); //copySmaller source2Picture to 300 this.copySmaller(source2Picture,0,0, source2Picture.getWidth(), source2Picture.getHeight(), 300,targetBottomY- source2Picture.getHeight()); //copySmaller negated source1Picture to 400 this.copySmaller(source1Picture,0,0, source1Picture.getWidth(), source1Picture.getHeight(), 400,targetBottomY- source1Picture.getHeight()); this.mirrorHorizontal2(); } Cars Collage (SM)

  6. public void createFlowerSmallerV() { Picture source1Picture= new Picture(FileChooser.getMediaPath("lightning.jpg")); Picture source2Picture= new Picture(FileChooser.getMediaPath("mater.jpg")); int targetBottomY=this.getHeight()-5; //copy source1Picture to 0, targetBottomY - height this.copySmaller(source1Picture,0,0, source1Picture.getWidth(), source1Picture.getHeight(), 0,targetBottomY- source1Picture.getHeight()); //copy source2Picture to 100, targetBottomY - height this.copySmaller(source2Picture,0,0, source2Picture.getWidth(), source2Picture.getHeight(), 100,targetBottomY- source2Picture.getHeight()); //negate the source1Picture source1Picture.negate(); //copy negated source1Picture to 200 this.copySmaller(source1Picture,0,0, source1Picture.getWidth(), source1Picture.getHeight(), 200,targetBottomY- source1Picture.getHeight()); //clear the blue from source 2 picture source2Picture.clearBlue(); //copySmaller source2Picture to 300 this.copySmaller(source2Picture,0,0, source2Picture.getWidth(), source2Picture.getHeight(), 300,targetBottomY- source2Picture.getHeight()); //copySmaller negated source1Picture to 400 this.copySmaller(source1Picture,0,0, source1Picture.getWidth(), source1Picture.getHeight(), 400,targetBottomY- source1Picture.getHeight()); this.mirrorVerticalLtoR(); } Cars Collage (Vertical)

  7. Cars Collage Vertical & Horizontal

  8. Cars Collage Vertical & Horizontal • public void createCollage() • { • Picture source1Picture= • new Picture(FileChooser.getMediaPath("lightning.jpg")); • Picture source2Picture= • new Picture(FileChooser.getMediaPath("mater.jpg")); • int targetBottomY=this.getHeight()-5; • this.createFlowerSmaller(); • this.createFlowerSmallerV(); • }

  9. Cars Collage (Smaller Lightning)

  10. public void createFlowerSmaller2() { Picture source1Picture= new Picture(FileChooser.getMediaPath("lightning.jpg")); Picture source2Picture= new Picture(FileChooser.getMediaPath("mater.jpg")); int targetBottomY=this.getHeight()-5; //copy source1Picture to 0, targetBottomY - height this.copySmaller4(source1Picture,0,0, source1Picture.getWidth(), source1Picture.getHeight(), 0,targetBottomY- source1Picture.getHeight()); //copy source2Picture to 100, targetBottomY - height this.copySmaller(source2Picture,0,0, source2Picture.getWidth(), source2Picture.getHeight(), 100,targetBottomY- source2Picture.getHeight()); //negate the source1Picture source1Picture.negate(); //copy negated source1Picture to 200 this.copySmaller4(source1Picture,0,0, source1Picture.getWidth(), source1Picture.getHeight(), 200,targetBottomY- source1Picture.getHeight()); //clear the blue from source 2 picture source2Picture.clearBlue(); //copySmaller source2Picture to 300 this.copySmaller(source2Picture,0,0, source2Picture.getWidth(), source2Picture.getHeight(), 300,targetBottomY- source2Picture.getHeight()); //copySmaller negated source1Picture to 400 this.copySmaller4(source1Picture,0,0, source1Picture.getWidth(), source1Picture.getHeight(), 400,targetBottomY- source1Picture.getHeight()); this.mirrorHorizontal2(); Cars Collage (Smaller lightning)

  11. Car Collage (Vertical & Horizontal – Lightning Smaller)

  12. public void createCollage2() • { • Picture source1Picture= • new Picture(FileChooser.getMediaPath("lightning.jpg")); • Picture source2Picture= • new Picture(FileChooser.getMediaPath("mater.jpg")); • int targetBottomY=this.getHeight()-5; • this.createFlowerSmaller2(); • this.createFlowerSmallerV(); • }

  13. public void createFlowerSmaller2() { Picture source1Picture= new Picture(FileChooser.getMediaPath("lightning.jpg")); Picture source2Picture= new Picture(FileChooser.getMediaPath("mater.jpg")); int targetBottomY=this.getHeight()-5; //copy source1Picture to 0, targetBottomY - height this.copySmaller4(source1Picture,0,0, source1Picture.getWidth(), source1Picture.getHeight(), 0,targetBottomY- source1Picture.getHeight()); //copy source2Picture to 112, targetBottomY - height this.copySmaller(source2Picture,0,0, source2Picture.getWidth(), source2Picture.getHeight(), 112,targetBottomY- source2Picture.getHeight()); //negate the source1Picture source1Picture.negate(); //copy negated source1Picture to 275 this.copySmaller4(source1Picture,0,0, source1Picture.getWidth(), source1Picture.getHeight(), 275,targetBottomY- source1Picture.getHeight()); //clear the blue from source 2 picture source2Picture.clearBlue(); //copySmaller source2Picture to 385 this.copySmaller(source2Picture,0,0, source2Picture.getWidth(), source2Picture.getHeight(), 385,targetBottomY- source2Picture.getHeight()); //copySmaller negated source1Picture to 480 /*this.copySmaller4(source1Picture,0,0, source1Picture.getWidth(), source1Picture.getHeight(), 480,targetBottomY- source1Picture.getHeight());*/ this.mirrorHorizontal2(); } Cars Collage – moving position of Pictures

  14. public void createFlowerC1() { Picture source1Picture= new Picture(FileChooser.getMediaPath("lightning.jpg")); Picture source2Picture= new Picture(FileChooser.getMediaPath("mater.jpg")); int targetBottomY=this.getHeight()-5; //copy source1Picture to 0, targetBottomY - height this.copySmaller4(source1Picture,0,0, source1Picture.getWidth(), source1Picture.getHeight(), 0,targetBottomY- source1Picture.getHeight()); //copy source2Picture to 100, targetBottomY - height this.copySmaller4(source2Picture,0,0, source2Picture.getWidth(), source2Picture.getHeight(), 100,targetBottomY- source2Picture.getHeight()); //copy negated source1Picture to 200 this.copySmaller4(source1Picture,0,0, source1Picture.getWidth(), source1Picture.getHeight(), 200,targetBottomY- source1Picture.getHeight()); //clear the blue from source 2 picture source2Picture.clearBlue(); //copy source2Picture to 300 this.copySmaller4(source2Picture,0,0, source2Picture.getWidth(), source2Picture.getHeight(), 300,targetBottomY- source2Picture.getHeight()); //copy negated source1Picture to 400 this.copySmaller4(source1Picture,0,0, source1Picture.getWidth(), source1Picture.getHeight(), 400,targetBottomY- source1Picture.getHeight()); } Copy Pictures smaller – side by side – no negation.

  15. Copy Pictures smaller – side by side – no negation.

  16. Make Extreme (make red – redder & blue – bluer) • public void makeExtreme(){ • Pixel[] pixelArray = this.getPixels(); • for (Pixel p: pixelArray) • { • if (p.colorDistance(Color.red) < 150) • {p.setColor(Color.red);} • if (p.colorDistance(Color.blue) < 150) • {p.setColor(Color.blue);} • } • }

  17. Changing blue in a picture!(greece.jpg) • public void changeWater(int startX, int startY, int endX, int endY, Color newColor) • { • Pixel pixelObj = null; • //loop through the pixels in the rectangel defined by the • //startX, startY, and end X and endY • for (int x = startX; x < endX;x++) • { • for (int y = startY; y < endY; y++) • { • //get the current pixel • pixelObj = getPixel(x,y); • //if the color is near red then change it • if (pixelObj.colorDistance(new Color(94,89,93)) < 50) • { • pixelObj.setColor(newColor); • } • } • } • }

  18. public void changeBackground (Picture newBackground) { Pixel currPixel = null; Pixel newPixel = null; //loop through the columns for (int x=0; x<this.getWidth();x++) { //loop through the rows for (int y=0; y<this.getHeight();y++) { //get the current pixel and old background pixel currPixel=this.getPixel(x,y); /* if the distance between the current pixel color * and the old background pixel color is less than the 15 * then swap in the new background pixel */ if (currPixel.colorDistance(new Color(87,157,3)) < 95.0) { newPixel = newBackground.getPixel(x,y); currPixel.setColor(newPixel.getColor()); } } } } TEST Picture p1 = new Picture(FileChooser.getMediaPath("trudy.jpg")); > Picture newBack = new Picture(FileChooser.getMediaPath("moon-surface.jpg")); > p1.changeBackground(newBack); > p1.show(); Change Background

  19. Swap Background • public void swapBackground(Picture oldBackground, Picture newBackground) • { • Pixel currPixel = null; • Pixel oldPixel = null; • Pixel newPixel = null; • //loop through the columns • for (int x=0; x<this.getWidth();x++) • { • //loop through the rows • for (int y=0; y<this.getHeight();y++) • { • //get the current pixel and old background pixel • currPixel=this.getPixel(x,y); • oldPixel=oldBackground.getPixel(x,y); • /* if the distance between the current pixel color • * and the old background pixel color is less than the 15 • * then swap in the new background pixel • */ • if (currPixel.colorDistance(oldPixel.getColor()) < 15.0) • { • newPixel = newBackground.getPixel(x,y); • currPixel.setColor(newPixel.getColor()); • } • } • } • }

  20. Sound.java • public String toString() • { • String output = "Sound"; • String fileName = getFileName(); • // if there is a file name then add that to the output • if (fileName != null) • output = output + " file: " + fileName; • // add the length in frames • output = output + " number of samples: " + getLengthInFrames(); • return output; • }

  21. Increase Volume(Sound.java) • public void increaseVolume() • { • SoundSample[] sampleArray = this.getSamples(); • int value = 0; // value at sample • //loop through SoundSample objects • for (SoundSample sample : sampleArray) • { • value = sample.getValue(); //get the value • sample.setValue(value*2); //set the value • } • }

  22. Decrease Volume (sound.java) • public void decreaseVolume() • { • SoundSample[] sampleArray = this.getSamples(); • int value = 0; // value at sample • //loop through SoundSample objects • for (SoundSample sample : sampleArray) • { • value = sample.getValue(); //get the value • sample.setValue(value/2); //set the value • } • }

  23. Clip Method • public Sound clip(int start, • int end) • { • //calc the num samples • int numSamples= • end - start + 1; • Sound target = • new Sound(numSamples); • int value = 0; • int targetIndex = 0; • //copy from start to end • for (int i = start; i <= end; • i++, targetIndex++) • { • value = this.getSampleValueAt(i); • target.setSampleValueAt(targetIndex, • value); • } • return target; • }

  24. Splice (sound.java) • public void splice() • { • Sound sound1 = new Sound(FileChooser.getMediaPath("guzdial.wav")); • Sound sound2 = new Sound(FileChooser.getMediaPath("is.wav")); • int targetIndex = 0;//starting place on the target • int value = 0; • //copy all of sound 1 into the current sound (target) • for (int i = 0; • i < sound1.getLength(); • i++,targetIndex++) • { • value = sound1.getSampleValueAt(i); • this.setSampleValueAt(targetIndex,value); • } • //create silence between words by setting values to 0 • for (int i=0; • i < (int) (this.getSamplingRate()*0.1); • i++,targetIndex++){ • this.setSampleValueAt(targetIndex,0); • } • //copy all of sound 2 into the current sound (target) • for (int i = 0; • i < sound2.getLength(); • i++,targetIndex++){ • value = sound2.getSampleValueAt(i); • this.setSampleValueAt(targetIndex,value); • } • }

More Related