introduction to computer science chapter 8 n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Introduction to Computer Science – Chapter 8 PowerPoint Presentation
Download Presentation
Introduction to Computer Science – Chapter 8

Loading in 2 Seconds...

play fullscreen
1 / 12

Introduction to Computer Science – Chapter 8 - PowerPoint PPT Presentation


  • 80 Views
  • Uploaded on

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

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Introduction to Computer Science – Chapter 8' - tehya


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
introduction to computer science chapter 8

Introduction to Computer Science – Chapter 8

CSc 2010

Spring 2011

Marco Valero

overview
Overview
  • Drawing a canvas
  • Objects and constructors
  • Animation
  • Scope
  • Text and images
  • Sound
  • Scales and making music
  • Songs
drawing a canvas
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)
drawing a canvas1
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)
objects and constructors
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)
objects and constructors1
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?
animation
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
scope
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
text and images
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>)
sound
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
scales and making music
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)
songs
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