1 / 11

CSC 160 Computer Programming for Non-Majors Lecture #5c: Functions with Images

CSC 160 Computer Programming for Non-Majors Lecture #5c: Functions with Images. Prof. Adam M. Wittenstein Wittenstein@adelphi.edu http://www.adelphi.edu/~wittensa/csc160/. A preview…. Today we will define functions involving images (as well as numbers, words, sentences).

becerra
Download Presentation

CSC 160 Computer Programming for Non-Majors Lecture #5c: Functions with Images

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSC 160Computer Programmingfor Non-MajorsLecture #5c: Functions with Images Prof. Adam M. Wittenstein Wittenstein@adelphi.edu http://www.adelphi.edu/~wittensa/csc160/

  2. 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.

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

  4. 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))

  5. 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))

  6. 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.

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

  8. Example 2: counterchange ; Purpose: To create a 2x2 arrangement of any two images. ; Contract: image image -> image ; Examples: ;(counterchange (rectangle 50 30 ‘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”

  9. 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?

  10. 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.

  11. 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.

More Related