Mirror Horizontal public void mirror Horizontal Pixel top
Mirror Horizontal • • • • • public void mirror. Horizontal() { Pixel top. Pixel=null; Pixel bottom. Pixel=null; Color color. Object=null; )); for (int y=0; y <(this. get. Height()/2); y++) { for (int x=0; x<this. get. Width(); x++) { top. Pixel=this. get. Pixel(x, y); bottom. Pixel=this. get. Pixel(x, this. get. Height()-1 -y); bottom. Pixel. set. Color(top. Pixel. get. Color( }//end the y loop }//end the x loop }// end the mirror method
• • • • • • public void copy. Picture() { String source. File= File. Chooser. get. Media. Path("eiffel. jpg"); Picture source. Picture = new Picture(source. File); Pixel source. Pixel=null; Pixel target. Pixel=null; //loop through the columns for (int source. X=0, target. X=0; source. X < source. Picture. get. Width(); source. X++, target. X++) { //loop through the rows for (int source. Y=0, target. Y=0; source. Y < source. Picture. get. Height(); source. Y++, target. Y++) { //set the target pixel color to the source pixel color source. Pixel = source. Picture. get. Pixel(source. X, source. Y); target. Pixel = this. get. Pixel(target. X, target. Y); target. Pixel. set. Color(source. Pixel. get. Color());
• • • • • • • public void create. Flower 2() { Picture source 1 Picture= new Picture(File. Chooser. get. Media. Path("butterfly. jpg")); Picture source 2 Picture= new Picture(File. Chooser. get. Media. Path("caterpillar. jpg")); int target. Bottom. Y=this. get. Height()-5; //copy source 1 Picture to 0, target. Bottom. Y - height this. copy(source 1 Picture, 0, 0, source 1 Picture. get. Width(), source 1 Picture. get. Height(), 0, target. Bottom. Ysource 1 Picture. get. Height()); //copy source 2 Picture to 100, target. Bottom. Y - height this. copy(source 2 Picture, 0, 0, source 2 Picture. get. Width(), source 2 Picture. get. Height(), 100, target. Bottom. Ysource 2 Picture. get. Height()); //negate the source 1 Picture. negate(); • • • • • • • //copy negated source 1 Picture to 200 this. copy(source 1 Picture, 0, 0, source 1 Picture. get. Width(), source 1 Picture. get. Height(), 200, target. Bottom. Ysource 1 Picture. get. Height()); //clear the blue from source 2 picture source 2 Picture. clear. Blue(); //copy source 2 Picture to 300 this. copy(source 2 Picture, 0, 0, source 2 Picture. get. Width(), source 2 Picture. get. Height(), 300, target. Bottom. Ysource 2 Picture. get. Height()); //copy negated source 1 Picture to 400 this. copy(source 1 Picture, 0, 0, source 1 Picture. get. Width(), source 1 Picture. get. Height(), 400, target. Bottom. Ysource 1 Picture. get. Height()); this. mirror. Horizontal 2(); }
Cars Collage • • • • • • • public void create. Flower 2() { Picture source 1 Picture= new Picture(File. Chooser. get. Media. Path("lightning. jpg")); Picture source 2 Picture= new Picture(File. Chooser. get. Media. Path("mater. jpg")); int target. Bottom. Y=this. get. Height()-5; //copy source 1 Picture to 0, target. Bottom. Y - height this. copy(source 1 Picture, 0, 0, source 1 Picture. get. Width(), source 1 Picture. get. Height(), 0, target. Bottom. Ysource 1 Picture. get. Height()); //copy source 2 Picture to 100, target. Bottom. Y - height this. copy(source 2 Picture, 0, 0, source 2 Picture. get. Width(), source 2 Picture. get. Height(), 100, target. Bottom. Ysource 2 Picture. get. Height()); //negate the source 1 Picture. negate(); • • • • • • • //copy negated source 1 Picture to 200 this. copy(source 1 Picture, 0, 0, source 1 Picture. get. Width(), source 1 Picture. get. Height(), 200, target. Bottom. Ysource 1 Picture. get. Height()); //clear the blue from source 2 picture source 2 Picture. clear. Blue(); //copy source 2 Picture to 300 this. copy(source 2 Picture, 0, 0, source 2 Picture. get. Width(), source 2 Picture. get. Height(), 300, target. Bottom. Ysource 2 Picture. get. Height()); //copy negated source 1 Picture to 400 /*this. copy(source 1 Picture, 0, 0, source 1 Picture. get. Width(), source 1 Picture. get. Height(), 400, target. Bottom. Ysource 1 Picture. get. Height()); */ this. mirror. Horizontal 2(); }
Cars Collage (SM) • • • • • • • public void create. Flower. Smaller() { Picture source 1 Picture= new Picture(File. Chooser. get. Media. Path("lightning. jpg")); Picture source 2 Picture= new Picture(File. Chooser. get. Media. Path("mater. jpg")); int target. Bottom. Y=this. get. Height()-5; //copy source 1 Picture to 0, target. Bottom. Y - height this. copy. Smaller(source 1 Picture, 0, 0, source 1 Picture. get. Width(), source 1 Picture. get. Height(), 0, target. Bottom. Ysource 1 Picture. get. Height()); //copy source 2 Picture to 100, target. Bottom. Y - height this. copy. Smaller(source 2 Picture, 0, 0, source 2 Picture. get. Width(), source 2 Picture. get. Height(), 100, target. Bottom. Ysource 2 Picture. get. Height()); //negate the source 1 Picture. negate(); • • • • • • • //copy negated source 1 Picture to 200 this. copy. Smaller(source 1 Picture, 0, 0, source 1 Picture. get. Width(), source 1 Picture. get. Height(), 200, target. Bottom. Ysource 1 Picture. get. Height()); //clear the blue from source 2 picture source 2 Picture. clear. Blue(); //copy. Smaller source 2 Picture to 300 this. copy. Smaller(source 2 Picture, 0, 0, source 2 Picture. get. Width(), source 2 Picture. get. Height(), 300, target. Bottom. Ysource 2 Picture. get. Height()); //copy. Smaller negated source 1 Picture to 400 this. copy. Smaller(source 1 Picture, 0, 0, source 1 Picture. get. Width(), source 1 Picture. get. Height(), 400, target. Bottom. Ysource 1 Picture. get. Height()); this. mirror. Horizontal 2(); }
Cars Collage (Vertical) • • • • • • • public void create. Flower. Smaller. V() { Picture source 1 Picture= new Picture(File. Chooser. get. Media. Path("lightning. jpg")); Picture source 2 Picture= new Picture(File. Chooser. get. Media. Path("mater. jpg")); int target. Bottom. Y=this. get. Height()-5; //copy source 1 Picture to 0, target. Bottom. Y - height this. copy. Smaller(source 1 Picture, 0, 0, source 1 Picture. get. Width(), source 1 Picture. get. Height(), 0, target. Bottom. Ysource 1 Picture. get. Height()); //copy source 2 Picture to 100, target. Bottom. Y - height this. copy. Smaller(source 2 Picture, 0, 0, source 2 Picture. get. Width(), source 2 Picture. get. Height(), 100, target. Bottom. Ysource 2 Picture. get. Height()); //negate the source 1 Picture. negate(); • • • • • • • //copy negated source 1 Picture to 200 this. copy. Smaller(source 1 Picture, 0, 0, source 1 Picture. get. Width(), source 1 Picture. get. Height(), 200, target. Bottom. Ysource 1 Picture. get. Height()); //clear the blue from source 2 picture source 2 Picture. clear. Blue(); //copy. Smaller source 2 Picture to 300 this. copy. Smaller(source 2 Picture, 0, 0, source 2 Picture. get. Width(), source 2 Picture. get. Height(), 300, target. Bottom. Ysource 2 Picture. get. Height()); //copy. Smaller negated source 1 Picture to 400 this. copy. Smaller(source 1 Picture, 0, 0, source 1 Picture. get. Width(), source 1 Picture. get. Height(), 400, target. Bottom. Ysource 1 Picture. get. Height()); this. mirror. Vertical. Lto. R(); }
Cars Collage Vertical & Horizontal
Cars Collage Vertical & Horizontal • public void create. Collage() • { • Picture source 1 Picture= • new Picture(File. Chooser. get. Media. Path("lightning. jpg")); • Picture source 2 Picture= • new Picture(File. Chooser. get. Media. Path("mater. jpg")); • int target. Bottom. Y=this. get. Height()-5; • • this. create. Flower. Smaller(); • • this. create. Flower. Smaller. V(); • }
Cars Collage (Smaller Lightning)
Cars Collage (Smaller lightning) • • • • • • • public void create. Flower. Smaller 2() { Picture source 1 Picture= new Picture(File. Chooser. get. Media. Path("lightning. jpg")); Picture source 2 Picture= new Picture(File. Chooser. get. Media. Path("mater. jpg")); int target. Bottom. Y=this. get. Height()-5; //copy source 1 Picture to 0, target. Bottom. Y - height this. copy. Smaller 4(source 1 Picture, 0, 0, source 1 Picture. get. Width(), source 1 Picture. get. Height(), 0, target. Bottom. Ysource 1 Picture. get. Height()); //copy source 2 Picture to 100, target. Bottom. Y - height this. copy. Smaller(source 2 Picture, 0, 0, source 2 Picture. get. Width(), source 2 Picture. get. Height(), 100, target. Bottom. Ysource 2 Picture. get. Height()); //negate the source 1 Picture. negate(); • • • • • • • //copy negated source 1 Picture to 200 this. copy. Smaller 4(source 1 Picture, 0, 0, source 1 Picture. get. Width(), source 1 Picture. get. Height(), 200, target. Bottom. Ysource 1 Picture. get. Height()); //clear the blue from source 2 picture source 2 Picture. clear. Blue(); //copy. Smaller source 2 Picture to 300 this. copy. Smaller(source 2 Picture, 0, 0, source 2 Picture. get. Width(), source 2 Picture. get. Height(), 300, target. Bottom. Ysource 2 Picture. get. Height()); //copy. Smaller negated source 1 Picture to 400 this. copy. Smaller 4(source 1 Picture, 0, 0, source 1 Picture. get. Width(), source 1 Picture. get. Height(), 400, target. Bottom. Ysource 1 Picture. get. Height()); this. mirror. Horizontal 2();
Car Collage (Vertical & Horizontal – Lightning Smaller)
• public void create. Collage 2() • { • Picture source 1 Picture= • new Picture(File. Chooser. get. Media. Path("lightning. jpg")); • Picture source 2 Picture= • new Picture(File. Chooser. get. Media. Path("mater. jpg")); • int target. Bottom. Y=this. get. Height()-5; • • this. create. Flower. Smaller 2(); • • this. create. Flower. Smaller. V(); • }
Cars Collage – moving position of Pictures • • • • • • • • • public void create. Flower. Smaller 2() { Picture source 1 Picture= new Picture(File. Chooser. get. Media. Path("lightning. jpg ")); Picture source 2 Picture= new Picture(File. Chooser. get. Media. Path("mater. jpg ")); int target. Bottom. Y=this. get. Height()-5; //copy source 1 Picture to 0, target. Bottom. Y - height this. copy. Smaller 4(source 1 Picture, 0, 0, source 1 Picture. get. Width(), source 1 Picture. get. Height(), 0, target. Bottom. Ysource 1 Picture. get. Height()); //copy source 2 Picture to 112, target. Bottom. Y - height this. copy. Smaller(source 2 Picture, 0, 0, source 2 Picture. get. Width(), source 2 Picture. get. Height(), 112, target. Bottom. Ysource 2 Picture. get. Height()); //negate the source 1 Picture. negate(); //copy negated source 1 Picture to 275 this. copy. Smaller 4(source 1 Picture, 0, 0, source 1 Picture. get. Width(), source 1 Picture. get. Height(), 275, target. Bottom. Ysource 1 Picture. get. Height()); • • • • • //clear the blue from source 2 picture source 2 Picture. clear. Blue(); //copy. Smaller source 2 Picture to 385 this. copy. Smaller(source 2 Picture, 0, 0, source 2 Picture. get. Width(), source 2 Picture. get. Height(), 385, target. Bottom. Ysource 2 Picture. get. Height()); //copy. Smaller negated source 1 Picture to 480 /*this. copy. Smaller 4(source 1 Picture, 0, 0, source 1 Picture. get. Width(), source 1 Picture. get. Height(), 480, target. Bottom. Ysource 1 Picture. get. Height()); */ this. mirror. Horizontal 2(); }
Copy Pictures smaller – side by side – no negation. • • • • • • • • public void create. Flower. C 1() { Picture source 1 Picture= new Picture(File. Chooser. get. Media. Path("lightning. jpg")); Picture source 2 Picture= new Picture(File. Chooser. get. Media. Path("mater. jpg")); int target. Bottom. Y=this. get. Height()-5; //copy source 1 Picture to 0, target. Bottom. Y - height this. copy. Smaller 4(source 1 Picture, 0, 0, source 1 Picture. get. Width(), source 1 Picture. get. Height(), 0, target. Bottom. Ysource 1 Picture. get. Height()); //copy source 2 Picture to 100, target. Bottom. Y - height this. copy. Smaller 4(source 2 Picture, 0, 0, source 2 Picture. get. Width(), source 2 Picture. get. Height(), 100, target. Bottom. Ysource 2 Picture. get. Height()); //copy negated source 1 Picture to 200 this. copy. Smaller 4(source 1 Picture, 0, 0, source 1 Picture. get. Width(), source 1 Picture. get. Height(), 200, target. Bottom. Ysource 1 Picture. get. Height()); • • • • • //clear the blue from source 2 picture source 2 Picture. clear. Blue(); //copy source 2 Picture to 300 this. copy. Smaller 4(source 2 Picture, 0, 0, source 2 Picture. get. Width(), source 2 Picture. get. Height(), 300, target. Bottom. Ysource 2 Picture. get. Height()); //copy negated source 1 Picture to 400 this. copy. Smaller 4(source 1 Picture, 0, 0, source 1 Picture. get. Width(), source 1 Picture. get. Height(), 400, target. Bottom. Ysource 1 Picture. get. Height()); }
Copy Pictures smaller – side by side – no negation.
Make Extreme (make red – redder & blue – bluer) • public void make. Extreme(){ • Pixel[] pixel. Array = this. get. Pixels(); • for (Pixel p: pixel. Array) • { • if (p. color. Distance(Color. red) < 150) • {p. set. Color(Color. red); } • if (p. color. Distance(Color. blue) < 150) • {p. set. Color(Color. blue); } • }
Changing blue in a picture! (greece. jpg) • • • • • • public void change. Water(int start. X, int start. Y, int end. X, int end. Y, Color new. Color) { Pixel pixel. Obj = null; //loop through the pixels in the rectangel defined by the //start. X, start. Y, and end X and end. Y for (int x = start. X; x < end. X; x++) { for (int y = start. Y; y < end. Y; y++) { //get the current pixel. Obj = get. Pixel(x, y); //if the color is near red then change it if (pixel. Obj. color. Distance(new Color(94, 89, 93)) < 50) { pixel. Obj. set. Color(new. Color); } }
Change Background • • • • • • • public void change. Background (Picture new. Background) { Pixel curr. Pixel = null; Pixel new. Pixel = null; //loop through the columns for (int x=0; x<this. get. Width(); x++) { //loop through the rows for (int y=0; y<this. get. Height(); y++) { //get the current pixel and old background pixel curr. Pixel=this. get. Pixel(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 (curr. Pixel. color. Distance(new Color(87, 157, 3)) < 95. 0) { new. Pixel = new. Background. get. Pixel(x, y); curr. Pixel. set. Color(new. Pixel. get. Color()); } } • • • TEST Picture p 1 = new Picture(File. Chooser. get. Media. Path("trudy. jpg")); > Picture new. Back = new Picture(File. Chooser. get. Media. Path("moon-surface. jpg")); > p 1. change. Background(new. Back); > p 1. show();
Swap Background • • • • • • • public void swap. Background(Picture old. Background, Picture new. Background) { Pixel curr. Pixel = null; Pixel old. Pixel = null; Pixel new. Pixel = null; //loop through the columns for (int x=0; x<this. get. Width(); x++) { //loop through the rows for (int y=0; y<this. get. Height(); y++) { //get the current pixel and old background pixel curr. Pixel=this. get. Pixel(x, y); old. Pixel=old. Background. get. Pixel(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 (curr. Pixel. color. Distance(old. Pixel. get. Color()) < 15. 0) { new. Pixel = new. Background. get. Pixel(x, y); curr. Pixel. set. Color(new. Pixel. get. Color()); } }
Sound. java • public String to. String() • { • String output = "Sound"; • String file. Name = get. File. Name(); • • // if there is a file name then add that to the output • if (file. Name != null) • output = output + " file: " + file. Name; • • // add the length in frames • output = output + " number of samples: " + get. Length. In. Frames(); • • return output; • }
Increase Volume (Sound. java) • public void increase. Volume() • { • Sound. Sample[] sample. Array = this. get. Samples(); • int value = 0; // value at sample • • //loop through Sound. Sample objects • for (Sound. Sample sample : sample. Array) • { • value = sample. get. Value(); //get the value • sample. set. Value(value*2); //set the value • }
Decrease Volume (sound. java) • • • public void decrease. Volume() { Sound. Sample[] sample. Array = this. get. Samples(); int value = 0; // value at sample //loop through Sound. Sample objects for (Sound. Sample sample : sample. Array) { value = sample. get. Value(); //get the value sample. set. Value(value/2); //set the value } }
Clip Method • • • • • • public Sound clip(int start, int end) { //calc the num samples int num. Samples= end - start + 1; Sound target = new Sound(num. Samples); int value = 0; int target. Index = 0; //copy from start to end for (int i = start; i <= end; i++, target. Index++) { value = this. get. Sample. Value. At(i); target. set. Sample. Value. At(target. Index, value); } return target; }
Splice (sound. java) • • • • • • • • public void splice() { Sound sound 1 = new Sound(File. Chooser. get. Media. Path("guzdial. wav")); Sound sound 2 = new Sound(File. Chooser. get. Media. Path("is. wav")); int target. Index = 0; //starting place on the target int value = 0; //copy all of sound 1 into the current sound (target) for (int i = 0; i < sound 1. get. Length(); i++, target. Index++) { value = sound 1. get. Sample. Value. At(i); this. set. Sample. Value. At(target. Index, value); } //create silence between words by setting values to 0 for (int i=0; i < (int) (this. get. Sampling. Rate()*0. 1); i++, target. Index++){ this. set. Sample. Value. At(target. Index, 0); } //copy all of sound 2 into the current sound (target) for (int i = 0; i < sound 2. get. Length(); i++, target. Index++){ value = sound 2. get. Sample. Value. At(i); this. set. Sample. Value. At(target. Index, value); } }
- Slides: 25