1 / 14

Creative Commons Attribution Non-Commercial Share Alike License

Creative Commons Attribution Non-Commercial Share Alike License. http://creativecommons.org/licenses/by-nc-sa/3.0/ Original Developer: Beth Simon, 2009 bsimon@cs.ucsd.edu. CSE8A Lecture 20. Read next class: read pg 293-300 Freshman seminar:

crwys
Télécharger la présentation

Creative Commons Attribution Non-Commercial Share Alike License

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. Creative Commons AttributionNon-Commercial Share Alike License • http://creativecommons.org/licenses/by-nc-sa/3.0/ • Original Developer: Beth Simon, 2009bsimon@cs.ucsd.edu

  2. CSE8A Lecture 20 • Read next class: read pg 293-300 • Freshman seminar: • Peer Instruction: Exploring a Revolution in College Science Teaching • Find out more about the theory behind clicker use • Analyze data from this and previous classes! • CSE 8A Art Show! Sat Nov 14 10:30-12 noon • Submit either your collage or chromakey (one per pair) • Art show open to all UCSD students • JSOE High School Outreach Day -- >110 high schoolers (and their parents) • We want MORE, GREAT people in CSE at UCSD!

  3. Midterm: Avg 83%90-80-70-60min 55% on individual final • Answers posted on line tomorrow • Midterms available for pickup Thurs/Fri in lab hours and in class

  4. By the end of today’s class you should be able to… • LG41: Read, trace, and write code to change the volume of a Sound object (using for each, while and for loops) • LG42: Compare and contrast the difference between changing the Color of Pixels in a Picture to changing the volume of SoundSamples in a Sound.

  5. How would we fill in this SampleSound[]

  6. The Sample Rate that the Sound class ASSUMES is 22KHz:How long is a SampleSound[] in a Sound object of 1 second? • 22 elements • 11,000 elements • 22,000 elements • 44,000 elements • We can’t tell from the data provided

  7. Write code which makes the following changes • Here’s a Sound String fileName = FileChooser.pickAFile(); Sound noise = new Sound(fileName); SoundSample[] noiseArray = noise.getSamples(); <<< PICK SOME CODE >>> int i = 0; while (i < noiseArray.length) { SoundSample sample = noiseArray[i]; int foo = sample.getValue(); sample.setValue(foo/2); } for (SoundSample sample: noiseArray) { int foo = sample.getValue(); sample.setValue(foo/2); } for (int i = noiseArray.length/2; i < noiseArray.length) { SoundSample sample = noiseArray[i]; int foo = sample.getValue(); sample.setValue(foo/2); }

  8. What does that code do? • But before we do that…

  9. So modified from the midterm: 0: Pixel[] pixelArray = this.getPixels(); 1: int mystery; 2: for(int i = pixelArray.length/4; i < 3*pixelArray.length/4; i++) 3: { 4: mystery = (pixelArray[i].getBlue() + pixelArray[i].getGreen() + pixelArray[i].getRed() ) / 3; 5: Color thing = new Color(mystery, mystery, mystery); 6: pixelArray[i].setColor(thing); 7: } 8: • This code modifies the middle half (from the top and bottom) of the picture • This code modifies the middle half (from the left and right) of the picture • This code loops over the pixels in the Pixel array starting at length/4 and up to 2*length/4 and gets the red, blue and green values adds them up and divides by 3 and sets that pixel to the calculated value

  10. Questions of the form:What does this code do should have what kind of answer? • A short sentence your grandmother can understand • A short sentence that describes the loop structure used • A short sentence that describes both the loop structure used and the method calls executed inside the loop • A paragraph at least 50 words long that the causes the graders’ eyes to glaze over

  11. REVIEW: Looking at this code… • Here’s a Sound String fileName = FileChooser.pickAFile(); Sound noise = new Sound(fileName); SoundSample[] noiseArray = noise.getSamples(); <<< PICK SOME CODE >>> int i = 0; while (i < noiseArray.length) { SoundSample sample = noiseArray[i]; int foo = sample.getValue(); sample.setValue(foo/2); } for (SoundSample sample: noiseArray) { int foo = sample.getValue(); sample.setValue(foo/2); } for (int i = noiseArray.length/2; i < noiseArray.length) { SoundSample sample = noiseArray[i]; int foo = sample.getValue(); sample.setValue(foo/2); }

  12. What does that code do • Makes a lower pitched sound during first half of play • Makes a quieter sound during first half of play • Makes a lower pitched sound during second half of play • Makes a quieter sound during second half of play • For each SoundSample element if the array it gets the Value and stores that in an int and then sets the Value with something that is half that

More Related