Python: Making colors and Using Loops. Review JES command area – program area Defining/using functions specifying a sequence of steps for what the function.

Slides:



Advertisements
Similar presentations
Introduction to Eclipse. Start Eclipse Click and then click Eclipse from the menu: Or open a shell and type eclipse after the prompt.
Advertisements

EasyGUI “Probably the Easiest GUI in the world”. Assumptions (Teachers’ Notes) This resources sets out an introduction to using easyGUI and Python
COMPUTER PROGRAMMING Task 1 LEVEL 6 PROGRAMMING: Be able to use a text based language like Python and JavaScript & correctly use procedures and functions.
CS2984: Introduction to Media Computation Drawing directly on images.
COMPUTER PROGRAMMING I Essential Standard 5.02 Understand Breakpoint, Watch Window, and Try And Catch to Find Errors.
Python: Modifying Pictures Using Loops. Review JES command area – program area Defining/using functions specifying a sequence of steps for what the function.
Desktop Publishing Lesson 1 — Working with Documents.
CS1315: Introduction to Media Computation Introduction to Programming.
Media Computation in JES (Chapter 2) DM Rasanjalee Himali.
 Adding Background image  Creating internal links  Creating external links  Save your document as a webpage(.mht) file.
James Tam Programming: Part II In this section of notes you will learn about more advanced programming concepts such as looping, functions.
Fundamentals of Programming in Visual Basic 3.1 Visual basic Objects Visual Basic programs display a Windows style screen (called a form) with boxes into.
Persistence of Vision What makes movies work is yet another limitation of our visual system: Persistence of vision We do not see every change that happens.
Graphics in Python using the JES environment
Scratch the Cat. Object Oriented Programing Writing computer programs Based on Objects Instead of Actions Based on Data Instead of Logic.
CS 102 Computers In Context (Multimedia)‏ 01 / 28 / 2009 Instructor: Michael Eckmann.
Georgia Institute of Technology Introduction to Media Computation Barb Ericson Georgia Institute of Technology May 2006.
TOPIC 4 INTRODUCTION TO MEDIA COMPUTATION: DIGITAL PICTURES Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach.
Image Processing & Perception Sec 9-11 Web Design.
CS 101: Introduction to Computing Programming picture manipulations Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified by.
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.
© 2011 Delmar, Cengage Learning Chapter 16 Annotating and Automating an Image.
Chapter 16 Annotating and Automating an Image. Chapter Lessons Add annotations to an image Create an action Modify an action Use a default action and.
Creating Multimedia Interaction with Windows Media Technologies 7.
Alice 2.0 Introductory Concepts and Techniques Project 1 Exploring Alice and Object-Oriented Programming.
Python programming Introduction to the JES environment and basics of Python Reading: Chapters 1, 2 from “Introduction to Computing and Programming in Python”
CS1315: Introduction to Media Computation Introduction to Programming.
1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Session 20 Graphical User Interface (GUI)
CS 100 Introduction to Computing Introduction to JES Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified by Robert H. Sloan.
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,
CS1315: Introduction to Media Computation Picture encoding and manipulation.
My Python Programmes NAME:.
GUI development with Matlab: GUI Front Panel Components GUI development with Matlab: Other GUI Components 1 Other GUI components In this section, we will.
line.net/ okpop.com/bar elythereflashin dex.html.
CSC 1010 Programming for All Lecture 7 Input, Output & Graphics.
Creating a picture in JES Use in the command window of JES (black background at bottom) to set the folder where the picture is to be saved >>> path = setMediaPath()
CSD 340 (Blum)1 Starting JavaScript Homage to the Homage to the Square.
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.
CMPF114 Computer Literacy Chapter 3 The Visual Basic Environment 1.
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!
CS1315: Introduction to Media Computation Introduction to JES.
THE C PROGRAMMING ENVIRONMENT. Four parts of C environment  Main menu  Editor status line and edit window  Compiler message window  “Hot Keys” quick.
TOPIC 4 INTRODUCTION TO MEDIA COMPUTATION: DIGITAL PICTURES Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach.
Python programming Introduction to the JES environment and basics of Python.
CS1315: Introduction to Media Computation Introduction to Programming.
Python: Working with pixels. Reminder: Conditionals if age < 18: showInformation(“Sorry, not allowed to vote yet.”) else: showInformation(“Please select.
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
Python programming Using the JES picture functions and defining new functions.
CS1315: Introduction to Media Computation Introduction to JES.
Desktop Publishing Lesson 1 — Working with Documents.
Multimedia Summer Camp
Development Environment
Persistence of Vision What makes movies work is yet another limitation of our visual system: Persistence of vision We do not see every change that happens.
Week 2.
Image Processing & Perception
Introduction to the JES environment and basics of Python
CS1315: Introduction to Media Computation
Download JES Tool JES: Jython Environment for Students
Week 1 Computer Programming Year 9 – Unit 9.04
Introduction to TouchDevelop
Introduction to Media Computation
A Media Computation Cookbook
CS 177 Week 3 Recitation Slides
CS1315: Introduction to Media Computation
Digital Story Telling with Frames
Presentation transcript:

Python: Making colors and Using Loops

Review JES command area – program area Defining/using functions specifying a sequence of steps for what the function should do. JES Functions for file manipulation JES->Files JES Functions for interacting with user JES-->Input/Output JES Functions for picture manipulation JES-->Pictures

Review: Functions in general F(a,b) 4‘a’ F(4, ‘a’) side-effects

Example: sqrt() sqrt(a) 4 2 side-effects

Example: showInformation() showInformation(message) message Pops up a new window displaying the message text

Example: requestNumber() requestNumber(“What is the answer to Life, the Universe and Everything?” ) “What is the answer to Life, the Universe and Everything?” Pops up a new window displaying the message text with an input box where the user can type in a number, e.g., 42 42

Example: makeEmptyPicture() makeEmptyPicture(300,200) 300 x 200 blank image 300 makePicture(width,height) creates and returns a picture object of the given dimensions 200

Example: show() show(picture-object) picture-object (an encoding of an image) Pops up a new window displaying image stored in picture-object

Example: pickAFile() pickAFile() Filename (eg: C:\Documents and Settings\mpapalas\My Documents\greenroom.jpg) Pops up a dialog box for the user to select a file

Example: makePicture() makePicture(filename) Picture object corresponding to image that is saved in theFile theFile (a string containing a file name) makePicture(filename) creates and returns a picture object, from the JPEG file at the filename

pickAFile() Pops up a dialog box for the user to select a file theFile A recipe for displaying picked picture files: def pickAndShow(): theFile = pickAFile()

pickAFile() Pops up a dialog box for the user to select a file makePicture(filename) pic theFile def pickAndShow(): theFile = pickAFile() pic = makePicture(theFile) A recipe for displaying picked picture files:

pickAFile() Pops up a dialog box for the user to select a file makePicture(filename) pic theFile show(picture-obj) Pops up a new window displaying image stored in the the picture object def pickAndShow(): theFile = pickAFile() pic = makePicture(theFile) show(pic) A recipe for displaying picked picture files:

pickAFile() Pops up a dialog box for the user to select a file makePicture(filename) pic theFile show(picture-obj) Pops up a new window displaying image stored in the the picture object def pickAndShow(): theFile = pickAFile() pic = makePicture(theFile) show(pic) A recipe for displaying picked picture files:

pickAFile() Pops up a dialog box for the user to select a file makePicture(filename) pic theFile show(picture-obj) Pops up a new window displaying image stored in the the picture object def pickAndShow(): theFile = pickAFile() pic = makePicture(theFile) show(pic) pickAndShow() A recipe for displaying picked picture files:

Reminder: Manipulating Pictures >>> pic1 = makeEmptyPicture(200,100) >>> show(pic1) >>> setAllPixelsToAColor(pic1, red) >>> show(pic1) >>> addText(pic1,30,50,“hello") similarly can add rectangles, lines, etc.

Reminder: Common errors >>> file = pickAFile() >>> pic = makePicture(file) >>> show(file) The error was:sample Name not found globally. A local or global name could not be found. You need to define the function or variable before you try to use it in any way. >>> show(pic) >>> print pic Picture, filename C:\Documents and Settings\mpapalas\Desktop\sample.jpg height 1200 width 1600 Oops!

Making new Colors Some names for common colors are predefined – try using the names: yellow, black, white, etc. makeColor() takes red, green, and blue values (in that order) between 0 and 255, and returns a Color object pickAColor() lets you use a color chooser and returns the chosen color

Color:(108,86,142) Position: (12,9) x = 12 y = 9 red=108green=86blue=142

Encoding RGB Colors go from (0,0,0) to (255,255,255) >>> pic2 = makeEmptyPicture(200,100) >>> show(pic2) >>> seafoam = makeColor(153, 255, 204) >>> setAllPixelsToAColor(pic2, seafoam ) >>> show(pic2)

Media Tools JES Picture function OR Media Tools menu How do you find out what RGB values you have? And where?

Saving to a file setMediaPath(): Prompts the user to pick a folder on the computer. JES then will look for files in that directory unless given a full path, i.e. one that starts with "c:\" writePictureTo(picture, path): picture: the picture you want to be written out to a file path: the path to the file you want the picture written to Takes a picture and a file name (string) as input, then writes the picture to the file as a JPEG. Example: >>> setMediaPath() writePictureTo(pic, “mypic.jpg”)

Conditionals if age < 18: showInformation(“Sorry, not allowed to vote yet.”) else: showInformation(“Please select candidate.”)

Repetition for number in range(0,N): pic =.... filename = base + str(number) writePictureTo(pic, filename)

Lists [“hi”, “hello”, “howdy”, “hiya”, “yo”] [10, 23, 15] [] range(0,6) range(1,4) range(3,8)

Assignment Step 1: Create a function makeMeSwatches() that makes lots of color swatches (small solid-colored image files). Specifically, your function should: –display a welcome message to the user –ask the user to say how many swatches – input that and save in a variable –create small files with images of solid color save each one with names "swatch00.jpg", "swatch01.jpg", "swatch02.jpg", etc (do this using a loop) –display a message letting the user know that the program is complete and swatches are saved in the default folder.

Assignment Step 2: To test your function: 1)from the command line, ask the user to select a folder for storing the swatches, using setMediaFolder() – you may have already done this during this session, so you only need to repeat it if you want to change the default folder for saving the files (and each time you start a new JES session). 2) invoke your function by using makeMeSwatches() from the command line. Try 10 for the number of swatches, and when it finishes running, check the folder you selected to make sure the files were created.

Assignment Step 3: Improve your function by adding a rectangle or other shape that moves to a different position with each frame. Be sure to test your function well, each time you make some changes.

Assignment Step 4: Make sure you have a folder with at least 100 images, named swatch00.jpg, swatch01.jpg, etc (or some other systematic name). In the command area, create a movie: swatchesMovie = makeMovieFromInitialFile("swatch00.jpg") Now use playMovie(swatchesMovie) to view your movie. You can adjust the number of frames/sec and view the movie or individual frames If you are satisfied with it, click Write Quicktime or Write AVI to save the movie.