NestedLoops-Mod7-part31 Two-Dimensional Arrays and Nested Loops – part 3 Bugs in the garden Originally by Barb Ericson Georgia Institute of Technology.

Slides:



Advertisements
Similar presentations
Georgia Institute of Technology Drawing in Java – part 2 Barb Ericson Georgia Institute of Technology September 2005.
Advertisements

Conditionals-part31 Conditionals – part 3 Barb Ericson Georgia Institute of Technology Nov 2009.
ManipulatingPictures-Mod6-part21 Manipulating Pictures, Arrays, and Loops part 2 Barb Ericson Georgia Institute of Technology.
Conditionals-part11 Barb Ericson Georgia Institute of Technology Nov 2009.
Georgia Institute of Technology Two-Dimensional Arrays and Nested Loops – part 6 Barb Ericson Georgia Institute of Technology August 2005.
TOPIC 9 MODIFYING PIXELS IN A MATRIX: COPYING, CROPPING 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach.
NestedLoops-part31 Nested Loops – part 3 Barb Ericson Georgia Institute of Technology Nov 2009.
How to use the Java class libraries Brief documentation of how to do this all with Java.
NestedLoops-part11 Nested Loops – part 1 Barb Ericson Georgia Institute of Technology Nov 2009.
02-RangesInPictures1 Barb Ericson Georgia Institute of Technology Oct 2010 Working with ranges in pictures.
ManipulatingPictures-part11 Manipulating Pictures, Arrays, and Loops part 1 Barb Ericson Georgia Institute of Technology Nov 2009.
Georgia Institute of Technology Movies part 2 Barb Ericson Georgia Institute of Technology April 2006.
Georgia Institute of Technology Processing Sound Ranges Barb Ericson Georgia Institute of Technology July 2005.
UsingSoundRanges-part21 Processing Sound Ranges part 2 Barb Ericson Georgia Institute of Technology Oct 2009.
TOPIC 11 RETURNING VALUES FROM METHODS PICTURE TRANSFORMATIONS 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach.
Georgia Institute of Technology Manipulating Pictures, Arrays, and Loops Barb Ericson Georgia Institute of Technology August 2005.
ManipulatingPictures-Mod6-part61 Manipulating Pictures, Arrays, and Loops: Eliminating color, Inversion, grey scale and adjusting for luminance Barb Ericson.
Georgia Institute of Technology Two-Dimensional Arrays and Nested Loops – part 5 Barb Ericson Georgia Institute of Technology August 2005.
NestedLoops-part41 Nested Loops – part 4 Barb Ericson Georgia Institute of Technology Nov 2009.
NestedLoops-Mody7-part51 Two-Dimensional Arrays and Nested Loops – part 5 Rotations Barb Ericson Georgia Institute of Technology May 2007.
February ,  2/16: Exam 1 Makeup Papers Available  2/20: Exam 2 Review Sheet Available in Lecture  2/27: Lab 2 due by 11:59:59pm  3/2:
CPSC1301 Computer Science 1 Chapter 4 Manipulating Pictures, Arrays, and Loops part 5.
Conditionals-Mod8-part41 Conditionals – part 4 Replace background Barb Ericson Georgia Institute of Technology May 2007.
Conditionals-part21 Conditionals – part 2 Barb Ericson Georgia Institute of Technology Nov 2009.
Georgia Institute of Technology Movies part 4 Barb Ericson Georgia Institute of Technology April 2006.
Georgia Institute of Technology What is new in Java 5.0 (1.5)? Barb Ericson Georgia Institute of Technology June 2006.
NestedLoops-part21 Nested Loops – part 2 Barb Ericson Georgia Institute of Technology Nov 2009.
SourceAnatomy1 Java Source Anatomy Barb Ericson Georgia Institute of Technology July 2008.
Intro-Sound-Mod10-part31 Introduction to Processing Digital Sounds part 3 while loop, tracing, for loop, parameters Barb Ericson Georgia Institute of Technology.
ManipulatingPictures-part31 Manipulating Pictures, Arrays, and Loops part 3 Barb Ericson Georgia Institute of Technology Nov 2009.
04-ManipulatingPictures-part21 Manipulating Pictures, Arrays, and Loops part 2 Barb Ericson Georgia Institute of Technology June 2008.
Madlib-Input, Strings, and Lists in Scratch Barb Ericson Georgia Tech.
Georgia Institute of Technology Two-Dimensional Arrays and Nested Loops – part 2 Barb Ericson Georgia Institute of Technology August 2005.
NestedLoops-Mod7-part61 Two-Dimensional Arrays and Nested Loops – part 6 Enlarge Barb Ericson Georgia Institute of Technology August 2005.
Georgia Institute of Technology Two-Dimensional Arrays and Nested Loops – part 4 Barb Ericson Georgia Institute of Technology August 2005.
Barbara Ericson Georgia Tech Sept 2005
Topic 9 Modifying Pixels in a Matrix: Copying, Cropping
Manipulating Pictures, Arrays, and Loops part 2
Manipulating Pictures, Arrays, and Loops part 2
Manipulating Pictures, Arrays, and Loops part 3
Barb Ericson Georgia Institute of Technology August 2005
Workshop for Programming And Systems Management Teachers
Manipulating Pictures, Arrays, and Loops part 2
Manipulating Pictures, Arrays, and Loops part 2
Georgia Institute of Technology
Manipulating Pictures, Arrays, and Loops
Barb Ericson Georgia Institute of Technology August 2005
Two-Dimensional Arrays and Nested Loops – part 1
Barb Ericson Georgia Institute of Technology August 2005
Manipulating Pictures, Arrays, and Loops part 5
Two-Dimensional Arrays and Nested Loops – part 5
Two-Dimensional Arrays and Nested Loops – part 1
Arrays versus ArrayList
Two-Dimensional Arrays and Nested Loops – part 4
Two-Dimensional Arrays and Nested Loops – part 3
Two-Dimensional Arrays and Nested Loops – part 6
Two-Dimensional Arrays and Nested Loops – part 2
Manipulating Pictures, Arrays, and Loops
Manipulating Pictures, Arrays, and Loops
Two-Dimensional Arrays and Nested Loops – part 6
Manipulating Pictures, Arrays, and Loops
Processing Sound Ranges part 2
Manipulating Pictures, Arrays, and Loops part 6
CSC1401 Viewing a picture as a 2D image - 2
February , 2009 CSE 113 B.
Two-Dimensional Arrays and Nested Loops – part 6
Barb Ericson Georgia Institute of Technology May 2006
Manipulating Pictures, Arrays, and Loops
Processing Sound Ranges part 3
Manipulating Pictures, Arrays, and Loops part 6
Presentation transcript:

NestedLoops-Mod7-part31 Two-Dimensional Arrays and Nested Loops – part 3 Bugs in the garden Originally by Barb Ericson Georgia Institute of Technology

NestedLoops-Mod7-part32 Learning Goals Understand at a conceptual and practical level –How to copy pixels from one picture to another –How to declare, initialize and change several variables in a for loop –How to copy pixels from one picture to a specified location in another picture

NestedLoops-Mod7-part33 Copying Pixels to a New Picture Need to track the source picture x and y –And the target picture x and y We can use any picture –As the target picture Several blank pictures are available –640x480.jpg –7inX95in.jpg source target

NestedLoops-Mod7-part34 For loops A for loop can have multiple statements in each section with semicolons in between for(intialization; condition; increment){ // do something } For example: for(int a=0, b=0; a<5; a++,b++){ System.out.println(“(a,b)=”+a+”, “+b); } (a,b)=0,0 (a,b)=1,1 (a,b)=2,2 (a,b)=3,3 (a,b)=4,4

NestedLoops-Mod7-part35 Copy Picture Algorithm Copy a picture to another picture –Create the target picture object –Create the source picture object Loop through the source picture pixels –Get the source and target pixels –Set the color of the target pixel to the color of the source pixel

NestedLoops-Mod7-part36 CopyOver Method – in a NEW class. public class Duplicate { public static void copyOver () { String sourceFile = “name your source file here”; String targetFile = “name the target file here”; Picture sourcePicture = new Picture(sourceFile); Picture targetPicture = new Picture(targetFile); Pixel sourcePixel = null; Pixel targetPixel = null; Convert the Algorithm into code //Create variables to hold the pixels while you // transfer the color over Create the target picture object Create the source picture object

NestedLoops-Mod7-part37 Convert the Algorithm to Code Loop through the source picture pixels

NestedLoops-Mod7-part38 CopyOver Method - Continued What goes here? Where do you get the target pixel from? This code goes inside the nested loops so every pixel in the source file gets copied over into the target file. Be sure your source file is smaller than your target file! Get the source and target pixels Set the target pixel color to the source pixel color

NestedLoops-Mod7-part39 Copying Pixels to a New Picture What if we want to copy the target to a different location in the source than 0,0 –Say startX and startY What is an algorithm that will do this? –Use the same for loops going through all pixels in the source picture but add startX and startY to the target x,y position source target

NestedLoops-Mod7-part310 What if you want to eliminate the background of the source picture? Blue backgrounds were made to eliminate Before changing the color of the target pixel, ask if the color of the source picture is blue Only change the target picture if the source is NOT blue. Color src = sourcePixel.getColor( ): if(!src.equals(Color.blue)) /// change the color of the target pixel to src which is the color of the source pixel NOTE: you must import the Color class to use Colors import java.awt.Color;

NestedLoops-Mod7-part311 Copy to Position Exercise First add a ladybug to position 0,0 in the garden without any changes. Next: Add code to eliminate any blue in the source picture Last: Add ladybugs to 3 different locations in the garden by with 3 different x and y values eliminating the blue background. Use these pictures: ladybug.gif and garden.jpg