Assignment 5: Conditional Transformations and Images


Due: 10:30 p.m. Tuesday 25 February 2014

Summary: In this assignment you will explore the power of conditional processing to make more interesting color transforms and generate a variety of representational images.

Purposes: To give you experience using boolean values, writing predicate procedures, using conditionals, and working with Gimp tools.

Expected Time: Two to three hours.

Collaboration: We encourage you to work in groups of size two or three. You may not work alone. You may discuss this assignment with anyone, provided you credit such discussions when you submit the assignment.

Submitting: Email your answer to . The title of your email should have the form CSC-151-01 Assignment 5 and should contain your answers to all parts of the assignment. Scheme code should be in the body of the message.

Warning: So that this assignment is a learning experience for everyone, we may spend class time publicly critiquing your work.

Assignment

Problem 1: Testing for Color Dominance

Write a suite of three predicates red-dominates?, green-dominates?, blue-dominates? that hold only when the named color channel is greater than both the others.

Note that while you did a similar problem in a previous lab, our definition of dominance here is slightly different. For example,

> (red-dominates? (irgb 128 64 64))
#t
> (red-dominates? (irgb 64 128 64))
#f
> (red-dominates? (irgb 64 64 128))
#f
> (red-dominates? (irgb 128 64 128))
#f

Problem 2: Enhancing Color Dominance

Write the color transform irgb-color-enhance that applies irgb-redder if red dominates the color, irgb-bluer if blue dominates the color, irgb-greener if green dominates the color, and leaves the color unchanged otherwise.

flowers
(image-variant flowers irgb-color-enhance)
(image-variant flowers (o irgb-color-enhance irgb-color-enhance))

Problem 3: Making Simple Representational Drawings

As you have noted, one “fun” aspect of programming the Gimp is that we can make some simple (well, perhaps childlike) representational images, such as the picture we made of a smiley face. Let's explore that aspect in a bit more depth.

Your goal is to document and write a procedure, (dwelling width height) that creates an image of a scene with something that might reasonably be interpreted as a modern dwelling (It might be a house or an apartment building; it's up to you.) The dwelling must have a door, windows, and a roof.

The two inputs, width and height, specify the width and height of the final image. You can assume that the width is never more than twice the height, and that the height is never more than twice the width (although you should document both preconditions).

In writing your procedure, you must achieve the following goals.

  • You must use the Gimp tools (e.g., image-select-ellipse! or image-draw-line!, etc.)--not drawings--to make the image.
  • Your instructions should give the same output if given the same width and height, even if the user has changed the current foreground color or brush. (That is, you have a responsibility to set the color and brush before doing any image operations.)
  • You must make at least one call to image-select-polygon!, which has the form (image-select-polygon! image selection-type list-of-positions). You can create each position with (position-new x y).
  • You must make at least one compound selection, using a selection type of ADD, SUBTRACT, or INTERSECT.
  • You must make at least one two-way decision using if. For example, you might decide that if the image is wider than it is tall, you will have four rows of windows per level and otherwise have three rows of windows per level.
  • You must make at least one three-way decision using cond. For example, you might decide that if the total area of the image is less than 10,000 square units (e.g., 100x100), you make one-paned windows, if it's between 10,000 and 40,000 square units (e.g., 200x200), you make two-paned windows, and if it's bigger than 40,00 square units, you make four-paned windows.
  • You must make at least one one-way decision using when.a For example, you might draw a flower out front only if the image is exactly square.

If your image consists of several elements, you may wish to collect each into separate functions to handle each, so that dwelling remains easy to read and understand.

Finally, please include at least three different calls to your procedure to visualize exemplar images.

(image-show (dwelling __ __))
(image-show (dwelling __ __))
(image-show (dwelling __ __))

Important Evaluation Criteria

Will will primary evaluate your procedures and documentation on their correctness and clarity. For portions of the assignment, we may also assess you on creativity.


Jerod Weinman

Copyright 2007-2014 Janet Davis, Matthew Kluber, Samuel A. Rebelsky, and Jerod Weinman. (Selected materials copyright by John David Stone and Henry Walker and used by permission.)

This material is based upon work partially supported by the National Science Foundation under Grant No. CCLI-0633090. Any opinions, findings, and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the National Science Foundation.

Creative Commons License This work is licensed under a Creative Commons Attribution-NonCommercial 3.0 Unported License .