Working with images and scenes CS 5010 Program Design Paradigms “Bootcamp” Lesson 2.5 TexPoint fonts used in EMF. Read the TexPoint manual before you delete.

Slides:



Advertisements
Similar presentations
Binary Search CS 5010 Program Design Paradigms “Bootcamp” Lesson 8.3 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.:
Advertisements

Contracts, Purpose Statements, Examples and Tests CS 5010 Program Design Paradigms “Bootcamp” Lesson 1.6 TexPoint fonts used in EMF. Read the TexPoint.
Two Draggable Cats CS 5010 Program Design Paradigms “Bootcamp” Lesson 3.4 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.:
Draggable Cat CS 5010 Program Design Paradigms “Bootcamp” Lesson 3.3 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.:
Basics of Inheritance CS 5010 Program Design Paradigms "Bootcamp" Lesson 12.1 © Mitchell Wand, This work is licensed under a Creative Commons.
The Function Design Recipe CS 5010 Program Design Paradigms “Bootcamp” Lesson 1.1 TexPoint fonts used in EMF. Read the TexPoint manual before you delete.
Image Maps and Graphics Internet Basics and Far Beyond! Mrs. Wilson.
Lists CS 5010 Program Design Paradigms “Bootcamp” Lesson 4.1 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: AAA 1 ©
Four simple expressions in meta. Data objects Pieces of data in a computer are called objects Today, we’ll talk about four kinds of objects Numbers Pictures.
Rewriting your function using map and foldr CS 5010 Program Design Paradigms “Bootcamp” Lesson 5.5 TexPoint fonts used in EMF. Read the TexPoint manual.
Function Composition CS 5010 Program Design Paradigms “Bootcamp” Lesson © Mitchell Wand, This work is licensed under a Creative Commons.
InDesign CS3 Lesson 3 Working with Frames. Using Frames Frames are containers in which you place graphics or text. Frames can also be used as graphic.
Foldr CS 5010 Program Design Paradigms “Bootcamp” Lesson 5.4 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: AAA © Mitchell.
Tutorial 2 Drawing Text, Adding Shapes, and Creating Symbols.
The Function Design Recipe CS 5010 Program Design Paradigms “Bootcamp” Lesson 1.1 TexPoint fonts used in EMF. Read the TexPoint manual before you delete.
Examining Two Pieces of Data CS 5010 Program Design Paradigms “Bootcamp” Lesson © Mitchell Wand, This work is licensed under a Creative.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 5 Working with Images Starting Out with Games & Graphics in.
Design Strategies 1: Combine Simpler Functions CS 5010 Program Design Paradigms “Bootcamp” Lesson © Mitchell Wand, This work is licensed.
Generalizing Similar Functions CS 5010 Program Design Paradigms “Bootcamp” Lesson 5.1 TexPoint fonts used in EMF. Read the TexPoint manual before you delete.
Lesson 10 Using AutoShapes, WordArt, and Comments Lesson 10 Using AutoShapes, WordArt, and Comments.
Digital Media Dr. Jim Rowan ITEC So far… We have compared bitmapped graphics and vector graphics We have discussed bitmapped images, some file formats.
Rewriting your function using map and foldr CS 5010 Program Design Paradigms “Bootcamp” Lesson TexPoint fonts used in EMF. Read the TexPoint manual.
Design Studies 20 ‘Show Off’ Project How to make a computer monitor In Google Sketchup By: Liam Jack.
Two Draggable Cats CS 5010 Program Design Paradigms “Bootcamp” Lesson TexPoint fonts used in EMF. Read the TexPoint manual before you delete this.
Generalizing Over Functions CS 5010 Program Design Paradigms “Bootcamp” Lesson TexPoint fonts used in EMF. Read the TexPoint manual before you delete.
Lists of Structures CS 5010 Program Design Paradigms “Bootcamp” Lesson TexPoint fonts used in EMF. Read the TexPoint manual before you delete this.
How to Design Worlds CS 5010 Program Design Paradigms “Bootcamp” Lesson TexPoint fonts used in EMF. Read the TexPoint manual before you delete this.
Digital Media Dr. Jim Rowan ITEC Vector Graphics Elegant way to construct digital images that –have a compact representation –are scalable –are.
Halting Measures and Termination Arguments CS 5010 Program Design Paradigms “Bootcamp” Lesson TexPoint fonts used in EMF. Read the TexPoint manual.
Using the List Template CS 5010 Program Design Paradigms “Bootcamp” Lesson TexPoint fonts used in EMF. Read the TexPoint manual before you delete.
Using the List Template CS 5010 Program Design Paradigms “Bootcamp” Lesson 4.2 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this.
Functions vs. Classes CS 5010 Program Design Paradigms "Bootcamp" Lesson © Mitchell Wand, This work is licensed under a Creative Commons.
+ This step by step tutorial demonstrates drawing a keyboard illustration using rectangles, grids, move and transform effects.
Contracts, Purpose Statements, Examples and Tests
Generalizing Similar Functions
Pixels, Colors and Shapes
CS 5010 Program Design Paradigms “Bootcamp” Lesson 5.2
Examining Two Pieces of Data
More About Recursive Data Types
CS 5010 Program Design Paradigms “Bootcamp” Lesson 3.1
CS 5010 Program Design Paradigms “Bootcamp” Lesson 4.3
CS 5010 Program Design Paradigms "Bootcamp" Lesson 9.4
CS 5010 Program Design Paradigms “Bootcamp” Lesson 1.3
More Recursive Data Types
CS 5010 Program Design Paradigms “Bootcamp” Lesson 4.1
CS 5010 Program Design Paradigms “Bootcamp” Lesson 5.3
The Different Kinds of Data
CS 5010 Program Design Paradigms “Bootcamp” Lesson 3.4
CS 5010 Program Design Paradigms “Bootcamp” Lesson 3.2
CS 5010 Program Design Paradigms "Bootcamp" Lesson 9.3
Case Study: Undefined Variables
CS 5010 Program Design Paradigms “Bootcamp” Lesson 7.5
Digital Media Dr. Jim Rowan ITEC 2110.
Contracts, Purpose Statements, Examples and Tests
CS 5010 Program Design Paradigms “Bootcamp” Lesson 6.5
More examples of invariants
ormap, andmap, and filter
Generalizing Similar Functions
The Iterative Design Recipe
Rewriting your function using map and foldr
Working with images and scenes
Introduction to Universe Programs
Examining Two Pieces of Data
CS 5010 Program Design Paradigms “Bootcamp” Lesson 4.1
When do I need an invariant?
CS 5010 Program Design Paradigms “Bootcamp” Lesson 8.3
CS 5010 Program Design Paradigms “Bootcamp” Lesson 3.4
Presentation transcript:

Working with images and scenes CS 5010 Program Design Paradigms “Bootcamp” Lesson 2.5 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: AAA 1 © Mitchell Wand, This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License. Creative Commons Attribution-NonCommercial 4.0 International License

Introduction Racket has a rich library for working with images and scenes. We will use this library extensively in this course. In this lesson, we will explore a few things from the library. 2

Learning Objectives At the end of this lesson, the student should be able to: – Create simple images and scenes – Combine simple images into more complex images and scenes – Determine the properties of an image – Test images and their properties 3

Images are Scalar Data In Racket, images are scalar data Racket has: – Functions for creating images – Functions for combining images – Functions for finding properties of images In general, we build complex images by starting with simple images and then combining them using functional composition. 4

Loading the image library To load the image library, include the line (require 2htdp/image) in your program. 5

Functions for Creating Images (1) bitmap : String -> Image GIVEN: the name of a file containing an image in.png or.jpg format RETURNS: the same image as a Racket value. 6

Functions for Creating Images (2) rectangle : Width Height Mode Color -> Image GIVEN: a width and height (in pixels), a mode (either the string “solid” or the string “outline”), and a color RETURNS: an image of that rectangle. [See the Help Desk for information on the representation of colors in Racket]. 7

Functions for Creating Images (3) circle : Radius Mode Color -> Image Like rectangle, but takes a radius instead of a width and height. There are lots of other functions for creating shapes, like ellipse, triangle, star, etc. 8

Functions for Creating Images (4) text : String Fontsize Color -> Image RETURNS: an image of the given text at the given font size and color. 9

Combining Images The image library contains many functions for combining images into larger images. These functions generally align the images on their centers. This is usually what you want. If you really want to align images on their edges, there are functions in the library to do that, too. See the help desk, as usual. Let’s look at the two most commonly-used image combining-functions: beside and above. Here’s an example: 10

beside and above 11

Slightly more complicated images 12

Slightly more complicated images 13 The rectangle has width 0, so it's invisible

Scenes A scene is an image that has a coordinate system. In a scene, the origin (0,0) is in the top left corner. The x-coordinate increases as we move to the right. The y-coordinate increases as we move down. These are sometimes called “computer-graphics coordinates” We use a scene when we need to combine images by placing them at specific locations. 14

Scene Coordinates (0,0) x y 15

Creating Scenes (empty-scene width height) – returns an empty scene with the given dimensions. (place-image img x y s) – returns a scene just like s, except that image img is placed with its center at position (x,y) in s – resulting image is cropped to the dimensions of s. 16

scene+line (scene+line s x1 y1 x2 y2 color) – returns a scene just like the original s, but with a line drawn from (x1,y1) to (x2,y2) in the given color. – the resulting scene is cropped to the dimensions of s. 17

Creating Scenes with Function Composition Use with function composition to create scenes with images in them Start with an empty-scene, then paint images and lines on the scene by using place-image and scene+line. This is all functional: painting an image on a scene doesn’t change the scene– it produces a new scene. 18

Video Demonstration 19 YouTube link

Measuring Images Racket also provides functions for determining image properties. Here the most important ones: – image-width : Image -> NonNegInt – image-height : Image -> NonNegInt – image? : Any -> Boolean 20 In pixels

Bounding Box The bounding box of an image is the smallest rectangle that completely encloses the image. Its width will be the image-width of the image, and its height will be the image-height of the image. It is easy to determine whether an arbitrary point is inside the bounding box– let’s look at an example. 21

Bounding Box Example w = (image-width CAT-IMAGE) h = (image-height CAT-IMAGE) (x0,y0) (x,y) is inside the rectangle iff (x0-w/2) ≤ x ≤ (x0 + w/2) and (y0-h/2) ≤ y ≤ (y0+h/2) (x,y) is inside the rectangle iff (x0-w/2) ≤ x ≤ (x0 + w/2) and (y0-h/2) ≤ y ≤ (y0+h/2) y = y0-h/2 y = y0+h/2 x = x0-w/2x = x0+w/2 22

Images and the Design Recipe: Examples In your examples, describe the image in words. EXAMPLE: Consider a function that takes an image and doubles it. In your examples you could write: (define red-circle1 (circle 20 "solid" "red")) ;; (double-image red-circle1) ;; = two red circles, side-by-side 23

Images and the Design Recipe: Tests (1) First, construct the correct image. Do NOT use the function you are testing to construct the image. EXAMPLE: (define two-red-circles (beside red-circle1 red-circle1)) Check it visually to see that it's correct – Alas, this step is not automatable. 24

Images and the Design Recipe: Tests (2) Then you can use check-equal? on the resulting images: (check-equal? (double-image red-circle1) two-red-circles) This looks a little silly now, but it will be helpful when you build more complicated images. 25

Images and the Design Recipe: Tests (3) check-equal? is fairly clever, but not perfect. Which of the images below are visually equal? See which of them check-equal? accepts as equal. (define vspace1 (rectangle 0 50 "solid" "black")) (define vspace2 (rectangle 0 50 "solid" "white")) (define vspace3 (rectangle 0 50 "solid" "red")) (define vspace4 (rectangle 0 50 "outline" "black")) (define vspace5 (rectangle 0 50 "outline" "white")) 26

Summary Images are ordinary scalar values Create and combine them using functions Scenes are a kind of image – create with empty-scene – build with place-image 2htdp/image has lots of functions for doing all this. – Go look at the help docs 27

Next Steps If you have questions or comments about this lesson, post them on the discussion board. 28