Created by Mark Guzdial, Georgia Institute of Technology; modified by Robert H. Sloan, University of Illinois at Chicago, 2005. For Educational Use. CS.

Slides:



Advertisements
Similar presentations
CS1315: Introduction to Media Computation Making sense of functions.
Advertisements

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.
Study Skills & Study Tips. Everyone is different, different methods work for different people The Following are only Suggestions on improving upon your.
CS1315: Introduction to Media Computation Introduction to Programming.
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.
Last time 3 main components to a computer system Types of computers Talked about software – task oriented What are some kinds of data that a computer works.
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.
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)
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 1 Introduction to Computers and Programming.
CS190/295 Programming in Python for Life Sciences: Lecture 3 Instructor: Xiaohui Xie University of California, Irvine.
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.
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,
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.
“But it looks right”: Bugs in non-majors media programs Mark Guzdial College of Computing/GVU Georgia Institute of Technology.
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.
Introduction to Computer Programming - Project 2 Intro to Digital Technology.
Python Lesson 1 1. Starter Create the following Excel spreadsheet and complete the calculations using formulae: 2 Add A1 and B1 A2 minus B2 A3 times B3.
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.
CS 122 Engineering Computation Lab Lab1 Bruce Char Department of Computer Science Drexel University Summer 2009 ©By the author. All rights reserved. Permission.
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.
File I/O. I/O Flags Flags are passed to give some information about how the file is to be used. – Read only file – flag=0x0 – Write only file – flag=0x1.
CS 101: Introduction to Computing Referencing pixels directly by index number Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified.
Multimedia Summer Camp
Lecture 1b- Introduction
CS1315: Introduction to Media Computation
Chapter 2: Introduction to Programming
Chapter 2: Introduction to Programming
Topics Introduction to File Input and Output
First Python Program Professor Hugh C. Lauer CS-1004 — Introduction to Programming for Non-Majors (Slides include materials from Python Programming: An.
Agenda – 1/31/18 Questions? Group practice problems
A Media Computation Cookbook
Workshop for Programming And Systems Management Teachers
Notes about Homework #4 Professor Hugh C. Lauer CS-1004 — Introduction to Programming for Non-Majors (Slides include materials from Python Programming:
CS 177 Week 3 Recitation Slides
CS1315: Introduction to Media Computation
Topics Introduction to File Input and Output
Presentation transcript:

Created by Mark Guzdial, Georgia Institute of Technology; modified by Robert H. Sloan, University of Illinois at Chicago, For Educational Use. CS 100: Introduction to Computing 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 (but not annoyingly long and wordy)  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

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 Be careful not to use command names as your own names  print = 1 won’t work Case matters  “Print” is not the same as “print”  “myPicture” is not the same as “mypicture”

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

Picture Functions makePicture(filename) creates and returns a picture object, from the JPEG or GIF 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()))

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

A function 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. Put r in front of Windows filenames: r " C:\mediasources\pic.jpg "

A function that takes input def playNamed(myfile): mysound = makeSound(myfile) play(mysound) def showNamed(myfile): mypict = makePicture(myfile) show(mypict) What functions do you need? What should be their input? In general, have enough to do what you want, easily, understandably, and in the fewest commands. We’ll talk more about what that means later.

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.

MOST IMPORTANT THING TO DO TO PASS THIS CLASS! DO THE EXAMPLES! Try them out for yourself. Try to replicate them. Understand them  EVERY WEEK, TYPE IN AT LEAST TWO OF THE EXAMPLES FROM CLASS To understand a program means that you know why each line is there. You will encounter all the simple-but-confusing errors early—BEFORE you are rushing to get homework done!!

Programming is a craft You don’t learn to write, paint, play the piano, 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 programs that you have to write in this class aren’t enough (even for this class–much less a CS minor or major)!  Do programming on your own!