SlideServe
Menu
Préférences
© SlideServe · v2026

CSE 8A Lecture 15

aimee avatar
19 diapositives · 303 Views · Jul 26, 2014

CSE 8A Lecture 15. Reading for next class : 10.1-10.4 Today’s (and Tuesday’s) goals: Recover form the midterm (try not to worry too much—it was hard!) Practice tracing code Practice writing code from scratch Applying the same algorithm to a picture and a sound Modifying data “in place”

CSE 8A Lecture 15 - slide 1
01 / 19CSE 8A Lecture 15
1 / 17

Télécharger la présentation

CSE 8A Lecture 15
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. CSE 8A Lecture 15 • Reading for next class: 10.1-10.4 • Today’s (and Tuesday’s) goals: • Recover form the midterm (try not to worry too much—it was hard!) • Practice tracing code • Practice writing code from scratch • Applying the same algorithm to a picture and a sound • Modifying data “in place” • PSA 7 (sounds) due next Monday (11/19)

  2. Become a super hero! SnehaJayaprakash and Sarah Haroon

  3. Sandra Hui and Sandeep Gill

  4. Meditation Sachi Pitkin and Tiffany Truong

  5. Dylan Mozlowski and Luis Castillo

  6. Political commentary Michael Chin + Chu Jang

  7. Pop Culture Michelle Wu and Kirk Wong"It's a-me, Mario! And my brother, Luigi!" :D

  8. Jason Tan and Zeyu Chen

  9. ??? Daniel Chang and Kevin Nguyen

  10. So many more… go check it out!

  11. Options to raisePitch • Create new Sound • V1) Of exact length needed for higher pitched sound • V2) Of same length as original with “silence” at end

  12. Complete the raisePitch method public Sound raisePitch() { SoundSample[] original = this.getSamples(); Sound highP = new Sound( original.length / 2 ); SoundSample[] higher = highP.getSamples(); intnewPlace = 0; for (intorigI = 0; origI < original.length; origI+=2) { higher[newPlace].setValue( original[origI].getValue() ); newPlace++; } return highP; }

  13. Complete V2: Create new sound of same length with 0 at end public Sound raiseP() { Sound highP = new Sound(this); SoundSample[] original = this.getSamples(); SoundSample[] higher = highP.getSamples(); intnewPlace = 0;

  14. Solo: (60 sec) • Discuss: (2 min) • Group: (20 sec) How would the code belowchange the SoundSample array? // In the sound class public void mystery() { SoundSample[] original = this.getSamples(); for ( int index = 0; index < original.length; index++ ) { original[index].setValue( original[index/2].getValue() ); } } 100 150 200 300 140 10 -40 -100 -250 -150 A 100 100 150 150 200 200 300 300 140 140 D It causes an error B 100 100 100 100 100 100 100 100 100 100 C 100 200 140 -40 -250 10 -40 -100 -250 -150

  15. Discuss: (2 min) Lowering the Pitch of the Sound // In the sound class public void lowerPitch() { SoundSample[] original = this.getSamples(); for ( int index = 0; index < original.length; index++ ) { original[index].setValue( original[index/2].getValue() ); } } Problem: We are overwriting the values we need to use before we have used them! Possible solutions? 100 150 200 300 140 10 -40 -100 -250 -150 before 100 100 150 150 200 200 300 300 140 140 after

  16. Think solo (2 min) • Discuss: (2 min) Start at the end! // In the sound class public void lowerPitch() { SoundSample[] original = this.getSamples(); for ( ___________________________________________________ ) { original[index].setValue( original[index/2].getValue() ); } } 100 150 200 300 140 10 -40 -100 -250 -150 before 100 100 150 150 200 200 300 300 140 140 after

  17. Another name for this method… // In the sound class public void stretchInPlace() { SoundSample[] original = this.getSamples(); for ( int index = original.length-1; index >= 0; index-- ) { original[index].setValue( original[index/2].getValue() ); } } 100 150 200 300 140 10 -40 -100 -250 -150 before 100 100 150 150 200 200 300 300 140 140 after

  18. …that could apply to Pictures too! Complete the code below to stretch the calling object Picture both horizontallyand vertically // In the sound class public void stretchInPlace() { SoundSample[] original = this.getSamples(); for ( int index = original.length-1; index >= 0; index-- ) { original[index].setValue( original[index/2].getValue() ); } } // In the Pictureclass public void stretchInPlace() { for ( intx = ) { for ( int y = ) { Pixel source = this.getPixel( ); Pixel target = this.getPixel( ); target.setColor( source.getColor() ); } } }

  19. Load Phet simulator TODO • Reading for next class: 10.1-10.4 • Finish PSA7 (Bring headphones to lab!)