1 / 110

Introduction to Media Computation

Introduction to Media Computation. Barb Ericson Georgia Institute of Technology May 2006. Media Computation: Teaching in a Relevant Context. Presenting CS topics with media projects and examples Iteration as creating negative and grayscale images Indexing in a range as removing redeye

tommy
Download Presentation

Introduction to Media Computation

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 Media Computation Barb Ericson Georgia Institute of Technology May 2006 Georgia Institute of Technology

  2. Media Computation: Teaching in a Relevant Context • Presenting CS topics with media projects and examples • Iteration as creating negative and grayscale images • Indexing in a range as removing redeye • Algorithms for blending both images and sounds • Linked lists as song fragments woven to make music • Information encodings as sound visualizations Georgia Institute of Technology

  3. Examples of Student Work Canon- LinkedList of (MIDI) Music Soup-Audio Collage Georgia Institute of Technology

  4. Where is it being used? • Introductory media computing in Python • Used for non-majors at Georgia Tech and ANU • Used for CS majors at U. Ill-Chicago, Kalamazoo College, Gainesville College. • Introduction to data structures in Java • Used at Georgia Tech and Gainesville College • Introduction to object-oriented programming in Java • Used at Dennison University, Duke, and U.Mass-Boston • Used in several high schools in Georgia Georgia Institute of Technology

  5. Results • Average CS1 success pre-MediaComp: Average 72.8%In MediaComp (51% female): Average 84% (as high as 90%) • Similar results at Gainesville, U.Ill-Chicago, ANU • Specific majors more dramatic:Management majors’s success rate 49% => 88% • Students are excited, and becoming CS majors, CS minors, CS teachers, and Computational Media majors (over 100, 25% female) Georgia Institute of Technology

  6. What works, Where it doesn’t • What works • Open-ended assignments to allow for student creativity and expression • Especially with their own media • Collaborative space for students to publicly share their media artifacts with others. • Transfer from Python =>Java • Where it doesn’t • MediaComp isn’t “just the slow path” • Not allowing students to be creative Georgia Institute of Technology

  7. Syllabus • Introduction to Java • Math operators, printing results, data types, casting, relational operators, Strings, variables • Introduction to Programming • Creating and naming objects • Using a turtle and a world • Creating new Turtle methods • Draw simple shapes • Using parameters Georgia Institute of Technology

  8. Syllabus - Continued • Modifying Pictures using Loops • One-dimensional arrays • Use for-each, while, and for loops to • Increase/decrease colors, fake a sunset, lighten and darken, create a negative, and grayscale Georgia Institute of Technology

  9. Syllabus - Continued • Modifying Pixels in a Matrix • Two-dimensional arrays • Nested loops • Copying, mirroring, blending, rotation, scaling Georgia Institute of Technology

  10. Syllabus - Continued • Conditionally Modifying Pixels • Boolean expressions • Using && and || • Replacing a color, reducing red-eye, edge detection, sepia-toned, posterize, highlight extremes, blurring, background subtractions, chromakey Georgia Institute of Technology

  11. Syllabus - Continued • Drawing on Pictures • Using existing Java classes • Inheritance • Interfaces • Drawing simple shapes, drawing text, general copy, general scale, shearing, gradient paint, general blending, clipping Georgia Institute of Technology

  12. Syllabus - Continued • Modifying all Samples in a Sound • 1D arrays • Loops • Conditional execution • Change volume, normalizing a sound (make it as loud as possible), force to extremes Georgia Institute of Technology

  13. Syllabus - Continued • Modifying Samples using Ranges • Loops • Clipping, splicing, reversing, mirroring Georgia Institute of Technology

  14. Syllabus - Continued • Combining and Creating Sounds • Class and private methods • Composing sounds, blending sounds, changing frequencies, and creating echoes • Creating sounds • Sine Waves, Square Waves, Triangle Waves • MP3 and MIDI Georgia Institute of Technology

  15. Syllabus - Continued Turtle ConfusedTurtle • Creating Classes • Identifying objects and classes • Defining a class • Overloading constructors • Creating and initializing an array • Creating getters and setters • Creating a main method • Javadoc comments • Reusing a class via inheritance • ConfusedTurtle Georgia Institute of Technology

  16. Syllabus - Continued • Creating and Modifying Text • String methods • Reading from and writing to files • Handling Exceptions • Creating a form letter • Modifying programs • Getting text from networks • Creating random sentences • Using text to shift between media Georgia Institute of Technology

  17. Syllabus - Continued • Making Text for the Web • Throwing exceptions, “unnamed” package, HashMap, Generics, and Iterators • Generating HTML • Create a web page from a directory • Create a web page from other web pages • Databases • Creating a web page from a database Georgia Institute of Technology

  18. Syllabus - Continued • Encoding, Manipulating, and Creating Movies • Frame-based animations with simple shapes and text • Special effects – fade out, fake sunset, and chromakey Georgia Institute of Technology

  19. Syllabus - Continued • Speed • What makes programs fast? • Compilers and Interpreters • Writing a graphics interpreter and compiler • Searching • Algorithms that can’t be written • What makes computers fast? • Clock rates, Storage, Display Georgia Institute of Technology

  20. Syllabus - Continued • Javascript • Syntax • User Interfaces • Multimedia Georgia Institute of Technology

  21. Introduction to Java • Introduction to DrJava • Math Operators • Integer and Floating Point • Casting • Primitive Types • Relational Operators • Order of Operations • How to print to the console • Representing Text (Strings) • Invoking Class and Object Methods • Using the Java API to find the methods for a class Georgia Institute of Technology

  22. What is DrJava? • DrJava is a free integrated development environment for doing Java programming • From Rice University • It is written in Java • It has several window panes in it • For creating programs (definitions pane) • For trying out Java code (interactions pane) • Listing of open files (files pane) Georgia Institute of Technology

  23. Math Operators Exercise • Open DrJava and do the following in the interactions pane • Subtract 8 from 12 • Add 7 to 5 • Divide 5 by 2 • Divide 4.6 by 2 • Multiply 8 by 10 • Find the remainder when you divide 13 by 5 Georgia Institute of Technology

  24. Console Output Exercise • Use System.out.println() to print the results of expression to the console • System.out.println(3 * 2); • System.out.println(14 – 5); • System.out.println(12 / 2); • System.out.println(256 + 234); • System.out.println("My" + "name"); • System.out.println("256 + 234"); • Try using System.out.print() instead • What is the difference? Georgia Institute of Technology

  25. Strings • Java has a type called: String • A string is an object that has a sequence of characters in Unicode • It can have no characters (the null string "") • It can have many characters • "This is one long string with spaces in it. “ • Everything in a string will be printed out as it was entered • Even math operations “128 + 234” • Java knows how to add strings • It returns a new string with the characters of the second string after the characters of the first • With no added space Georgia Institute of Technology

  26. Methods • Classes in Java define methods • Recipes or functions f(x) = x2 • May take input • May produce an output • Two Types • Object method • Sent as a message to an object • Implicitly passed the current object • Class method • Sent as a message to a class • Declared using the keyword static Georgia Institute of Technology

  27. Method Exercise • In DrJava’s interaction pane try these • Object methods • "HELLO".toLowerCase() • "This is a string".indexOf("is") • " This is ".trim() • Class methods • Math.abs(53) • Math.abs(-3) • Math.min(22,1) • Character.getNumericValue('b') Georgia Institute of Technology

  28. Message Always Have Parenthesis • You can tell that out.println() is sending a message • Because of the () • Messages always have () • Even if there are no parameters (arguments) • If you are sending data along with a message it goes inside the parentheses • Separated by commas • Math.min(3,4); Georgia Institute of Technology

  29. Java is Case Sensitive • Some programming languages are case sensitive • Meaning that min isn’t the same as Min • Or string isn’t the same as String • In Java primitive types are all lowercase • double, float, int, • Class names start with an uppercase letter • So Math and System are the names of classes Georgia Institute of Technology

  30. Java Naming Conventions • In Java only Class names start with an uppercase letter • System, BufferedImage, Picture • All other names start with lowercase letters but uppercase the first letter of each additional word • picture, fileName, thisIsALongName Georgia Institute of Technology

  31. Teaching Java using Turtles • How to add classes to your classpath in DrJava • How to create objects in Java • How to declare variables in Java • How to invoke methods on objects in Java • Objects control their data • And can refuse to do what you ask • How to create a method in Java • How to pass a parameter to a method in Java Georgia Institute of Technology

  32. Creating a Simulation • Computers let us simulate things • We do this by creating models of the things we want to simulate • We need to define what types of objects we will want in our simulation and what they can do • Classes define the types and create objects of that type • Objects act in the simulation • Objects can have data and know how to do things Georgia Institute of Technology

  33. Running a Simulation • How many objects does it take to get a person fed at a restaurant? • Pick people to be the customer, greeter/seater, waiter, chef, and cashier and have them role play • What data does each of these people need to do their job? • What do they need to know how to do? • What other objects do you talk about? • How about simulating going to a dentist? • Or to the movies? Georgia Institute of Technology

  34. Adding to the Classpath Click on Edit and then Preferences Add bookClasses directory Click on Add Click on Apply then OK Georgia Institute of Technology

  35. Creating Objects in Java • In Java to create an object of a class you use new Class(value, value, …); • Our Turtle objects live in a World object • We must create a World object first • Try typing the following in the interactions pane: new World(); Georgia Institute of Technology

  36. Creating Objects • If you just execute • new World(); • You will create a new World object and it will display • But you will not have any way to refer to it again • Once you close the window the object can be garbage collected • The memory can be reused • We need a way to refer to the new object • to be able to work with it again Georgia Institute of Technology

  37. Naming is Important • If you get a new pet one of the first things you do is name it • Gives you a way to refer to the new pet without saying • Please take that dog we got yesterday for a walk. • Please take Fifi for a walk. • In programming we name things we want to refer to again • Gives us a way to work with them • Like the World object • This is called declaring a variable Georgia Institute of Technology

  38. Declaring a Variable • To be able to refer to an object again we need to specify what type of thing it is and give it a name • This is also called declaring a variable • Type name; OR • Typename = new Class(value, value, …); • The equal sign doesn’t mean equal • But assign the value of the variable on the left to the result of the expression on the right • The following creates a variable named earth which refers to a World object created on the right • World earth = new World(); Georgia Institute of Technology

  39. Declaring Variables • Variables are names associated with values • If the type of the variable is null • It doesn’t refer to an object yet • Variables can be reused • World earth = null; • earth = new World(); • earth = new World(); null earth World Object 1 earth earth World Object 2 Georgia Institute of Technology

  40. Limits on Declaring Variables • You can't declare two variables with the same name! > World earth = new World(); > World earth = new World(); Error: Redefinition of 'earth' • You can change what an object variable refers to > World earth = new World(); > earth = new World(); Georgia Institute of Technology

  41. Turtle Basics • The world starts off with a size of 640 by 480 • With no turtles World earth1 = new World(); • The turtle starts off facing north and in the center of the world by default • You must pass a World object when you create the Turtle object • Or you will get an error: java.lang.NoSuchMethodException: Turtle constructor Turtle tommy = new Turtle(earth1); Georgia Institute of Technology

  42. Creating Several Objects • You can create several World objects World mars = new World(); • You can create several Turtle objects Turtle shar = new Turtle(mars); Turtle jen = new Turtle(mars); • One turtle is on top of the other Georgia Institute of Technology

  43. What do Objects Look Like? t1 : Turtle tina : Turtle • Objects are created with space for their data • Objects have a reference to the object that represents the class • Object of the class “Class” Pos = 320,240 Color = green Heading = 0 Pos = 110, 30 Color = blue Heading = 90 Turtle : Class Name = Turtle Fields = pos, heading, color Methods = forward, backward, turnLeft, turn … Georgia Institute of Technology

  44. Looking up Turtle Methods • Open bookClasses/doc/Turtle.html and find the methods for the following: • How to turn a turtle left 90 degrees? • How to turn a turtle by a specific amount? • How many methods will make a turtle go forward • How are they different? • What are the two ways to stop a turtle from being drawn? • How do you change the color of the pen? • What happens if you use setColor? • How would you draw a letter T with a Turtle? Georgia Institute of Technology

  45. Objects can Refuse • Turtles won’t move completely out of the boundaries of the world World world2 = new World(); Turtle turtle2 = new Turtle(world2); turtle2.forward(600); Georgia Institute of Technology

  46. Objects send Messages • Objects don’t “tell” each other what to do • They “ask” each other to do things • Objects can refuse to do what they are asked • The object must protect it’s data • Not let it get into an incorrect state • A bank account object shouldn’t let you withdraw more money that you have in the account Georgia Institute of Technology

  47. Creating a Method • We can name a block of Java statements and then execute them again • By declaring a method in a class • The syntax for declaring a method is • visibilityreturnTypename(parameterList) • Visibility determines access • Usually public or private • The return type is the type of thing returned • If nothing is returned use the keyword void • Name the method starting with a lowercase word and uppercasing the first letter of each additional word Georgia Institute of Technology

  48. public void drawT() { this.forward(100); this.turnLeft(); this.penUp(); this.forward(40); this.turn(180); this.penDown(); this.forward(80); this.hide(); } The visibility is public The keyword void means this method doesn’t return a value The method name is drawT There are no parameters Notice that the parentheses are still required The keyword this means the object this method was invoked on Example Method Georgia Institute of Technology

  49. Adding a Method to a Class 1. Open file Turtle.java 3. Compile open files 2. Type the method before the last } // end Georgia Institute of Technology

  50. Adding a Parameter to a Method • The method drawT will always draw the same size T (height of 100 with a cross bar of 80 on top) • But what if you want to draw different size Ts • By specifying the height • Use .8 x height for the length of the cross bar • You can pass the height that you want as a parameter • And calculate the length of the cross bar Georgia Institute of Technology

More Related