Intro to Robots 8 Sights & Sounds. Intro to Robots Computing is more than Computation So many devices – iPod, digital cameras, etc – use computers to.

Slides:



Advertisements
Similar presentations
1 More on Applets Overview l Changing Colors l Changing Fonts & Styles l Applet Life-Cycle l Input using Dialog Window l Input using HTML parameters l.
Advertisements

Graphics Shapes. Setup for using graphics You have to import the graphics library You can use either “import graphics” or “from graphics import *” or.
Noadswood Science,  To know how to use Python to produce windows and colours along with specified co-ordinates Sunday, April 12, 2015.
Graphics You draw on a Graphics object The Graphics object cannot directly be created by your code, instead one is generated when the method paintComponent.
CS2984: Introduction to Media Computation Drawing directly on images.
Python Programming, 2/e1 CS177: Programming in Multimedia Objects Recitation Topic: Graphics Library.
Objectives Define photo editing software
CSC 160 Computer Programming for Non-Majors Lecture #8: Animations I Prof. Adam M. Wittenstein
Intro to Robots Lab 8. Intro to Robots Exercise 1: Follow the text’s suggestion and Google “color names list” Collect from the list a set of 25 colors.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Java Applets What is an Applet? How do you create.
Four simple expressions in meta. Data objects Pieces of data in a computer are called objects Today, we’ll talk about four kinds of objects Numbers Pictures.
1 Python Programming: An Introduction to Computer Science Chapter 3 Objects and Graphics.
Graphics and Multimedia. Introduction The language contains many sophisticated drawing capabilities as part of namespace System.Drawing and the other.
Chapter 4 Objects and Graphics
Chapter 1 Functions and Graphs Copyright © 2014, 2010, 2007 Pearson Education, Inc Distance and Midpoint Formulas; Circles.
Animation CSC 161: The Art of Programming Prof. Henry Kautz 10/14/2009.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 3 Variables, Calculations, and Colors Starting Out with Games.
Introduction to TouchDevelop
Chapter 5 Graphics.  We’ve been doing command line programming, but now it’s time to try GUI programming—programming in a graphical user interface, using.
Image Processing & Perception Sec 9-11 Web Design.
Scribbler Music Web Design Notes Your robot can play music by “beeping” the correct notes. Every note in music has a “frequency” – Physics of Frequencies:
Color Correct and Remove Keystoning A minimalist approach to photographing your art By Paul Marley.
Functions Part I (Syntax). What is a function? A function is a set of statements which is split off into a separate entity that can be used like a “new.
B.A. (Mahayana Studies) Introduction to Computer Science November March Logo (Part 2) More complex procedures using parameters,
Computer Science 111 Fundamentals of Programming I Introduction to Graphics.
Tutorial 1 Introducing Adobe Flash CS3 Professional
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 7 The Game Loop and Animation Starting Out with Games & Graphics.
Graphics Concepts CS 2302, Fall /3/20142 Drawing Paths.
Computer Science 112 Fundamentals of Programming II Graphics Programming.
Chapter 2 : Business Information Business Data Communications, 6e.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved CheckWriter Application Introducing Graphics and Printing.
Lecture 15: Intro to Graphics Yoni Fridman 7/25/01 7/25/01.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 2 Graphics Programming with C++ and the Dark GDK Library Starting.
Chapter 2 Functions and Graphs Copyright © 2014, 2010, 2007 Pearson Education, Inc Distance and Midpoint Formulas; Circles.
Introduction to Computer Science – Chapter 8 CSc 2010 Spring 2011 Marco Valero.
CSC1401. Learning Goals Understand at a conceptual level What is media computation? How does color vision work? How can you make colors with red, green,
Graphic Basics in C ATS 315. The Graphics Window Will look something like this.
Tkinter Canvas.
Digital Media Dr. Jim Rowan ITEC So far… We have compared bitmapped graphics and vector graphics We have discussed bitmapped images, some file formats.
Some Graphics CS303E: Elements of Computers and Programming.
(C) 2010 Pearson Education, Inc. All rights reserved.  Class Graphics (from package java.awt) provides various methods for drawing text and shapes onto.
Variables Art &Technology, 3rd Semester Aalborg University Programming David Meredith
Your robot can play a note by “beeping” Every note in music has a “frequency” – Physics of Frequencies: (
GRAPHICS MODULE 14 STUDY BOOK. Graphic commands SCREEN - puts the screen into graphics mode WINDOW - allows scaling of the screen LINE - 3 formats –LINE.
Creating a Simple Game in Scratch Barb Ericson Georgia Tech June 2008.
CSC 1010 Programming for All Lecture 7 Input, Output & Graphics.
Graphics Concepts CS 2302, Fall /17/20142 Drawing in Android.
Graphics and Java2D Chapter Java Coordinate System Origin is in _____________ corner –Behind title bar of window X values increase to the ________.
Create a Halloween Computer Game in Scratch Stephanie Smullen and Dawn Ellis Barb Ericson October 2008.
Chapter 1 Functions and Graphs Copyright © 2014, 2010, 2007 Pearson Education, Inc Distance and Midpoint Formulas; Circles.
Microsoft® Small Basic Exploring Shapes Estimated time to complete this lesson: 1 hour.
Digital Media Lecture 5: Vector Graphics Georgia Gwinnett College School of Science and Technology Dr. Jim Rowan.
Week 10 - Friday.  What did we talk about last time?  References and primitive types  Started review.
5. COMPUTING WITH GRAPHICS OBJECTS Dennis Y. W. Liu and Rocky K. C. Chang October 8, 2015 (Adapted from John Zelle’s slides)
Intro to Turtle Graphics (Part 2)
PyGame - Unit 1 PyGame Unit – – Introduction to PyGame.
Scanner Scanner Introduction: Scanner is an input device. It reads the graphical images or line art or text from the source and converts.
Adobe Photoshop CS4 – Illustrated Unit A: Getting Started with Photoshop CS4.
1 Sections 5.1 – 5.2 Digital Image Processing Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
CS 115 Lecture 6 Graphics Taken from notes by Dr. Neil Moore.
CompSci 4 Java 4 Apr 14, 2009 Prof. Susan Rodger.
Adobe Illustrator CS Design Professional WITH ILLUSTRATOR GETTING STARTED.
GUI in Python Ismail Abumuhfouz.
Introduction to Illustrator
Flash Interface, Commands and Functions
Image Processing & Perception
Lab 9 Intro to Robots.
Graphics Part I Taken from notes by Dr. Neil Moore
SSEA Computer Science: Track A
Graphics Part I Taken from notes by Dr. Neil Moore
Presentation transcript:

Intro to Robots 8 Sights & Sounds

Intro to Robots Computing is more than Computation So many devices – iPod, digital cameras, etc – use computers to do so much more than “compute”. Such devices manage and manipulate images and sounds in amazing ways. In this chapter we try to get some of that for ourselves.

Intro to Robots GraphWin(): Myro comes with a graphics windows in which we can play. We create it by invoking it by name: This produces a gray 200 x 200 pixel window. The myCanvas window becomes our canvas where we exploring drawing images. From myro import * myCanvas = GraphWin() Exercise: Are pixels round, square or rectangular?

Intro to Robots GraphWin(): Close it And create it again with a new name and size. Change its color myCanvas.close() myCanvas = GraphWin(‘Silly Scene’,200,300) myCanvas.setBackground(“white”)

Intro to Robots Moment of Reflection: Our graphics window is an “object” with a name – myCanvas. You can create an object by calling a function whose name identifies the “type” of object (also called its class). We communicate with our window by “sending it messages” myCanvas.setBackground(“white”) message name name of message “receiver” message argument myCanvas = GraphWin(‘Silly Scene’,200,300)

Intro to Robots Locating the Pixels Pixels, like points on the xy-plane, have coordinates. The coordinate numbering system begins in the top, left- hand corner. (0,0) (100,100)

Intro to Robots Creating More Objects Besides graphics windows objects we can create many others – points, lines, circles, etc. Up to this point, p only exists in the programming interface (IDLE). To see it, we need to place it on the graphics window at its specified location. Remember, we are sending a message to p to draw itself on the myCanvas graphics window. p = Point(100,125) p.draw(myCanvas)

Intro to Robots Point object messages: There are some more messages we can send to a Point. getX() # returns the x-coordinate getY() # returns the y-coordinate undraw() # makes the object disappear

Intro to Robots What’s the Point? Points by themselves are not so interesting. What is really the point is that with them we can draw lines. There is a lab exercise where we end up drawing a line by ourselves. Alternatively we can create a Line object. A Line object is a straight line between two end points. myLine = Line(Point(5,100), Point(50,200)) executing the Line function creates a new Line object the arguments of the Line function are its starting and ending Points. These points are created by calling the Point() function twice. myLine.draw()

Intro to Robots A real Fan of Lines. for n in range(0, 200, 5): L=Line(Point(n,25),Point(100,100)) L.draw(myCanvas) range(x,y,z) is a function that returns a list of numbers starting at x, x+z, x+2z, … until y all the lines drawn have a common end-point – Point(100,100) all the lines drawn have starting points with a common y-coordinate (25)

Intro to Robots Other Line functions: L = Line(Point(25,25), Point(100,100)) L.draw() start = L.getP1() # returns the starting point of line end = L.getP2() # returns the end point of line print start.getX(), start.getY(), end.getX(), end.getY() L.undraw() Exercise: If L is a line, print out the starting and ending coordinates of L as (x,y) print ‘(‘,L.getP1().getX(),’,’,L.getP1().getY(),’)’ print ‘(‘,L.getP2().getX(),’,’,L.getP2().getY(),’)’ We send L a message to return its starting point and the starting point a message to return its x-coordinate. Obviously, the dot (.) operator functions like +, left-to-right.

Intro to Robots Circles: The definition of a circle is “the set of points equidistant from a given point”. The Circle object has a similar definition. myCircle = Circle(Point(100,100), 50) myCircle.draw() center point radius

Intro to Robots Circle Functions: You can change and retrieve various Circle characteristics. c = Circle(Point(100, 150), 30) c.draw(myCanvas) centerPoint = c.getCenter() c.setOutline(“red”) # line color c.setFill(“yellow”) # interior fill color c.setWidth(5) # line width in pixels color = color_rgb(100,125,150) c.setFill(color) Exercise: Try out these commands

Intro to Robots Circle Example # Program to draw a bunch of # random colored circles from myro import * from random import * width = 500 height = 500 def makeCircle(x, y, r): # creates a Circle centered at point (x, y) of radius r # we plan to use randomly generated numbers x, y and r return Circle(Point(x, y), r) def makeColor(): # creates a new color using random RGB values red = randrange(0, 256) # returns a random number between 0 and 255 green = randrange(0, 256) # returns a random number between 0 and 255 blue = randrange(0, 256) # returns a random number between 0 and 255 return color_rgb(red, green,blue) main()

Intro to Robots Circle Example def main(): # Create and display a graphics window myCanvas = GraphWin("Cicrles", width, height) myCanvas.setBackground("white") # draw a bunch of random circles with random colors. N = 500 for i in range(N): # pick random center # point and radius # in the window x = randrange(0,width) y = randrange(0,height) r = randrange(5, 25) c = makeCircle(x, y, r) # select a random color c.setFill(makeColor()) c.draw(myCanvas)

Intro to Robots Function Definition Alternatives: Consider the following two examples: makeCircle() hides the details of makeCircle(x,y,r) exposes by requiring previously assigned values for x, y and r x = randrange(0,width) y = randrange(0,height) r = randrange(5, 25) c = makeCircle(x, y, r) def makeCircle(): # creates a Circle centered at point (x, y) of radius r x = randrange(0,width) # only if width is “global” y = randrange(0,height) # only if height is “global” r = randrange(5, 25) return Circle(Point(x, y), r)

Intro to Robots Variable Scope: Variables defined outside any function definition have “global” scope. They can be used anywhere in the program. Variables defined inside a function have scope restricted to that function. If you want to use their values in a different functions you need to pass them as arguments. def foo(): x = 4 # scope of x is inside foo() y = 5 # scope of y is inside foo() return bar() def bar(): z = x + y # fails because x and y are # have scope within foo() only return z def foo(): x = 4 y = 5 # now pass x and y as arguments return bar(x,y) def bar(a,b): z = a + b return z

Intro to Robots Pros and Cons Having global variables is nice because you can use them whenever you need them. However it gives you added responsibility not to misuse the variable (change its value by mistake, for example) A variable with a function scope can only be modified inside that function.

Intro to Robots Sound: Both the computer and the robot can beep(). What is Hertz? beep(1,440) # plays a 440 Hz tone for 1 second computer.beep(1,440) # computer plays the same tone Hertz is the unit for measuring frequencies 1 Hz = 1 cycle/second 1 cycle

Intro to Robots Sound (cont): Computer CPUs measure their “speed” in Gigahertz. Computer CPUs have an internal clock that “ticks” at the Gigahertz rate of the CPU. All the various components of a computer synchronize their activities against this clock. 1 Gigahertz = 10 9 cycles / second

Intro to Robots Sound (cont): Other periodic motions: What is sound? What can the human ear hear? earth rotational rate: 1/day = 1/86400 seconds = cycles/second cd rotational rate: 400 turns/second 52x cd rotational rate: 52*400/second = 20800/second hummingbird wing flap rate: flaps/second A periodic compression and decompression (refraction) of air. 1 cycle of sound = 1 compression + 1 decompression 440 cycles/second = 440 compressions and decompressions / second in the range 20Hz to 20000Hz (20KHz)

Intro to Robots What sounds can Scribbler make? A musical scale consists of 12 sounds You can move up or down an octave by multiplying or dividing by 2. The C-note in various octaves is identified as: C C#/Db D D#/Eb E F F#/Gb G G#/Ab A A#/Bb B C0 C1 C2 C3 C4 C5 C6 C7 C8

Intro to Robots Music: C4 has frequency Hz. Try it out with Scribbler. The notes in a scale are exponentially equidistant. By this we mean: C4 frequency = * 2 (0/12) Hz = * 2 0 Hz = Hz C#4 frequency = * 2 (1/12) Hz = * Hz = Hz D4 frequency = * 2 (2/12) Hz = * Hz = Hz D#4 frequency = * 2 (3/12) Hz = * Hz = Hz E4 frequency = * 2 (4/12) Hz = * Hz = Hz F4 frequency = * 2 (5/12) Hz = * Hz = Hz F#4 frequency = * 2 (6/12) Hz = * Hz = Hz G4 frequency = * 2 (7/12) Hz = * Hz = Hz G#4 frequency = * 2 (8/12) Hz = * Hz = Hz A4 frequency = * 2 (9/12) Hz = * Hz = Hz A#4 frequency = * 2 (10/12) Hz = * Hz = Hz B4 frequency = * 2 (11/12) Hz = * Hz = Hz C5 frequency = * 2 (12/12) Hz = * 2 1 Hz = Hz

Intro to Robots Music Tempo: Music has tempo. In tempo – a quarter note is 0.68 seconds –A half note is 1.36 seconds –A whole note is 2.72 seconds. 4444

Intro to Robots Myro Music: Playing notes by frequency and time is a pain. Myro lets you “write out a tune” as a string and then converts the string into a song. Each note in the string is either or where note = ‘C4’, etc and time = ¼, ½, 1, etc tune = “c 1; d 1; e 1; f 1; g 1; a 1; b 1; c7 1;“ song = makeSong(tune) computer.playSong(song) note time; note1 note2 time;

Intro to Robots Myro Music 2: You can also put your string in a file and myro will read the file and play the song. Of course, if you want, the robot can play the song itself, just drop the “computer” receiver tag. song = readSong(filename) computer.playSong(song)

Intro to Robots Myro Reference: The end of chapter 8 holds a review of the myro graphics function calls. GraphWin() GraphWin(,, ).close().setBackground( ) = color_rgb(,, ) Point(, ).getX().getY() Line(, ) Circle(, ) Rectangle(, ) Oval(, ) Polygon(,,,…) Polygon([,, …]) Text(, ) Image(, ).draw( ).undraw().getCenter().setOutline( ).setFill( ).setWidth( ).move(, )

Intro to Robots Myro Reference: The end of chapter 8 holds a review of the myro graphics function calls. beep(, ) beep(,, ).beep(, ).beep(,, ) robot.playSong( ) readSong( ) song2text(song) makeSong( ) text2song( )