CS 101 Computer Science I
Fall 2013

Computer Science Department
The College of Arts and Sciences
Boston College

About Calendar Textbook Vista Piazza
Staff Resources Grading Problem Sets code:red Lab
Problem Set 2: Tessellation

Assigned: Tuesday September 10, 2013
Due: Thursday September 19, 2013
Points: 15 Points up to 21 Points Total

This problem set consists of 2 required parts and an optional (but highly encouraged!) CS101 Tessellation Contest. In Part 1, there are 6 required 2-point problems A through F. In Part 2, you are required to do at least one tessellation problem. You can do the easy one and be done with it or you can do extras, or a more challenging one for up to 6 points extra credit.

The problems in Part 1, labeled A through F, all involve writing functions that use some of the stddraw.Picture functions to draw images in the graphics window. As we've discussed in class, the graphics window is Cartesian or xy-plane. The pixel at the extreme lower left corner is at (x, y) coordinates (0, 0) while the pixel at the extreme upper right corner is at (x, y) coordinates (1.0, 1.0).

Parts A through E involve drawing rings in the graphics window; all are worth 2 points. Part F requires a drawing of squares running on a diagonal. Part A is relatively simple and can be done right away. Parts B and C require branching and parts D, E and F all require repetition which we will continue to cover in the coming lectures.

Setup

Start by creating a folder named with your surname followed by the digit 2. (Mine would be called Muller2.) In this problem set you'll populate the folder with one .py file for each problem. All of the problems are couched in terms of writing a specific function. In each case, you should demonstrate your function by embedding a call to your function in an appropriate tester function that calls the required function with arguments that demostrate that it works correctly. For example, the first problem requires a function ring. It should be defined in a file ring.py. The ring.py file should look something like:
# file: ring.py
# author: Bob Muller
# date: September 1, 2013
#
from stddraw import *

def ring(picture, x, y, radius, width, color):
    YOUR CODE HERE

def testRing():
    picture = Picture()
    color = picture.randomColor()
    ring(picture, .5, .5, .3, .2, color)
    picture.start()

testRing()
Or, if you prefer to run your program by clicking the picture as demonstrated in class:
# file: ring.py
# author: Bob Muller
# date: September 1, 2013
#
from stddraw import *

def ring(picture, x, y, radius, width, color):
    YOUR CODE HERE

def testRing():
    def responder(event):
        color = picture.randomColor()
        ring(picture, .5, .5, .3, .2, color)

    picture = Picture()
    picture.bind('<Button-1>', responder)
    picture.start()

testRing()

Part 1: Diamonds, Rings

All of the problems in Part 1 refer to the following images.

Figure A Figure C Figure D
Figure E Figure F

Part A (2 Points) ring

Write a function ring : Picture * float * float * float * float * color -> void such that, given a call ring(pict, x, y, radius, width, color), the ring function draws a ring with the given radius and width and color centered at point (x, y). Figure A show the result of the call ring(picture, .5, .5, .3, .2, 'green').

Part B (2 Points) goodRing

The radius of a ring is the distance from its center to its outer edge. The width of a ring is the width of its colored band. Clearly, the width of a ring cannot be greater than or equal to its radius. Write a new version of ring called goodRing(picture, x, y, radius, width, color) that will only draw a ring if the width is less than the radius. If the width and radius provided as inputs to goodRing are such that the width is greater than or equal to the radius, the goodRing function should print an error message and return the integer 0.

Part C (2 Points) ringInBounds

Write a new version of ring called ringInBounds(picture, x, y, radius, width, color) that will only draw a ring if it is good, i.e., such that width < radius and it is completely contained within the graphics window. It would rule out rings like the one show in Figure C. If the x, y and radius provided as inputs to ringInBounds give rise to a ring that would not be completely included in the picture, the ringInBounds function should use the print statement to print an error message to the console. For example, the call ringInBounds(picture, .5, .5, .8, .2, 'red') should give rise to an error message along the following lines:
Error: Ring centered at (.5, .5) with radius .8 is out of bounds.
If the ring is good and contained within the unit square, the function should go ahead and render it. Note that you should fee free to use your previously built ring and goodRing functions for this purpose if you want to. In order to get access to these functions you'll need to import the files containing their definitions. Simply include the line import ring, goodRing at the top of the file.

Part D (2 Points) Random Rings

Python's Standard Library includes a handy random module that has a number of functions relating to pseudo-random numbers. In order to access the definitions within this module, put the line:
import random
somewhere near the top of your file. In this problem we will use the random.random function. The function:
random.random : void -> float 
returns a random number r such that 0 <= r < 1. Fire up a Python shell and try it! Among many other applications, the random.random function can be used to randomly select x or y coordinates in the unit square. For example:
...
x = random.random()
y = random.random()
...
We'll work extensively with random functions throughout the semester.

In this problem, you will write a function randomRings : Picture * int -> void such that given a call randomRings(picture, N), the randomRings function draws N random rings in the picture. For the purposes of this problem, it doesn't matter whether or not the rings are strictly contained in the picture. See Figure D.

Everything about a given ring should be randomly generated: the center-point, the radius, the width and the color. But note that the randomly selected width of the ring should not be larger than the radius. You can use the stddraw function randomColor to generate a random color.

Your randomRing function should be accompanied by a tester function in the usual way.

Part E (2 Points) rowOfRings

Write a function rowOfRings : Picture * float * int -> void such that given a call rowOfRings(picture, y, N) the rowOfRings function draws a horizontal row of N equally sized rings across the square picture centered at height y, as shown in Figure E. The radii of all the rings should be the same and can be easily computed from N (and the width of the picture). The width and colorof each the rings should be computed randomly. See Figure E.

Your function should have the usual tester function.

Part F (2 Points) Diamonds

Write a function diamonds : Picture * int -> void such that given a call diamonds(picture, n), the diamonds function draws a sequence of n square randomly colored blocks as shown in Figure F. Your function should have the usual tester function.

Part 2: Tessellation

According to the OED, the word tessellate means To make into a mosaic; to form a mosaic upon, adorn with mosaics; to construct (esp. a pavement) by combining variously coloured blocks so as to form a pattern..

Tessellation was raised to a high art in Persian and Islamic architecture which featured spectacular tessellated structures.
Hafez Tomb Isfahan Alhambra

The 16/17th century German mathematician and astronomer (and astrologer) Johannes Kepler studied tessellation. In 1619 he published Harmonices Mundi (The Harmony of the World) which investigated the mathematical properties of semi-regular (or so-called Archimedian) tessellations. The mathematical properties of tilings remains an active field of study today. See here, here and here.

The stunning tilings at Alhambra date from the 12th century. Some are shown below.
Alhambra 1 Alhambra 2 Alhambra 3
Alhambra 4 Alhambra 5

MC Escher

The Alhambra examples are notable because of the complex interplay between foreground and background. This proved to be especially interesting to the 20th century Dutch artist MC Escher whose famous work was largely inspired by a 1922 visit to Alhambra.
Bird Fish MC Escher Sky and Water I
See also Escher Tessellations.

Your Part

In class on Thursday September 12, we will develop two simple tessellations.
Square Tiling Octagonal Tiling
In this part of the problem set you are required to implement ONE tessellation of the graphics window. The simplest problem is part A below. Choose part B for 3 points extra credit. Choose Part C for up to 6 points extra credit. Also, see the CS101 Tessellation Contest below.

Ring Tiling Hexagon Hexagonal Tiling

Part A (3 Points) Ring Tessellation

Write a function ringTiling : Picture * int -> void such that given a call ringTiling(picture, n), the ringTiling function fills the picture with n2 rings as shown in Figure Ring Tiling above. Each ring should have the same radius but both the width and the color of the ring should be random. Your function should have the usual tester function.

Part B (6 Points) Hex Tessellation

A regular hexagon is a 6-sided figure with all sides of equal length and all interior angles equal (120 degrees). Like an equilateral triangle, a square and a regular pentagon, a regular hexagon is a regular polygon.

Write a function hexTiling : Picture * float -> void such that given a call hexTiling(picture, size), the hexTiling function fills the picture with randomly colored regular hexagons where each side is of length size.

The stddraw library includes a function filledPolygon that draws a filled polygon. In order to solve this problem, you will need to create a helper function that uses the stddraw filledPolygon function to draw a regular hexagon as shown in Figure Hexagon above. Your function should have the usual tester function.

Part C: (Up to 9 Points) Roll Your Own

Choose your own tessellation for up to 6 points extra credit. Better yet, enter the CS101 Tessellation Contest below! Some possible tiles include:

Greek Cross Golden Ratio TriHexagonal
Elongated Snub Weave

CS101 Fall Tessellation Contest

If you find tessellation interesting and would like to try your hand at making a beautiful and interesting tiling, have at it! The most interesting tessellation submitted by 12PM, Friday October 18, will receive a prize and two bumps of their final letter grade. This means that a C+ would move to a B, a B would move to an A- and so forth. Last years winner was:

Tessellation submissions will be presented in class and voted on by members of the class. In the case of a tie, the course staff will break the tie.

Submissions

1 2 3

4 5 6

7 8 9

Created on 08-31-2013 15:49.