CS 100 Python commands, computing concepts, and algorithmic approaches for final Fall 2015

Similar documents
Image Size vs. File Size. gif File Compression. 1 Review. Slides05 - Pixels.key - September 28, 2015

Objectives. Connecting with Computer Science 2

Media Computation Module

Introduction to JES and Programming. Installation

Why do computers store all information as binary numbers? (B) This requires no translation of data after it is entered by the user.

Introduction to Computer Science (I1100) Data Storage

Announcements. Project 2 due next Monday. Next Tuesday is review session; Midterm 1 on Wed., EE 129, 8:00 9:30pm

Chapter 2: Introduction to Programming

Chapter 2: Introduction to Programming

Data Representation 1

Introduction to Computer Science. Course Goals. Python. Slides02 - Intro to Python.key - September 15, 2015

CHAPTER 2 - DIGITAL DATA REPRESENTATION AND NUMBERING SYSTEMS

CS 1124 Media Computation. Steve Harrison Lecture 4.2 (September 18, 2008)

An Introduction to Processing

CS 107 Practice Final Exam Spring Instructions: closed books, closed notes, open minds, 2 hour time limit. There are 4 sections.

CISC 1600 Lecture 3.1 Introduction to Processing

CS 1124 Media computation. Lecture 9.1, October 20, 2008 Steve Harrison

Binary representation and data

CS 101 Representing Information. Lecture 5

Data Representation From 0s and 1s to images CPSC 101

CS 1124 Media Computation Lecture 2.2. Steve Harrison September 3, 2008

GCSE Computing. Revision Pack TWO. Data Representation Questions. Name: /113. Attempt One % Attempt Two % Attempt Three %

2nd Paragraph should make a point (could be an advantage or disadvantage) and explain the point fully giving an example where necessary.

CMPSCI 119 Fall 2018 Wednesday, November 14, 2018 Midterm #2 Solution Key Professor William T. Verts

Metamorphosis of Information. Chapter 2: Metamorphosis of Information. What is Information? What is Information? Chapter 2. The Computer Continuum 1

TOPIC 10 THE IF STATEMENT. Making Decisions. Making Decisions. If Statement Syntax. If Statement

TOPIC 10 THE IF STATEMENT

255, 255, 0 0, 255, 255 XHTML:

Lecture 1: What is a computer?

CpSc 101, Fall 2015 Lab7: Image File Creation

Bits, bytes, binary numbers, and the representation of information

Digital Media. Daniel Fuller ITEC 2110

To start, open or build a simple solid model. The bracket from a previous exercise will be used for demonstration purposes.

Introduction to Programming with JES

Creating a Java class with a main method

Data encoding. Lauri Võsandi

Data Storage. Slides derived from those available on the web site of the book: Computer Science: An Overview, 11 th Edition, by J.

Next Generation Intelligent LCDs

CSE 8A Lecture 13. Reading for next class: Today s topics: Finish PSA 6: Chromakey! DUE TUESDAY Interm exam 3 next Friday. Sounds!

CS 177 Fall 2010 Final Exam

Your Name: Your TA's Name: 1 / 10 CS 1301 CS1 with Robots Fall 2008 Exam 3

MCS 2514 Fall 2012 Programming Assignment 3 Image Processing Pointers, Class & Dynamic Data Due: Nov 25, 11:59 pm.

Chapter 1. Data Storage Pearson Addison-Wesley. All rights reserved

[301] Bits and Memory. Tyler Caraza-Harter

15110 PRINCIPLES OF COMPUTING SAMPLE EXAM 2

Languages. Solve problems using a computer, give the computer instructions. Remember our diaper-changing exercise?

3 Data Storage 3.1. Foundations of Computer Science Cengage Learning

Flying Start AS Computer Science. September 2015

The Warhol Language Reference Manual

Color and Shading. Color. Shapiro and Stockman, Chapter 6. Color and Machine Vision. Color and Perception

Introduction to Flash - Creating a Motion Tween

Bits and Bit Patterns

Elementary Computing CSC 100. M. Cheng, Computer Science

Final Study Guide Arts & Communications

8/31/2015 BITS BYTES AND FILES. What is a bit. Representing a number. Technically, it s a change of voltage

CS101 Lecture 12: Image Compression. What You ll Learn Today

The pixelman Language Reference Manual. Anthony Chan, Teresa Choe, Gabriel Kramer-Garcia, Brian Tsau

IMAGE COMPRESSION USING FOURIER TRANSFORMS

计算原理导论. Introduction to Computing Principles 智能与计算学部刘志磊

CS 315 Software Design Homework 1 First Sip of Java Due: Sept. 10, 11:30 PM

User Guide Belltech Systems, LLC

Midterm Exam 2B Answer key

Jianhui Zhang, Ph.D., Associate Prof. College of Computer Science and Technology, Hangzhou Dianzi Univ.

Standard File Formats

Programming for Non-Programmers

Example 1: Denary = 1. Answer: Binary = (1 * 1) = 1. Example 2: Denary = 3. Answer: Binary = (1 * 1) + (2 * 1) = 3

Topics. Hardware and Software. Introduction. Main Memory. The CPU 9/21/2014. Introduction to Computers and Programming

Compression. storage medium/ communications network. For the purpose of this lecture, we observe the following constraints:

Numbers and their bases

How to Make a Poster Using PowerPoint

CS1114: Matlab Introduction

Sketchpad Graphics Language Reference Manual. Zhongyu Wang, zw2259 Yichen Liu, yl2904 Yan Peng, yp2321

CS 315 Data Structures Fall Figure 1

XPM 2D Transformations Week 2, Lecture 3

Unicode. Standard Alphanumeric Formats. Unicode Version 2.1 BCD ASCII EBCDIC

Exploring Microsoft Office Word 2007

CS 1301 Final Exam Review Guide

PREPARING FOR PRELIM 1

Ordinary Differential Equation Solver Language (ODESL) Reference Manual

Lab 7: Python Loops and Images 1

Part 1 Change Color Effects, like Black & White

XPM 2D Transformations Week 2, Lecture 3

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

SMURF Language Reference Manual Serial MUsic Represented as Functions

egrapher Language Reference Manual

Turtle Tango (TT) Language Reference Manual

Teaching KS3 Computing. Session 3 Theory: More on binary and representing text Practical: Introducing IF

Here is a sample IDLE window illustrating the use of these two functions:

COMP-202: Foundations of Programming. Lecture 26: Image Manipulation; Wrap-Up Jackie Cheung, Winter 2015

BCC Rays Ripply Filter

Using Microsoft Word. Working With Objects

CS Lab 8. Part 1 - Basics of File I/O

Midterm Review. October 17

8/16/12. Computer Organization. Architecture. Computer Organization. Computer Basics

Unit 2 Digital Information. Chapter 1 Study Guide

Colour and Number Representation. From Hex to Binary and Back. Colour and Number Representation. Colour and Number Representation

Microsoft Office Word 2010

CS1114: Matlab Introduction

Software and Hardware

CS 177 Fall 2010 Exam II

Transcription:

CS 100 Python commands, computing concepts, and algorithmic approaches for final Fall 2015 These pages will NOT BE INCLUDED IN THE MIDTERM. print - Displays a value in the command area - Examples: - print Hello - print 10 - print x, where x is a variable. Its value will be printed. assignment statement - Used to change the value of a variable - Examples: def file = pickafile() color = red - Used to define a function - The names inside the parentheses on the def line are parameters. They get their value when the function is called. def HelloWorld (name) : print Hello, + name calling a function - Executes the function, assigning argument values to parameter names - The names inside the parentheses when a function is called are arguments. Their value is assigned to the parameter in the same position on the def line of the function. return HelloWorld ( Mary Lyon ) - A return statement allows a function to compute a value and report it back to the caller - The caller saves the value in a variable using an assignment statement

def loadpicture () : file = pickafile() pic = makepicture(file) return pic - Then the caller can say: mypic = loadpicture() for loop - Repeats the statements inside the loop for each value looped over for p in getpixels(picture) : setcolor (p, red) - Nested for loops are handy for selecting a rectangular part of an image or for doing image manipulations based on the location of a pixel. if statement - Executes some statements only when a condition is true # Shadows if (grayness < 63) : redness = redness * 1.1 blueness = blueness * 0.9 # Midtones elif (grayness < 192) : redness = redness * 1.15 blueness = blueness * 0.85 # Highlights else : redness = redness * 1.08 blueness = blueness * 0.93 - An if-statement can have any number of elif parts, including 0. The else part is optional and must come last. The statements associated with the first condition that is true are executed and the rest of the if-statement is skipped. The else part is executed if none of the conditions are true. Computing concepts you should be familiar with These are just the highlights. Questions on the exam may go beyond this level of detail. - An algorithm is a sequence of instructions describing how to complete a task. A program is an algorithm written in a programming language.

- Abstraction is describing a solution in a way that you use already understood concepts in your description, rather than providing complete detail. A function is a way of defining an abstraction, by giving a name to a list of instructions. - Syntax refers to the grammar rules of a programming language. - Semantics defines what a programming language construct means. - Variables allow you to use names for values, where the variable can have different values at different times. - The scope of a variable is the part of the program where the variable is known. A parameter or a variable set within a function has the function as its scope. - The computer encodes all data as binary, just 0s and 1s. The same sequence of 0s and 1s can mean different things depending on its context. For example, it could be a number, a letter, or a color. - ASCII is the most common encoding of characters into binary. Unicode is another encoding that can support many different alphabets and common symbols. - JPEG and GIF are two different formats for images that compress images so they take less space on disk than their complete bitmap representation. - Vector graphics is a way of representing an image by providing instructions to draw the image rather than describing the image directly. - A bit can take on one of 2 values, 0 or 1. A byte is 8 bits and can take on any value between 0 and 255. - Images are made up of pixels. A pixel has a location identified by its row and column numbers. Each pixel has a color. - RGB represents a color with a red value, a green value and a blue value. Each of these values can range from 0 to 255. Black is 0, 0, 0. White is 255, 255, 255. Any color where the R, G, and B values are the same is a shade of gray. - A test function allows us to easily re-run functions we are writing without needing to do a lot of typing in the console. - We can compute the negative of a color by subtracting each RGB color component from 255 and using those values to create a new color. - We can convert an image to grayscale by averaging the red, green and blue values of each pixel. Luminance is another word we use for this average. - Chromakey is a technique used to record something or someone against a solid background, often bright green, so that the object or person can be separated from the background and copied cleanly into another image. - Sound is caused by changes in air pressure. A sound wave is a visual representation of these air pressure changes over time. - The amplitude of a sound wave is its height above or below a middle line. Amplitude affects the volume. - The frequency of a sound wave is how often the sound wave repeats in one second. Frequency determines pitch.

- Sound is recorded digitally by sampling it at fixed intervals and recording the values found. More frequent sampling generally results in higher quality sound. - Normalizing a sound changes the amplitude of a sound so that its highest amplitude is at the maximum value of 32,767. - Notes are chorded by normalizing each and then averaging their values. - A sound wave that is a sine wave produces a "pure" note. The same pitch can be created with different shape sounds, like square waves, or less regular waves such as those that come from a musical instrument as long as the frequency is the same as that of the sound wave. Algorithmic approaches We have been working with some standard algorithmic approaches in the functions that we have been writing in class. Image algorithms When we want to treat all pixels in an image the same way for pixel in getpixels ( <picture> ) : <instructions to change the pixel> When we want to change a rectangular portion of a picture for row in range ( <top row>, <bottom row> ) : for col in range ( <left col>, <right col> ) : pixel = getpixel ( <picture>, col, row ) <instructions to change the pixel> When we want to create a new picture based on the contents of an existing picture <canvas> = makeemptypicture ( <width>, <height> ) for row in range ( <top row>, <bottom row> ) : for col in range ( <left col>, <right col> ) : <original pixel> = getpixel ( <picture>, col, row ) <calculate row & column to copy to on the canvas> <canvas pixel> = getpixel (<canvas>, <canvas col>, <canvas row> ) setcolor ( <canvas pixel>, getcolor ( <original pixel> ) ) return <canvas> When we want to treat pixels differently based on their original color, we use an ifstatement for p in getpixels (pic) : if <some condition is true> : setcolor (p, <some color> ) Testing We separate the loading of files and the displaying of images into a test function to keep the image manipulation function more reusable.

When the image manipulation function modifies the image in place, the test function generally follows this pattern def test<func> () : file = <file name> picture = makepicture (file) explore (picture) <image manipulation function> (picture) explore (picture) When the image manipulation function creates a new canvas, the test function generally follows this pattern def test<func> () : file = <file name> picture = makepicture (file) explore (picture) copy = <image manipulation function> (picture) explore (copy) Sound algorithms When we want to treat all samples in a sound the same way for sample in getsamples ( <sound> ) : <instructions to change the sample> When we want to change a sample based on its position for index in range ( <first position>, <last position> ) : sample = getsamplevalueat ( <sound>, index ) <instructions to change the sample> When we want to create a new sound based on the contents of an existing sound <new sound> = makeemptysound ( <number of samples> ) for index in range ( <first position>, <last position> ) : <original sample> = getsamplevalueat ( <sound>, index ) <calculate position to copy to in the new sound> <calculate new sample value> setsamplevalueat ( <new sound>, <new position>, <new value> ) return <new sound> Before combining sounds, we generally normalize the sounds so that they have the same relative volume. def normalize (sound): # Find the highest value in the sound highestvalue = 0 for sample in getsamples (sound): if getsamplevalue (sample) > highestvalue : highestvalue = getsamplevalue ( sample ) # Calculate the multiplier to maximize the highest value

multiplier = 32767.0 / highestvalue # Apply the multiplier to all the samples in the sound changevolume (sound, multiplier) To chord two notes, we first normalize the notes and then average their values def chord ( note1, note2 ) : # Normalize the notes normalize (note1) normalize (note2) # Create a new sound if getlength ( note1 ) < getlength (note2) : newlength = getlength (note1) else : newlength = getlength (note2) newsound = makeemptysound (newlength) # Walk over the 2 notes for index in range (newlength) : value1 = getsamplevalueat (note1, index) value2 = getsamplevalueat (note2, index) # Average their values and store that in the chorded sound setsamplevalueat (newsound, index, (value1 + value2) / 2) return newsound