CSE8A Lecture 5 TODO: –FINISH PSA2 WITH YOUR PARTNER! Read next class: Section 5.1. PLAY WITH CODE! –Get stuck, then figure out how to get unstuck – it’s.

Slides:



Advertisements
Similar presentations
TOPIC 5 INTRODUCTION TO PICTURES 1 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B.
Advertisements

ManipulatingPictures-Mod6-part21 Manipulating Pictures, Arrays, and Loops part 2 Barb Ericson Georgia Institute of Technology.
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
Georgia Institute of Technology Manipulating Pictures, Arrays, and Loops part 1.
Peer Instruction for the First Time: Experiences of a First Time User in Computer Science Beth Simon Computer Science and Engineering University of California,
Workshop on Peer Instruction: Making Good Clicker Questions Beth Simon Computer Science and Engineering University of California, San Diego Credits: Sara.
©2004 Brooks/Cole Chapter 8 Arrays. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Sometimes we have lists of data values that all need to be.
CSE 8A Lecture 8 Reading for next class: None Prepare for In-term exam 2 PSA4: Collage and Picture Flip, DON’T WAIT (it’s longer than the previous PSAs)
CS 101: Introduction to Computing Programming picture manipulations Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified by.
TOPIC 7 MODIFYING PIXELS IN A MATRIX NESTED FOR LOOPS 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by.
NestedLoops-part11 Nested Loops – part 1 Barb Ericson Georgia Institute of Technology Nov 2009.
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
CSC1401 Viewing a picture as a 2D image - 1. Review from the last week We used a getPixels() to get all of the pixels of a picture But this has been somewhat.
CSE8A Lecture3 TODO: –Finish PSA1 individually (no partner!) and turn it in with the bundlePSA1 command GET AN INTERVIEW for PSA1 from a tutor See tutor.
ManipulatingPictures-part11 Manipulating Pictures, Arrays, and Loops part 1 Barb Ericson Georgia Institute of Technology Nov 2009.
Georgia Institute of Technology Movies part 5 Barb Ericson Georgia Institute of Technology April 2006.
CSE8A Lecture2 Check the class web page (and discussion board, linked form webpage) for news and info: cse8a.weebly.com Lab starts this week. Discussion.
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
Today’s lecture 2-Dimensional indexing Color Format Thread Synchronization within for- loops Shared Memory Tiling Review example programs Using Printf.
11 Working with Images Session Session Overview  Find out more about image manipulation and scaling when drawing using XNA  Start to implement.
Tables Web Authoring. This kind of a table THISIs aTABLE THISIs aTABLE THISIs aTABLE THISIs aTABLE.
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
Georgia Institute of Technology Manipulating Pictures, Arrays, and Loops Barb Ericson Georgia Institute of Technology August 2005.
TOPIC 6 MODIFYING PICTURES USING LOOPS 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and.
CSE 8A Lecture 8 Reading for next class: PSA4: Collage and Picture Flip, DON’T WAIT (it’s longer than the previous PSAs)
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
Processing can load images, display them on the screen, and change their size, position, opacity, and tint. You can load gif, png and jpg images in processing.
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
CS Class 05 Topics  Selection: switch statement Announcements  Read pages 74-83, ,
Graphic Basics in C ATS 315. The Graphics Window Will look something like this.
CSC1401 Manipulating Pictures. What we have done to date We have modified pictures by writing on top of them Using Turtles and using Graphics Drawing.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
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.
Recognizing Patterns Counting: continually updating a value by a fixed amount Counting raindrops int dropCount = 0; //Raindrop counter while (dropCount.
Georgia Institute of Technology Creating Classes part 2 Barb Ericson Georgia Institute of Technology June 2006.
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
Georgia Institute of Technology Manipulating Pictures, Arrays, and Loops Barb Ericson Georgia Institute of Technology August 2005.
CSE 8A Lecture 13 Reading for next class: Chapter 9 Today’s topics: –Sounds! Finish PSA 6: Chromakey! DUE TUESDAY Interm exam 3 next Thursday.
CSE 8A Lecture 14 Reading for next class: None (INTERM EXAM #3) Today’s topics: –More Sounds! PSA 6 due tonight PSA 7 (sounds) due next Monday (11/19)
Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/
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.
CompSci 4 Java 4 Apr 14, 2009 Prof. Susan Rodger.
Barbara Ericson Georgia Tech Sept 2005
Manipulating Pictures, Arrays, and Loops part 2
Manipulating Pictures, Arrays, and Loops part 2
Topic 6 Modifying Pictures Using Loops
Chapter 3 Syntax, Errors, and Debugging
CSE 8A Lecture 17 Reading for next class: None (interm exam 4)
Creative Commons Attribution Non-Commercial Share Alike License
What to do when a test fails
Manipulating Pictures, Arrays, and Loops part 3
Stack Lesson xx   This module shows you the basic elements of a type of linked list called a stack.
Manipulating Pictures, Arrays, and Loops part 2
Manipulating Pictures, Arrays, and Loops part 2
Manipulating Pictures, Arrays, and Loops
One-Dimensional Array Introduction Lesson xx
Manipulating Pictures, Arrays, and Loops part 5
CSE 8A Lecture 6 Reading for next class:
Manipulating Pictures, Arrays, and Loops part 3
Manipulating Pictures, Arrays, and Loops
Manipulating Pictures, Arrays, and Loops
Creative Commons Attribution Non-Commercial Share Alike License
February , 2009 CSE 113 B.
Manipulating Pictures, Arrays, and Loops
CSC1401 Manipulating Pictures 2
Presentation transcript:

CSE8A Lecture 5 TODO: –FINISH PSA2 WITH YOUR PARTNER! Read next class: Section 5.1. PLAY WITH CODE! –Get stuck, then figure out how to get unstuck – it’s how you learn! “I felt like a lost child when I first came in and tried this. But now I’m much more comfortable with how we’re supposed to be learning.” -- an “A” Student from CSE8A 2008

Your discussion groups Did you know…you were assigned not just a seat, but a group! Examine this layout to see who is in your group. –You MUST be discussing with the people shown in your group (same color) on this chart! –NOT just “anybody nearby to you”! –This prevents anybody from being left out (example: stuck between two groups neither of which really claims them) or other problems.

Your discussion groups Please take a moment to: –Shake hands with everyone in your group –Tell each other your names –What was your favorite TV or movie character when you were 8 years old?

CSE8A Today Arrays: from 2D to 1D, unraveling your arrays Debugging tips and tricks

Clicker Quickie: In the decreaseRed method in the book we see What happens if you remove the (int) ? Pixel[] pixelArray = this.getPixels(); int value = 0; for (Pixel pixelObj: pixelArray) { value = pixelObj.getRed(); value = (int) (value *.5); pixelObj.setRed(value); } A)value = value *.5 would cause an error B)pixelObj.setRed(value) would cause an error C)The red channel would be set to 0 for all Pixels D)Nothing would change 1)Solo ONLY: (45 sec)

CS Concept: while loops Pixel[] pixelArray = this.getPixels(); int value = 0; Pixel p = null; int index = 0; while (index < pixelArray.length) { value = pixelArray[index].getRed(); value = (int) (value * 0.5); pixelArray[index].setRed(value); index = index + 1; } 1)Solo: (60 sec) 2)Discuss: (2min) 3)Group: (30 sec) How many times is each section of code executed?

What does this code do?* A.Removes all red from the picture B.Changes ½ of the red pixels to not be red C.Reduces the red component of ½ of the pixels D.Reduces the red component of each pixel to ½ of its original value E.Sets the red component of each pixel to 0.5 Pixel[] pixelArray = this.getPixels(); int value = 0; int index = 0; while (index < pixelArray.length) { value = pixelArray[index].getRed(); value = (int) (value * 0.5); pixelArray[index].setRed(value); index = index + 1; } * This is something you WILL be asked to do on an exam/quiz. You should also be able to draw the memory model!

What pixels does this code modify? Pixel[] pixelArray = this.getPixels(); int value = 0; int index = 0; while (index < pixelArray.length/4) { value = pixelArray[index].getRed(); value = (int) (value * 0.5); pixelArray[index].setRed(value); index = index + 1; }

Pixel arrays and pixels in Pictures A Picture is a 2-dimensional array of pixels –Each pixel in the Picture has (x,y) coordinates, with x==0,y==0 at the upper-left-hand corner of the picture A Pixel[] pixel array is a 1-dimensional array of pixels –Each Pixel in the array has an integer index I, with I==0 indexing the first Pixel in the array How do the two relate to each other…?

Pixel arrays and pixels in Pictures How do the two relate to each other…? Picture pic = new Picture(“mypic.jpg”); Pixel[] pixArray = pic.getPixels(); (x) (y) (index) pic pixArray Width 4 Height 3 Length 12

Pixel arrays and pixels in Pictures How do the two relate to each other…? Picture pic = new Picture(“mypic.jpg”); Pixel[] pixArray = pic.getPixels(); The top row of pixels in comes first in pixArray, then the second row of pixels, etc. pixArray[ i ] corresponds to what (x,y) in pic ? i = y * pic.getWidth() + x Try it!

CS Concept: Bugs! Pixel[] pixelArray = this.getPixels(); int value = 0; int index = 0; while (index < pixelArray.length) { value = pixelArray[index].getRed(); value = (int)1.5 * value; pixelArray[index].setRed(value); index = index + 1; } This code is supposed to increase red by 1.5, but…

Debugging Loops: Tracing variables Pixel[] pixelArray = this.getPixels(); int value = 0; int index = 0; while (index < pixelArray.length) { value = pixelArray[index].getRed(); value = (int)1.5 * value; pixelArray[index].setRed(value); index = index + 1; } Step 1: Have a mental model of what the variables are supposed to do Step 2: Add print statements to make sure variables are doing what you think are. Think Step 1 (1 min) Discuss Step 1 (2 mins)

Debugging Loops: Tracing variables Pixel[] pixelArray = this.getPixels(); int value = 0; int index = 0; while (index < pixelArray.length) { value = pixelArray[index].getRed(); value = (int)1.5 * value; pixelArray[index].setRed(value); index = index + 1; } Where should you insert the following print statements in the code below? System.out.println( “Old value of red is ” + value ); System.out.println( “New value of red is ” + value ); A.1 & 2 B.1 & 3 C.2 & 3 D.3 & 4 E.2 & 4 Solo (2 mins) Discuss (3 mins) Group vote (30 sec)

DEBUGGING: This code should swap the red and blue components at each Pixel; what does it ACTUALLY do? A.It has a compiler error B.It sets the red value to be the same as blue C.It sets the blue value to be the same as red D.It really does swap them Pixel[] pixelArray = this.getPixels(); int value = 0; int index = 0; while (index < pixelArray.length) { Pixel pix = pixelArray[index]; value = pix.getRed(); value = pix.getBlue(); pix.setRed(value); pixelArray[index].setBlue(value); index++; } How could we fix it? Solo (2 mins) Discuss (2 mins) Group vote (30 sec)

Swapping: A better way Pixel[] pixelArray = this.getPixels(); int value = 0; int index = 0; while (index < pixelArray.length) { Pixel pix = pixelArray[index]; > index++; } value = pix.getRed(); pix.setRed(pix.getBlue()); pix.setBlue(value); value = pix.getRed(); pix.setBlue(pix.getRed()); pix.setRed(value); value = pix.getRed(); pix.setRed(value); pix.setBlue(pix.getRed()); value = pix.getRed(); pix.setBlue(value); pix.setRed(pix.getBlue()); Solo (2 mins) Discuss (2 mins) Group vote (30 sec)

What picture most accurately describes what this code does ? Pixel[] pixelArray = this.getPixels(); int value = 0; Pixel p = null; for(int index = 0; index < pixelArray.length-1; index++) { p = pixelArray[index]; q = pixelArray[index+1]; p.setRed(q.getRed()); p.setBlue(q.getRed()); p.setGreen(q.getGreen()); }

What picture most accurately describes what this code does ? Pixel[] pixelArray = this.getPixels(); int value = 0; Pixel p = null; for(int index = 0; index < pixelArray.length-1; index++) { p = pixelArray[index+1]; q = pixelArray[index]; p.setRed(q.getRed()); p.setBlue(q.getRed()); p.setGreen(q.getGreen()); }

Why does this code have an error? A.It tries to access pixelArray[-1] B.It tries to access pixelArray[0] C.It tries to access pixelArray[pixelArray.length] D.It tries to access pixelArray[pixelArray.length+1] E.None of the above Pixel[] pixelArray = this.getPixels(); int value = 0; Pixel p = null; for(int index = 0; index < pixelArray.length; index++) { p = pixelArray[index]; q = pixelArray[index+1]; p.setRed(q.getRed()); p.setBlue(q.getRed()); p.setGreen(q.getGreen()); }

Fill in the for(……) to loop over pixels bottom right to top left Like this: Pixel[] pixArr = this.getPixels(); for ( ) { //Some code doing set on pixArr[i] } first next etc.

TODO FINISH PSA2, do interview Go to discussion section for help getting started Read next class: Section 5.1 PLAY WITH CODE! –Get stuck, then figure out how to get unstuck – it’s how you learn!