Lab 2: Repetition and Looping
CS 145: Images and Imagination, Spring 2014


Due Date:

Final submission is due Mon, Feb 3 before class.
This lab is worth 20 points.
See policy page for late penalties.

Summary of Goals

Reading

See bookResources in CS145 folder on the shared drive gorr-classes:

Suggested Folder Structure

This is a suggested structure. On your H-drive, in the same CS145 folder you created in the first lab, create a subfolder called Lab2. In this folder, created two subfolders, one named Practice, and the other named Lab2Final. Save all of the practice sketches for this lab into the Practice folder. In the Lab2Final folder, save all of the sketches that you plan on submitting.

When you are done, you will copy over the sketches in the Lab2 over to the shared drive gorr-classes along with the generated images.

Practice Programs

Before you attempt the assignment below, it is necessary that you work through the practice problems.

You will not be asked to turn these in, however, it will be assumed you know how to write code to generate the images, e.g. on an exam or for later assignments. If you have questions on how to do these, please ask.

Assignment - Part 1: Repeating An Image

In this part of the lab, you will

Create a small image of your character: Begin with the code you have for your character from Lab 1 and save it to a new sketch folder (e.g. do a "save as" and place the sketch into CS145/Lab2/Lab2Final). As described in class (and in the code below), place your character code (e.g. tree) in a separate function and add a setup function that contains the initial setup code. There are then 3 code modifications you need to do: 1) scale the window size, 2) scale the the character size, and 3) save the image. Below is example code showing how it can be done using the tree example from class (tree code is not shown). Do the same for your code. When done, you should have a small image file saved of your character.

Program 1: Generating a small image of your character

// The original tree had a width of 500 and height 600.
// Here, we scale the size down by a factor of 10, i.e. to 50x60

void setup() {
  int scaleFactor = 10;                    // declare and initialize scale factor
  size(500/scaleFactor, 600/scaleFactor);  // reduce window size by scale factor
  background(255);                         // set background to white
  scale (1.0/scaleFactor);                 // reduce size by factor of 10
  tree();                                  // draw the tree
  save("mytree.png");                      // save to an image file
}

void tree() {
    ... // character code goes here.
}

mytree.png

Generate a banner using a for-loop: Create a new sketch (e.g. called wallpaper) and copy the small image of your character (e.g. mytree.png) in to the sketch folder. Write code that is similar to the image for-loop example in the practice problems to generate a banner containing repeated copies of your character.

Generate a wallpaper patterin using a nested for-loop: Modify your code above to generate a "wallpaper" pattern by using a nested for-loop..

Part 1 Submission: By Feb 3 before class, please submit your work by placing the following onto the shared drive gorr-classes:

Assignment - Part 2: Texture

Your goal is to create 2-3 complex abstract patterns or textures using for-loops and nested loops which vary elements such as color, shape, size, and position. For each image, pick a color scheme ahead of time. Save each final image to a jpg or png file with a minimum size of 400x400.

General References on Design:

Examples Patterns and Textures:

Part 2 Submission: By Feb 3 before class, please submit your work by placing the following onto the shared drive gorr-classes: