Programming: Part II

Similar documents
Project Name Test Plan

Review. What about images? What about images? Slides04 - RGB-Pixels.key - September 22, 2015

Programs. onevent("can", "mousedown", function(event) { var x = event.x; var y = event.y; circle( x, y, 10 ); });

technology T05.2 teach with space MEET THE SENSE HAT Displaying text and images on the Sense HAT LED matrix

CHAPTER 7 BASIC GRAPHICS, EVENTS AND GLOBAL DATA

MultiSpec Tutorial: Visualizing Growing Degree Day (GDD) Images. In this tutorial, the MultiSpec image processing software will be used to:

Part 1: Introduction to Computer Graphics

Fig. 21-1CIF block diagram. Translate the input video data into the requisite data format

Hour of Code: Teacher Guide

Chapter 6: Modifying Sounds Using Loops

PYROPTIX TM IMAGE PROCESSING SOFTWARE

-1GUIDE FOR THE PRACTICAL USE OF NUBES

High-Definition, Standard-Definition Compatible Color Bar Signal

Professor Henry Selvaraj, PhD. November 30, CPE 302 Digital System Design. Super Project

Subtitle Safe Crop Area SCA

Remote Application Update for the RCM33xx

Registers and Counters

Chapter 4. Logic Design

XI'AN NOVASTAR TECH CO., LTD

Sample: A small part of a lot or sublot which represents the whole. A sample may be made up of one or more increments or test portions.

SpectraPlotterMap 12 User Guide

ECE438 - Laboratory 1: Discrete and Continuous-Time Signals

Training Note TR-06RD. Schedules. Schedule types

Using the Agilent for Single Crystal Work

KRAMER ELECTRONICS LTD. USER MANUAL

XRD-DSC Sample Alignment (BB) Part

DICOM Correction Item

Lab P-6: Synthesis of Sinusoidal Signals A Music Illusion. A k cos.! k t C k / (1)

Multicore Design Considerations

DCI Memorandum Regarding Direct View Displays

NENS 230 Assignment #2 Data Import, Manipulation, and Basic Plotting

TV Synchronism Generation with PIC Microcontroller

Bite Size Brownies. Designed by: Jonathan Thompson George Mason University, COMPLETE Math

Python Quick-Look Utilities for Ground WFC3 Images

FLIP Procedure. From the main work screen, select Menu. Then select Start Job. Press New Job.

UG0651 User Guide. Scaler. February2018

RS232 Decoding (Option)

E X P E R I M E N T 1

Analyzing Modulated Signals with the V93000 Signal Analyzer Tool. Joe Kelly, Verigy, Inc.

Case study: how to create a 3D potential scan Nyquist plot?

Technical Specifications

PS User Guide Series Seismic-Data Display

Setting up a RTK Survey Using Trimble Access

De-embedding Gigaprobes Using Time Domain Gating with the LeCroy SPARQ

How to Optimize Ad-Detective

CURIE Day 3: Frequency Domain Images

The parameters can be changed according to the needs of the operator. Do not change the settings of the Maintenance screen.

Defining and Labeling Circuits and Electrical Phasing in PLS-CADD

The PK Antenna Analyzer

FOR WWW TEACUPSOFTWARE COM User Guide

Checkpoint 4. Waveform Generator

Multi-Screen Splicing Video Processor. Xi an NovaStar Tech Co., Ltd. Specifications. Document Version: Document Number:

SIGVIEW v2.6 User Manual

Physics 277:Special Topics Medieval Arms and Armor. Fall Dr. Martin John Madsen Department of Physics Wabash College

JAMAR TRAX RD Detector Package Power Requirements Installation Setting Up The Unit

TechNote: MuraTool CA: 1 2/9/00. Figure 1: High contrast fringe ring mura on a microdisplay

Let's Learn Pygame: Exercises Saengthong School, June July 2016 Teacher: Aj. Andrew Davison CoE, PSU Hat Yai Campus

Lecture 1: Introduction & Image and Video Coding Techniques (I)

Comparing Distributions of Univariate Data

Import and quantification of a micro titer plate image

Informatics Enlightened Station 1 Sunflower

Typography Day Typography and Culture

Getting Graphical PART II. Chapter 5. Chapter 6. Chapter 7. Chapter 8. Chapter 9. Beginning Graphics Page Flipping and Pixel Plotting...

Operation Procedure for Phillips XL30 ESEM

UNIVERSITY OF PRETORIA. Dept of Library Services RefWorks (Pt 2) 2011

The Micropython Microcontroller

TL-2900 AMMONIA & NITRATE ANALYZER DUAL CHANNEL

UNIVERSITY OF TORONTO JOÃO MARCUS RAMOS BACALHAU GUSTAVO MAIA FERREIRA HEYANG WANG ECE532 FINAL DESIGN REPORT HOLE IN THE WALL

ECE 172 Digital Systems. Chapter 2.2 Review: Ring Counter, Johnson Counter. Herbert G. Mayer, PSU Status 7/14/2018

FPGA Laboratory Assignment 4. Due Date: 06/11/2012

Data Collection Using APEX3. March 30, Chemical Crystallography Laboratory

Minimailer 4 OMR SPECIFICATION FOR INTELLIGENT MAILING SYSTEMS. 1. Introduction. 2. Mark function description. 3. Programming OMR Marks

Table of content. Table of content Introduction Concepts Hardware setup...4

WebMedia Plugin Manager Operational Reference

WAVES Cobalt Saphira. User Guide

Chapter 3 The Wall using the screen

Optimization of Multi-Channel BCH Error Decoding for Common Cases. Russell Dill Master's Thesis Defense April 20, 2015

Entry 1: Turtle graphics 1.8

10 Digital TV Introduction Subsampling

LCD STIMULUS DISPLAY for ENV-007/008 CHAMBERS

For an alphabet, we can make do with just { s, 0, 1 }, in which for typographic simplicity, s stands for the blank space.

What is Statistics? 13.1 What is Statistics? Statistics

General Certificate of Education Advanced Subsidiary Examination June Problem Solving, Programming, Data Representation and Practical Exercise

The ADAPTS function has been enhanced to support the new scan table mode as well as supporting the existing super stimulus mode.

Biometric Voting system

visual identity guidelines

Session 1 Introduction to Data Acquisition and Real-Time Control

PulseCounter Neutron & Gamma Spectrometry Software Manual

J.M. Stewart Corporation 2201 Cantu Ct., Suite 218 Sarasota, FL Stewartsigns.com

Dragon. manual version 1.6

Section 6.8 Synthesis of Sequential Logic Page 1 of 8

9 Analyzing Digital Sources and Cables

Appeal decision. Appeal No France. Tokyo, Japan. Tokyo, Japan. Tokyo, Japan. Tokyo, Japan. Tokyo, Japan

INTERNATIONAL TELECOMMUNICATION UNION 4%2-).!, %15)0-%.4!.$ 02/4/#/,3 &/2 4%,%-!4)# 3%26)#%3

Analyzing Numerical Data: Using Ratios I.B Student Activity Sheet 4: Ratios in the Media

Lab experience 1: Introduction to LabView

Phenopix - Exposure extraction

Introduction to GRIP. The GRIP user interface consists of 4 parts:

Optical Technologies Micro Motion Absolute, Technology Overview & Programming

Slide Set 9. for ENCM 501 in Winter Steve Norman, PhD, PEng

Transcription:

Programming: Part II In this section of notes you will learn about more advanced programming concepts such as looping, functions. Repetition Problem: what if a program or portion of a program needs to repeat itself. Example: Allowing a player to re-play a game again. Continuing to prompt a person to type in value if they enter in an invalid response. Loops: Allows a program or portion of a program to be repeated There are two main types of loops in Python (for and while). In this course we ll focus on the latter.

The For Loop Format: for <variable> in <something that can be stepped through>: body Example: Available online and is called loop1.py def loop1 (): total = 0 for i in range (1, 4, 1): total = total + i print "i=", i, " total=", total print "Done!" Additional For-Loop Examples Available online and is called loop2.py def loop2 (): for i in range (5, 0, -2): print "i=", i print "Done! Available online and is called loop3.py def loop3 (): for i in [5, 2, 3, 10]: print i print "Done!"

Bottom up Top down Real: Problem Solving Approaches Bottom Up Approach To Design Start implementing all details of a solution without first developing a structure or a plan. Here is the first of my many witty anecdotes, it took place in a Tim Horton s in Balzac.. Potential problems: (Generic problems): Redundancies and lack of coherence between sections. (Programming specific problem): Trying to implement all the details of large problem all at once may prove to be overwhelming.

Top Down Design 1. Start by outlining the major parts (structure) My autobiography Chapter 1: The humble beginnings Chapter 2: My rise to greatness 2. Then implement the solution for each part Chapter 1: The humble beginnings It all started seven and one score years ago with a log-shaped work station Writing Programs Using The Top Down Approach Functions can be used to break a program down into manageable parts. Each part of the program is defined by a function. Each function is written one at a time and tested before being added to the main program.

A Very Simple Example Of Using Functions Available online and is called fun1.py def display (): print "Inside display" 4. Statements inside of display execute one-at-a-time. 2. First statement inside main runs def main (): print "Starting main" display () print Display is done, back in main 3. Second statement invokes the function called display 5. Execution returns back to main and the third and final statement here executes. 1. Starting the main program (function called main ) Issue: What s Inside A Function Stays Inside A Function Note: This example won t translate into binary so it can t be run. def fun (): print num Num??? Never heard of it!!! def main (): num = 10 print num fun ()

Passing Information Into Functions Parameters/Inputs: Allows the contents of a variable to be passed into a function. (Modified version of the previous example and it will work): def fun (num): print num The contents of variable num in main are stored in a local variable called num it s num in fun :D def main (): num = 10 print num fun (num) Passes the contents of num from the main function into function fun Passing Multiple Parameters/Inputs Format: def function name (input 1, input 2,...input n ) body Example: def fun (num1, num2, num3, string1) num1 = num2 + num3 string1 = dude!

In A Similar Fashion Values Must Be Returned From Functions def fun (): num = 1 print num def start (): fun () print num Num??? Never heard of it???!!! Returning Values From Functions Format (Writing the function being called): def function name (): return value 1, value 2,...value n Examples (Writing the function being called): def fun1 (): num1 = 10 num2 = 20 return num1, num2 def fun2 (num1, num2): num3 = num1 + num2 return num3

Returning Values From Functions (2) Format (Storing the return values): variable 1, variable 2,...variable n = function name () Examples (Storing the return values): num1, num2 = fun1 () num3 = fun2 (num1, num2) Parameter Passing And Return Values: An Example Available online and is called interest.py : def calculate (principle, rate, time): interest = principle * rate * time total = principle + interest return interest, total def start (): interest, total = calculate (100, 0.1, 5) print "Interest $ ", interest print "Total $", total

Top Down Approach: Example Of Breaking A Programming Problem Down Into Parts (Functions) Calculate Interest Function: Get information Function: Do calculations Function: Display results Using Output Statements To Understand How A Program Works Example: what does the following program do? def start (): for i in range (1, 20, 1): j = i print j=, j if (i % 5 == 0): print i=, i An output statement shows the successive values of i inside the loop An output statement shows the successive values of i inside the loop and inside the ifbranch

Information About Pictures In JES Images/pictures consist of pixels Each pixel has a set of coordinates (x, y) that determine it s location. Example image (200 pixels x 100 pixels) Top left (x =0, y = 0) X coordinate (200) Top right (x =200, y = 0) Y coordinate (100) Bottom left (x =0, y = 100) Bottom right (x =200, y = 100) Picture/Image-Related Functions In JES For more details look under the help menu under Picture functions. addline (picture, startx, starty, endx, endy) addrect (picture, startx, starty, width, height) addrectfilled (picture, startx, starty, width, height, color) addtext (picture, xpos, ypos, text): Explanation of the function values picture: the name of the picture that you want to edit startx: the starting pixel coordinate on the x axis starty: the starting pixel coordinate on the y axis endx: the ending pixel coordinate on the x axis endy: the ending pixel coordinate on the y axis width: the width of the rectangle in pixels weight: the height of the rectangle in pixels color: the color to fill the rectangle with (red, green, blue etc.)

Example Of Editing A Picture Available online and is called picture1.py def picture1(): lion = makepicture ("lion.jpg") addline (lion,0,0,100,100) addrectfilled (lion,100,100,100,200,red) addtext (lion,200,300,"lion dance for the Lions Club") show (lion) Important: Typically you want to show a picture only after you have finished all your edits! Review: The 24 Bit Color Model Each pixel s color is specified with 24 bits: 8 bits (256 combinations) for the red component 8 bits (256 combinations) for the blue component 8 bits (256 combinations) for the green component In JES the color value is an integer ranging from 0 255. Smaller numbers result in darker pixels. Larger numbers result in lighter pixels.

JES Pixel-Related Functions Get functions: find out the color level of a particular pixel getred: returns the red level (0 255) of a pixel getblue: returns the blue level (0 255) of a pixel getgreen: returns the green level (0 255) of a pixel Set functions: change the color of a particular pixel setred: change the red level of a pixel (to a value from 0 255) setblue: change the blue level of a pixel (to a value from 0 255) setgreen: change the green level of a pixel (to a value from 0 255) Example: Seeing The Color Values Of A Picture Available online and is called picture2.py. It also requires that you download and save the picture smalllion.jpg into the folder that you run JES from. def picture2 (): picture = makepicture ("smalllion.jpg") show (picture) allpixels = getpixels (picture) for pixel in allpixels: red = getred (pixel) blue = getblue (pixel) green = getgreen (pixel) print "RBG:", red, blue, green

Example: Changing The Color Values Of A Picture Available online and is called picture3.py. It also requires that you download and save the picture mediumlion.jpg into the folder that you run JES from. def picture3 (): picture = makepicture ("mediumlion.jpg") show (picture) allpixels = getpixels (picture) for pixel in allpixels: red = getred (pixel) blue = getblue (pixel) green = getgreen (pixel) if ((red + 50) <= 255): setred (pixel, (red+50)) if ((blue + 50) <= 255): setblue (pixel, (blue+50)) if ((green + 50) <= 255): setgreen (pixel, (green+50)) repaint (picture) Show the original picture loaded from file. Show the original picture after it has been manipulated. You Should Now Know What is the purpose of a loop How to write a for-loop in JES How functions are a way of implementing a top down approach to program design How to write and trace through a program that employs functions How to pass information to and from functions via parameters and return values A technique for tracing programs: using output statements Functions for working with images/pictures in JES