1 / 12

Introduction to Computer Science – Chapter 8

Introduction to Computer Science – Chapter 8. CSc 2010 Spring 2011 Marco Valero. Overview. Drawing a canvas Objects and constructors Animation Scope Text and images Sound Scales and making music Songs. Drawing a canvas. We’ve seen the canvas before Asking a question

tehya
Download Presentation

Introduction to Computer Science – Chapter 8

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. Introduction to Computer Science – Chapter 8 CSc 2010 Spring 2011 Marco Valero

  2. Overview • Drawing a canvas • Objects and constructors • Animation • Scope • Text and images • Sound • Scales and making music • Songs

  3. Drawing a canvas • We’ve seen the canvas before • Asking a question • Showing a picture • myCanvas = GraphWin() • myCanvas.close() • myCanvas.setBackground(‘white’) • myCanvas = GraphWin(‘My Masterpiece’, 200, 300)

  4. Drawing a canvas • Uses a grid layout of coordinates for position • (0,0) is the top left corner • We can create points and lines • p = Point(100, 50) • p.draw(myCanvas) • l = Line(Point(0,0), Point(100, 200)) • l.draw(myCanvas)

  5. Objects and constructors • We’ve seen this style of functions before • myList.append(‘a’) • myList.sort() • <object>.<function identifier>(<parameters>) • Think of variables as an object that encapsulates some data and functionality • We construct these objects with special functions called constructors • p = Point(100, 50)

  6. Objects and constructors • Objects may have many member functions • p = Point(100, 50) • p.getX() returns 100 • p.getY() returns 50 • l = Line(p, Point(75,200)) • l.getP1().getX() returns? • L.getP2().getX() returns?

  7. Animation • <graphic object>.undraw() • Erases object from the screen • Circles are defined as a point with a radius • c = Circle(Point(100, 50), 30) • c.draw(myCanvas) • By using the undraw and draw methods we can animate our graphics

  8. Scope • Scope is the ability to ‘see’ or ‘know of’ an identifier in python • Scope of an identifier in python is in ‘textual order’, and local to functions • A global defined at the top will be visible to all • A variable within a function will only be visible to that specific function’s body

  9. Text and images • We can create graphic representations of text • myText = Text(<anchor point>, <string>) • mytext = Text(Point(50,50), ‘hello world’) • mytext.draw(myCanvas) • We can also display images • myphoto = Image(<center point>, <file name>)

  10. Sound • We have used the beep command • beep(<seconds>, <frequency>) • We can make our computer beep as well • computer.beep(<seconds>, <frequency>) • Sorry, no wobble bass electro music

  11. Scales and making music • A scale is 12 notes • C C#/Db D D#/Eb E F F#/Gb G G#/Ab A A#/Bb B • Also known as an octave • We can double an octave by doubling the frequency • C3 (130.815) • C4 (261.63) • The lowest scribbler can go is A0(27.5 Hz)

  12. Songs • We can create a string of notes and durations for myro to play as a song • Note1 [Note2] Fraction of a Whole Note • ‘C5 1;’ • readSong(<file name>) • Reads a file and returns a song object • playSong(<song>) • Plays the given song • makeSong(<textual song>) • Returns a song object based on the string of notes given

More Related