CS1315: Introduction to Media Computation Introduction to Programming.

Slides:



Advertisements
Similar presentations
EasyGUI “Probably the Easiest GUI in the world”. Assumptions (Teachers’ Notes) This resources sets out an introduction to using easyGUI and Python
Advertisements

Speed CS A109. Big speed differences Many of the techniques we’ve learned take no time at all in other applications Select a figure in Word. –It’s automatically.
CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
Python: Modifying Pictures Using Loops. Review JES command area – program area Defining/using functions specifying a sequence of steps for what the function.
TOPIC 5 INTRODUCTION TO PICTURES 1 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B.
CS1315: Introduction to Media Computation Introduction to Programming.
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
 2005 Pearson Education, Inc. All rights reserved Introduction.
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.
James Tam Programming: Part I In this section of notes you will learn how to write simple Jython programs using JES.
CS1061 C Programming Lecture 2: A Few Simple Programs A. O’Riordan, 2004.
Programming Introduction November 9 Unit 7. What is Programming? Besides being a huge industry? Programming is the process used to write computer programs.
Graphics in Python using the JES environment
Python.
An Introduction to Textual Programming
CS 102 Computers In Context (Multimedia)‏ 01 / 28 / 2009 Instructor: Michael Eckmann.
CS 101: Introduction to Computing Programming picture manipulations Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified by.
Week 2 - Monday.  What did we talk about last time?  Software development  Lab 1.
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.
CS 102 Computers In Context (Multimedia)‏ 01 / 23 / 2009 Instructor: Michael Eckmann.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #002 (January 17, 2015)
Introduction to Programming Peggy Batchelor.
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”
5 BASIC CONCEPTS OF ANY PROGRAMMING LANGUAGE Let’s get started …
CS1315: Introduction to Media Computation Introduction to Programming.
Class 1: What this course is about. Assignment Read: Chapter 1 Read: Chapter 1 Do: Chapter 1 ‘workbook’ pages not finished in class Do: Chapter 1 ‘workbook’
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.
CS 101: Introduction to Computing Color replacements and targeted color replacement (if statement) Developed by Mark Guzdial, Georgia Institute of Technology,
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)
LCC 6310 Computation as an Expressive Medium Lecture 2.
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.
Python Let’s get started!.
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.
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.
C OMPUTER P ROGRAMMING 1 Input and Variables. I/O S TATEMENTS : I NPUT & V ARIABLES Input is the term used to describe the transfer of information from.
CS1315: Introduction to Media Computation Transforming pictures by index number.
Python programming Using the JES picture functions and defining new functions.
CS0007: Introduction to Computer Programming Primitive Data Types and Arithmetic Operations.
CS1315: Introduction to Media Computation Introduction to JES.
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
Lecture 1b- Introduction
Introduction to Python
CS1315: Introduction to Media Computation
Exceptions and files Taken from notes by Dr. Neil Moore
Chapter 2: Introduction to Programming
Chapter 2: Introduction to Programming
Exceptions and files Taken from notes by Dr. Neil Moore
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
CSIS110 - Introduction to Computer Science
Presentation transcript:

CS1315: Introduction to Media Computation Introduction to Programming

All about naming We name our data  Data: The “numbers” or values we manipulate  The names for data are "variables" We name our recipes/functions Quality of names determined much as in Philosophy or Math  Enough words to describe what you need to describe  Understandable

Naming our Encodings Even encodings have names (34 is a number, “hello” is text...)  Sometimes referred to as types Some programming languages are strongly typed  Python is considered strongly typed  but unlike java or C++, variables do not have to be declared of a given type  whatever data a variable refers to at a given moment determines its type

Python’s Typing x = 34its type is integer x = “hello”its type is now string the type is always determined by the data, not the variable itself

Programs contain a variety of names You will name your functions  Just like functions 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  parameters, like the 90 in sine(90) is an angle  def sine(angle): Key: Names inside a function only have meaning while the function is being executed by the computer.

Names for things that are not in memory A common name that you’ll deal with is a file name  Your computer’s operating system, like Windows, MacOS, Linux is software expert at dealing with files 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 (your information) Files are typed, typically with three letter extensions .jpg files are JPEG (pictures),.wav are WAV (sounds)

Jython names can be (nearly) anything Must start with a letter (but can contain digits) No spaces  myPicture is okay but my Picture is not No command names as your own names  print = 1 won’t work  (Hint: 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  This is a common and elusive error! Sensible names are indeed sensible  E.g. myPicture is a good name for a picture, but not for a sound file.  x could be a good name for an x-coordinate in a picture, but probably not for anything else - it is too vague

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

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

Sound Functions makeSound(filename) takes the filename of a WAV file, then reads, creates, and returns a sound object play(sound) plays the sound  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

A value can be: literally the value itself like 24 from a variable name that holds a value age = 24 now age can be used anywhere a 24 is needed a function that returns a value len([1, 22, 30, 14]) that is the same as 4

Windows paths >>> 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 (.jpg,.jpeg) Most images on the Internet are copyright. Without permission you can download and use them for your use only.

Writing a recipe: Making our own functions Use the command def Give the name of the function List the parameters between parentheses (height, weight) End the line with a colon : The body of the recipe is indented (Hint: Use three 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 unknown 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 = r”C:\bark.wav" mysound = makeSound(myfile) play(mysound) def showPicture(): myfile = r”C:\boat.jpg" 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 the disadvantage?

Function parameters allow flexibility 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 parameter(s)? A: In general, have enough functions to do what you want, easily, understandably, and flexibly (try for more generic, less specific functions)

What can go wrong when things look right? Did you use the exact same names (check case / check 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. Are your statements in the right order? Need to pick the file before you try to make a picture out of it. 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 ride a bike by attending biking lectures and watching others bike.  You learn to bike by biking! 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 HW programs that you have to write in this class aren’t enough!  Do programming on your own!  Play around with the class and book examples!