CSC 160 Computer Programming for Non-Majors Lecture #5c: Functions with Images Prof. Adam M. Wittenstein

Slides:



Advertisements
Similar presentations
FRACTIONS.
Advertisements

Fractions.
My Penguin Math Book By:. I see How many penguins do you see? Count them & type the number in the box penguins.
CSC 160 Computer Programming for Non-Majors Lecture #3a: Stepper, Words, Sentences (continued) Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #9: Booleans Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #4: Defining Variables Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Images: Another Form of Symbolic Data Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #8: Animations I Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #5: Defining Functions Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Chapter 2: Numbers, Expressions, and Simple Programs Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Chapter 6: Structures Prof. Adam M. Wittenstein
PREPOSITIONS WITH ANGELS (Adapted by Damon Lewis from “Prepositions With Angel Babies” by M. Thrash)
CSC 160 Computer Programming for Non-Majors Lecture #11: Conditionals II Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Syntax Rules Prof. Adam M. Wittenstein
Section 4.4: Designing Conditional Functions. REVIEW: Design Recipe – V. 2  Figure out precisely what you need to do. 1. Understand the problem 2. Function.
CSC 160 Computer Programming for Non-Majors Lecture #3: Calling Functions Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #3c: Working with Pictures (continued) Prof. Adam M. Wittenstein
Section 6.1: Structures (continued). Example 1: in-left-side? ; Purpose: To determine whether a point is in the leftmost 150 pixels of the screen. ; Contract.
CSC 160 Computer Programming for Non-Majors Draft Chapter: The UFO Example Prof. Adam M. Wittenstein
Clicker Question 1 Are you (and your clicker) here? A. Yes B. No C. Not sure. Too early.
CSC 160 Computer Programming for Non-Majors Lecture #10: Conditionals I Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Section 1.2: Drawing a UFO Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Chapter 4: Conditional Expressions and Functions Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #5b: Designing Programs Prof. Adam M. Wittenstein
You write the caption Thunderstorms - Chap Instructions §Write a two-sentence caption for each of the following. The first sentence has been started.
CSC 160 Computer Programming for Non-Majors Lecture #7: Variables Revisited Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Chapter 3: Programs are Functions Plus Variable Definitions Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #2: What are Functions? Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #3a: Stepper, Words, Sentences Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #5a: Defining Functions on Words and Sentences Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #6: Function Composition Prof. Adam M. Wittenstein
Programming with Images (continued). Another teachpack – “tiles.ss” Download from the website: “ Save.
CSC 160 Computer Programming for Non-Majors Lecture #3b: Working with Pictures Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #5 (continued): More on Writing Functions Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #12: Syntax and Semantics Prof. Adam M. Wittenstein
MAIN MENU Let’s learn how to add! 1+1 Video Quiz time! Great job everyone!
Another method to solve quadratics. Why isn’t the last picture a square? Is this a square? What about this one?This one?
HOW MANY SHAPES do you see?
Sullivan – Fundamentals of Statistics – 2 nd Edition – Chapter 2 Section 1 – Slide 1 of 27 Chapter 2 Section 1 Organizing Qualitative Data.
ORGANIZING QUALITATIVE DATA 2.1. FREQUENCY DISTRIBUTION Qualitative data values can be organized by a frequency distribution A frequency distribution.
1 CS6825: Digital images How are DIGITAL images created. How are DIGITAL images created. Previous lecture we discussed how ANALOG images are created Previous.
CSC 160 Computer Programming for Non-Majors Chapter 8: Scheme Language Review Prof. Adam M. Wittenstein
Is this a square or a pentagon? It is a square.
Miss. Ajsa’s Geometry shapes practice Click the arrow button to begin.
Teacher Miguel’s. For the month of November our focus was recognition of different shapes and colors. We look around the classroom and find different.
SEPTEMBER 8, 2010 ICS 3U. Today’s Agenda Course Outline What is a program? What is a program Instruction Writing ActivityActivity.
Another method to solve quadratics Why isn’t the last picture a square? Is this a square? What about this one?This one?
LECTURE 34 Reading Assignment: 1.) Wed. 04/25: Sections ) Friday 04/27: Sections ) Mon. 04/30: Sections Reading Assignment: 1.)
How many …?. What shape can you see? I can see some _____. Q1 Q1 stars.
Organizing Qualitative Data
Basic Elements of Composition
CS 5010 Program Design Paradigms "Bootcamp" Lesson 9.3
Art Elements & Principles of Design
− −2 − −4 >5 2+4>5
Tides Foldable.
Fraction Fun.

Name of Person Name of Person Place Picture Here Place Picture Here
Symmetries of Solids.
Here are four triangles. What do all of these triangles have in common
Let's Play "What's the Question"
Organizing Qualitative Data
Name of Person Name of Person Place Picture Here Place Picture Here
Cross Sections of Three-Dimensional Figures
Name of Person Name of Person Place Picture Here Place Picture Here
M.U.Gs 1-13.
Review: 9.3c Mini-Quiz Simplify 108 − Simplify.
Shapes.
Cross Sections of Three-Dimensional Figures
The parallelogram and the isosceles triangle have the same perimeter.
Presentation transcript:

CSC 160 Computer Programming for Non-Majors Lecture #5c: Functions with Images Prof. Adam M. Wittenstein

A preview… Today we will define functions involving images (as well as numbers, words, sentences). We follow the same rule for defining Scheme functions: (define (function-name param-name[s]) (expression)) We will practice using the Design Recipe when writing these functions.

Example 1: mirror-horiz ; Purpose: To place any picture next to its horizontal mirror image. ; Contract: image -> image

Example 1: mirror-horiz ; Purpose: To place any picture next to its horizontal mirror image. ; Contract: image -> image “Examples of mirror-horiz:” (define ADAM ) (mirror-horiz ADAM) “should be” (image-beside Adam (reflect-horiz ADAM))

Example 1: mirror-horiz ; Purpose: To place any picture next to its horizontal mirror image. ; Contract: image -> image (define (mirror-horiz pic) … pic …) “Examples of mirror-horiz:” (define ADAM ) (mirror-horiz ADAM) “should be” (image-beside Adam (reflect-horiz ADAM))

Example 1: mirror-horiz ; Purpose: To place any picture next to its horizontal mirror image. ; Contract: image -> image (define (mirror-horiz pic) (image-beside pic (reflect-horiz pic))) “Examples of mirror-horiz:” (mirror-horiz ADAM) “should be” (image-beside ADAM (reflect-horiz ADAM)) *Note that this function “uses” image-beside and reflect-horiz.

Example 2: counterchange Define a function called counterchange that takes in two images and returns a 2x2 arrangement of them as shown here.

Example 2: counterchange ; Purpose: To create a 2x2 arrangement of any two images. ; Contract: image image -> image ; Examples: ;(counterchange (rectangle ‘solid ‘blue) (rectangle 20 ;20 ‘solid ‘red)) “should be” “a blue rectangle next to a red ;square with a red square next to a blue rectangle below it” ;(counterchange (circle 30 ‘solid ‘green) HANDS) “should be” ;“a green circle next to the HANDS with the HANDS next to a ;green circle below it”

Example 2: counterchange ; Skeleton: ; (define (counterchange pic1 pic2) ; … pic1 … pic2 …) ;Informal Thinking ;We need to put two images next to each other. How do we do this? ;How do we put an image directly above another?

Example 2: counterchange ; Actual Function: (define (counterchange pic1 pic2) (image-above (image-beside pic1 pic2) (image-beside pic2 pic1) ) *Note that this function “uses” image-above once and image-beside twice.

In summary… We have now defined functions involving several different data types. Next class, we will discuss error messages (including how to prevent them and how to interpret them). Please read Section 2.4 of How to Design Programs before next class.