CS1315: Introduction to Media Computation Introduction to Programming.

Slides:



Advertisements
Similar presentations
The Windows File System and Windows Explorer To move around the file system and examine your files or get to one you want (say, to modify, delete or copy.
Advertisements

CS1315: Introduction to Media Computation Making sense of functions.
CS2984: Introduction to Media Computation Drawing directly on images.
Python: Modifying Pictures Using Loops. Review JES command area – program area Defining/using functions specifying a sequence of steps for what the function.
Created by Mark Guzdial, Georgia Institute of Technology; modified by Robert H. Sloan, University of Illinois at Chicago, For Educational Use. CS.
Media Computation in JES (Chapter 2) DM Rasanjalee Himali.
IT151: Introduction to Programming
Python: Making colors and Using Loops. Review JES command area – program area Defining/using functions specifying a sequence of steps for what the function.
Chapter 2: Introduction to Programming. Chapter Learning Objectives.
01-IntroToMediaComp1 Barb Ericson Georgia Institute of Technology Oct 2010 Introduction to Computer Science and Media Computation.
James Tam Programming: Part I In this section of notes you will learn how to write simple Jython programs using JES.
Graphics in Python using the JES environment
CS 102 Computers In Context (Multimedia)‏ 01 / 28 / 2009 Instructor: Michael Eckmann.
TOPIC 4 INTRODUCTION TO MEDIA COMPUTATION: DIGITAL PICTURES Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach.
Python Programming, 2/e1 Python Programming: An Introduction to Computer Science Chapter 2.
CS 101: Introduction to Computing Programming picture manipulations Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified by.
ICAPRG301A Week 4Buggy Programming ICAPRG301A Apply introductory programming techniques Program Bugs US Navy Admiral Grace Hopper is often credited with.
CS1315: Introduction to Media Computation Picture encoding and manipulation.
CS1315: Introduction to Media Computation Picture encoding and manipulation.
Download JES Tool JES: Jython Environment for Students
Lecture # 27 Python I. Python “Interpretive” language (vs. compiled) So is HTML, JavaScript. Python supports file I/O. JavaScript doesn’t Python is a.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #002 (January 17, 2015)
C++ Basics Structure of a Program. C++ Source Code Plain text file Typical file extension .CPP Must compile the C++ source code without errors before.
Python programming Introduction to the JES environment and basics of Python Reading: Chapters 1, 2 from “Introduction to Computing and Programming in Python”
Introduction to Java CS1316: Representing Structure and Behavior.
Programming Fundamentals. Today’s Lecture Why do we need Object Oriented Language C++ and C Basics of a typical C++ Environment Basic Program Construction.
CS1315: Introduction to Media Computation Introduction to Programming.
CS 177 Week 4 Recitation Slides Variables, Files and Functions.
CS 102 Computers In Context (Multimedia)‏ 01 / 26 / 2009 Instructor: Michael Eckmann.
CS1315: Introduction to Media Computation Making sense of functions.
CS 100 Introduction to Computing Introduction to JES Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified by Robert H. Sloan.
CS1315: Introduction to Media Computation Picture encoding and manipulation.
1 CS 177 Week 11 Recitation Slides Writing out programs, Reading from the Internet and Using Modules.
Introduction to Digital Media. What is it? Digital media is what computers use to; Store, transmit, receive and manipulate data Raw data are numbers,
Practical PC, 7 th Edition Chapter 4: File Basics.
CS 101: Introduction to Computing Color replacements and targeted color replacement (if statement) Developed by Mark Guzdial, Georgia Institute of Technology,
CSC 110 Using Python [Reading: chapter 1] CSC 110 B 1.
Lecture 5 1.What is a variable 2.What types of information are stored in a variable 3.Getting user input from the keyboard 1.
CS1315: Introduction to Media Computation Color replacements and targeted color replacement (IF)
1 Printing in Python Every program needs to do some output This is usually to the screen (shell window) Later we’ll see graphics windows and external files.
A Media Computation Cookbook Manipulating Images and Sounds for Use in Alice Part 1: Image Manipulations Part 2: Changing colors in an area Part 3: Chromakey.
A Media Computation Cookbook Manipulating Images and Sounds for Use in Alice Part 1: Image Manipulations Part 2: Advanced Image Manipulations, e.g., changing.
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
1 CS 177 Week 2 Recitation Slides Variables, Files and Functions.
CS1315: Introduction to Media Computation Introduction to JES.
Know what a computer is used for Understand the difference between hardware and software Be able to describe the way that data is stored in a computer.
Introduction to Computer Programming - Project 2 Intro to Digital Technology.
TOPIC 4 INTRODUCTION TO MEDIA COMPUTATION: DIGITAL PICTURES Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach.
CS1315: Introduction to Media Computation Introduction to Programming.
CS1315: Introduction to Media Computation Transforming pictures by index number.
Intro CS and Media Computation1 Barb Ericson Georgia Institute of Technology Feb 2010 Introduction to Computer Science and Media Computation.
Python programming Using the JES picture functions and defining new functions.
CS1315: Introduction to Media Computation Introduction to JES.
CS1315: Introduction to Media Computation Making sense of functions.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
CS 201 Lecture 1 (b) Using an IDE Tarik Booker CS 201: Introduction to Programming California State University, Los Angeles.
Multimedia Summer Camp
A Playful Introduction to Programming by Jason R. Briggs
Introduction to Python
CS1315: Introduction to Media Computation
Chapter 2: Introduction to Programming
Chapter 2: Introduction to Programming
Agenda – 1/31/18 Questions? Group practice problems
A Media Computation Cookbook
Programming Fundamentals Lecture #3 Overview of Computer Programming
Workshop for Programming And Systems Management Teachers
CS 177 Week 3 Recitation Slides
CS1315: Introduction to Media Computation
CS1315: Introduction to Media Computation
Presentation transcript:

CS1315: Introduction to Media Computation Introduction to Programming

Much of programming is about naming We name our data  Data: The “numbers” we manipulate  We call our names for data variables We name our recipes Quality of names determined much as in Philosophy or Math  Enough words to describe what you need to describe  Understandable

Naming our Encodings We even name our encodings  Sometimes referred to as types Some programming languages are strongly typed  A name has to be declared to have a type, before any data is associated with it  Python is not strongly typed

Our programs work with a variety of names You will name your functions  Just like functions you knew in math, like sine and gcd (Greatest Common Divisor) You will name your data (variables) You will name the data that your functions work on  Inputs, like the 90 in sine(90) Key: Names inside a function only have meaning while the function is being executed by the computer. (You’ll see what we mean.)

Names for things that are not in memory A common name that you’ll deal with is a file name  The program that deals with those is called the operating system, like Windows, MacOS, Linux A file is a collection of bytes, with a name, that resides on some external medium, like a hard disk.  Think of it as a whole bunch of space where you can put your bytes Files are typed, typically with three letter extensions .jpg files are JPEG (pictures),.wav are WAV (sounds)

Names can be (nearly) whatever we want Must start with a letter (but can contain numerals) Can’t contain spaces  myPicture is okay but my Picture is not Be careful not to use command names as your own names  print = 1 won’t work  (Avoid names that appear in the editor pane of JES highlighted in blue or purple) Case matters  MyPicture is not the same as myPicture or mypicture Sensible names are sensible  E.g. myPicture is a good name for a picture, but not for a picture file.  x could be a good name for an x-coordinate in a picture, but probably not for anything else

JES Functions A bunch of functions are pre-defined in JES for sound and picture manipulations  pickAFile()  makePicture()  makeSound()  show()  play() Some of these functions accept input values theFile = pickAFile() pic = makePicture(theFile)

Picture Functions makePicture(filename) creates and returns a picture object, from the JPEG file at the filename show(picture) displays a picture in a window We’ll learn functions for manipulating pictures later, like getColor, setColor, and repaint

Sound Functions makeSound(filename) creates and returns a sound object, from the WAV file at the filename play(sound) makes the sound play  but doesn’t wait until it’s done  blockingPlay(sound) waits for the sound to finish We’ll learn more later like getSample and setSample

COMPLETELY THE SAME: Values, names for those values, functions that return those values >>> file=pickAFile() >>> print file C:\Documents and Settings\Mark Guzdial\My Documents\mediasources\barbara.jpg >>> show(makePicture(file)) >>> show(makePicture(r"C:\Documents and Settings\Mark Guzdial\My Documents\mediasources\barbara.jpg")) >>> show(makePicture(pickAFile())) Put r in front of Windows filenames: r“C:\mediasources\pic.jpg”

Grabbing media from the Web Right-click (Windows) or Control-Click (Mac) Save Target As… Can only do JPEG images (.jpe,.jpg,.jpeg) Most images on the Internet are copyright. You can download and use them for your use only without permission.

Writing a recipe: Making our own functions To make a function, use the command def Then, the name of the function, and the names of the input values between parentheses (“(input1)”) End the line with a colon (“:”) The body of the recipe is indented (Hint: Use two spaces)  That’s called a block

A recipe for playing picked sound files def pickAndPlay(): myfile = pickAFile() mysound = makeSound(myfile) play(mysound) Bug alert!!! myfile and mysound, inside pickAndPlay(), are completely different from the same names in the command area.

A recipe for showing picked picture files def pickAndShow(): myfile = pickAFile() mypicture = makePicture(myfile) show(mypicture)

“Hard-coding” for a specific sound or picture def playSound(): myfile = "FILENAME" mysound = makeSound(myfile) play(mysound) def showPicture(): myfile = "FILENAME" mypict = makePicture(myfile) show(mypict) You can always replace data (a string of characters, a number…. whatever) with a name (variable) that holds that data …. or vice versa. Q: This works, but can you see its disadvantage?

Functions with inputs are more general-purpose def playNamed(myfile): mysound = makeSound(myfile) play(mysound) def showNamed(myfile): mypict = makePicture(myfile) show(mypict) Q: What functions do you need? Q: What (if any) should be their input(s)? A: In general, have enough functions to do what you want, easily, understandably, and in the fewest commands (i.e. by using more generic, less specific functions) But these are only questions of style

What can go wrong? Did you use the exact same names (case, spelling)? All the lines in the block must be indented, and indented the same amount. Variables in the command area don’t exist in your functions, and variables in your functions don’t exist in the command area. The computer can’t read your mind.  It will only do exactly what you tell it to do.

Programming is a craft You don’t learn to write, paint, or knit by attending knitting lectures and watching others knit.  You learn to knit by doing it. Programming is much the same.  You have to try it, make many mistakes, learn how to control the computer, learn how to think in Python. The six programs that you have to write in this class aren’t enough!  Do programming on your own!

What to do! Finish Lab1 and turn it in on time Have a small amount of fun Start Lab 2 Read Chapter 2 And the most important  Practice and experiment with JES