CSC151 2010S, Class 07: Drawings as Values Overview: * Reflection on recent topics. * Detour: What are the integers? * Drawings as values: A new way to think about the construction of images * Internal representation of drawings * Leftover questions * Lab Admin: * Readings for Friday: Writing Your Own Procedures and How Scheme Evaluates Expressions (version 2). * Sorry for the delay in posting the readings for today. It will happen again. * Advance warning: Today has a lot of talking before lab. * Philosophical question: Can someone join 151 late? * Due: Assignment 2. * Don't forget: Keep your lab partners from yesterday. * EC: CS Table Friday at noon. Information distributed via email. * EC: CS Extras Thursday at 4:30 in 3821 (Talk on summer opportunities in CS). * EC: Booth family fundraiser Friday night. Reflection on recent topics * Nora noted some confusion about the relationship of selections and lines. * How would you generalize your drawing algorithms to work with different images? * Use the width and the height directly whenever you write a number (instead of 75, use (* .25 image-width), or some such) * Write a procedure that takes key things as parameters (e.g., image width) * Moral: When you write code, think about how to generalize it * Followup q: What does this do to your precise placement? Short answer: You need to use the technique for *all* the numbers Long answer: Consider the following instructions for making the "face" part of our smiley (define smiley (image-show (image-new 200 200))) (context-set-fgcolor "yellow") (image-select-ellipse! smiley REPLACE 10 10 180 180) (image-fill! smiley) (image-select-nothing! smiley) (context-update-displays!) Suppose we want to make the face 'scale' with the image. What do we do? We make the width and height of the face reflect the width and height of the image. Let's see 180/200 is 90%, so ... (define smiley (image-show (image-new 200 200))) (context-set-fgcolor "yellow") (image-select-ellipse! smiley REPLACE 10 10 ; left top (* (image-width smiley) .9) ; width (* (image-height smiley) .9)) ; height (image-fill! smiley) (image-select-nothing! smiley) (context-update-displays!) But that doesn't look so great for small images (since the 10's may shift it enough that parts don't even appear in the image) or for large images (since there's a lot of whitespace at the right). Hence, we also need so make the left and top edges depend on the size of the image. (image-select-ellipse! smiley REPLACE (* (image-width smiley) .05) ; left (* (image-height smiley) .05) ; top (* (image-width smiley) .9) ; width (* (image-height smiley) .9)) ; height --- Detour: What are the integers? * A number (assumes that we know what numbers are) on the number line * In terms of other terms: Natural numbers, Whole numbers, ... * Integers are: Natural numbers union -1*natural numberes union { 0 } * Anything that doesn't have a decimal. And isn't a fraction. 5/1. * Moral: Things we have intuitive definitions for may be hard to define formally * Moral: We like to define things in terms of other things * Postive natural numbers: 1 is a natural number If w is a natural number, then w+1 is also * Therefore: 1, 1+1, 1+1+1, 1+1+1+1, 1+1+1+1+1 * Interesting characteristic: We've defined the whole numbers in terms of themselves Drawings as values: A new way to think about the construction of images * Define some simple cases: X and Y are imags * A black circle with diameter 1, centered at 0,0, is a drawing * A black square with edge length 1, centered at 0,0, is a drawing * Build drawings from other drawings * The composition of two drawings is a drawing * The recoloring of a drawing is a drawing * The scaling of a drawing is a drawing * The translation of a drawing is a drawing Internal representation of drawings Leftover questions Lab * Don't forget: Keep your lab partners from yesterday.