120 likes | 136 Views
This lecture focuses on working with images (pictures and shapes) in computer programming. Learn how to call pre-defined functions with images, insert images into a program, and manipulate images using functions. Prepare for the next class by installing teachpacks and practicing with image functions.
E N D
CSC 160Computer Programmingfor Non-MajorsLecture #3b: Working with Pictures Prof. Adam M. Wittenstein Wittenstein@adelphi.edu http://www.adelphi.edu/~wittensa/csc160/
A preview of today… • So far we called pre-defined functions with numbers, words, and sentences. • Today, we call pre-defined functions with images (pictures and shapes). • Then, we will see how to define variables in Scheme.
Data Type: Image • Another type of data. Fun to process images. • Images are values like numbers, booleans, words, or sentences – they can be used inside expressions. • Usually given names, since the same image can be used with several different functions. • There are predefined functions to create shapes. Besides that, all other images (pictures) are inserted as follows:
Inserting Images • You cannot type in images the way you type in a number or a word. • To insert an image into a program, move the blinking caret to the place in your program where you want the image, and select the Insert Image item from the Special menu. • DrScheme will then provide a dialog for selecting an image file. • After you have selected a file, the image will be inserted at the blinking caret.
Calling Functions involving Images • Once you have inserted the image (usually a picture), it is treated the same way as any other (simple) data type. • You can use image objects as arguments in a function. • Image objects can be the result of a function.
Install two teachpacks • Open Internet Explorer and type in the website, http://www.adelphi.edu/~wittensa/csc160/tiles.plt • Save the file to the folder C:\ProgramFiles\PLT\Teachpack. • Then in DrScheme, go to “File >Install .plt File > File > tiles.plt”. • Now, as for any teachpack, choose “Language -> Add Teachpack -> tiles (bottom one)” and click Run. • Also, add the “world.ss” teachpack. Choose “Language -> Add Teachpack -> htdp -> world” and click Run.
Some “tiles.ss” functions • reflect-horiz : image -> image • reflect-vert : image -> image • image-beside : image image -> image • image-above : image image -> image • rotate-cw : image -> image • rotate-ccw : image -> image • rotate-180 : image -> image
Exercise 1: Calling Image Functions • Insert a picture into your DrScheme file either from your computer or a website. • Find the horizontal mirror image of the picture. • Put your picture next to itself. • Put your picture next to its horizontal mirror image.
In summary… • Pictures have to be inserted. They cannot simply be typed in like numbers, words, and sentences can. • However, after inserting them, they are treated like any other data type. Next time… • More practice with images • Defining variables
Homework for next time… • No written assignments. • Readings: • Read the article on Pair Programming. • Read Sections 2.2-2.3 of How to Design Programs. • Read Chapter 4 of Simply Scheme.