## Coding Exercise 1

Prerequisite Concepts |
6, 7, 10, & 12 |

Key Concept |
13 |

The Bricklayer coordinate system is discrete. Specically, coordinates consist exclusively of integers and bricks may only be placed at coordinate positions. For example, a 1-bit brick may be placed at (0, 0) or at (1, 0), but cannot be placed at an “in-between” location such as (1.5, 0). As a result, in order to divide a distance exactly in half, the distance must span an odd number of coordinate positions. Consider a sequence of 1-bit bricks starting at (0, 0) and ending at (4, 0). This sequence contains 5 1-bit bricks. The center of this sequence is at coordinate (2, 0) and has two bricks to the left of it and two bricks to the right of it. Similar reasoning applies when constructing circles and rings. In particular, a Bricklayer circle/ring with radius 5 will have a diameter of 5+5+1 = 11. Because of this, it is very easy to make an off-by-one error when constructing artifacts containing circles/rings.

Write a Bricklayer program that builds a LEGO artifact similar to the “Bat in the Moon” shown below. Note that the red brick denotes the center of the bat as well as the center of the moon.

Before building this artifact it is recommended that you complete all Vitruvia exercises for Concept 13.

## Coding Exercise 2

Prerequisite Concepts |
6, 7, 10, & 12 |

Key Concept |
13 |

A *Venn Diagram* is a graphical formalism in which relationships between sets can be pictorially represented. In the traditional Venn diagram a set is denoted by a circle and intersections between two sets (i.e., elements belonging to both sets) are represented by overlapping their circles. The universal set (the set of all elements) is represented as a rectangle and it is within this rectangle that all circles must be drawn. Venn diagrams provide a natural way of understanding the dierent overlap possibilities between sets. For example, consider the possibilities of overlap among 3 sets A, B, and C. The sets A and B can overlap, A and C can overlap, B and C can overlap. And nally, A, B, and C can overlap. Venn diagrams are named after the British mathematician John Venn (1834-1923).

Write a Bricklayer program that builds a LEGO artifact similar to the Venn Diagram shown below.

Before building this artifact it is recommended that you complete all Vitruvia exercises for Concept 13.

## Coding Exercise 3

Prerequisite Concepts |
6, 7, 10, & 12 |

Key Concept |
13 |

The official symbol of the Olympics (since 1915) consists of five interlocking rings. The rings represent the ve inhabited parts of the world, and the design was created by Pierre de Fredy, Baron de Coubertin.

Write a Bricklayer program that builds a symbol, similar to the Olympic rings, shown below. Notice the rings in the LEGO artifact below are not interlocking. However, Concept 17 provides a mechanism which can be used to construct interlocking rings.

Before building this artifact it is recommended that you complete all Vitruvia exercises for Concept 13.

## Coding Exercise 4

Prerequisite Concepts |
6, 7, 10, & 12 |

Key Concept |
13 |

The Bricklayer coordinate system is discrete. Specically, coordinates consist exclusively of integers and bricks may only be placed at coordinate positions. For example, a 1-bit brick may be placed at (0, 0) or at (1, 0), but cannot be placed at an “in-between” location such as (1.5, 0). As a result, in order to divide a distance exactly in half, the distance must span an odd number of coordinate positions. Consider a sequence of 1-bit bricks starting at (0, 0) and ending at (4, 0). This sequence contains 5 1-bit bricks. The center of this sequence is at coordinate (2, 0) and has two bricks to the left of it and two bricks to the right of it. Similar reasoning applies when constructing circles and rings. In particular, a Bricklayer circle/ring with radius 5 will have a diameter of 5+5+1 = 11. Because of this, it is very easy to make an off-by-one error when constructing artifacts containing circles/rings.

This project, involves placing 4 rings in a checkerboard pattern. The rings should be touching, but not overlapping. Feel free to adjust the radius and thickness of the rings to make your checkerboard pattern look nice.

## Coding Exercise 5

Prerequisite Concepts |
6, 7, 10, & 12 |

Key Concept |
13 |

The Bricklayer coordinate system is discrete. Specically, coordinates consist exclusively of integers and bricks may only be placed at coordinate positions. For example, a 1-bit brick may be placed at (0, 0) or at (1, 0), but cannot be placed at an “in-between” location such as (1.5, 0). As a result, in order to divide a distance exactly in half, the distance must span an odd number of coordinate positions. Consider a sequence of 1-bit bricks starting at (0, 0) and ending at (4, 0). This sequence contains 5 1-bit bricks. The center of this sequence is at coordinate (2, 0) and has two bricks to the left of it and two bricks to the right of it. Similar reasoning applies when constructing circles and rings. In particular, a Bricklayer circle/ring with radius 5 will have a diameter of 5+5+1 = 11. Because of this, it is very easy to make an off-by-one error when constructing artifacts containing circles/rings.

This project, involves placing 4 rings in a checkerboard pattern. The rings should be touching, but not overlapping. Feel free to adjust the radius and thickness of the rings to make your checkerboard pattern look nice.

## Coding Exercise 6

Prerequisite Concepts |
6, 7, 10, & 12 |

Key Concept |
13 |

This project, involves creating a chessboard-like pattern using orange and violet rings instead of squares (you can use other bricks if you choose). In this pattern, adjacent rings should be overlapping and rings having the same color should share their edges. Feel free to adjust the radius and thickness of the rings to make your pattern look nice.

## Coding Exercise 7

Prerequisite Concepts |
6, 7, 10, & 12 |

Key Concept |
13 |

In Bricklayer, the *build2D* function is used in levels 1 – 3 to create a virtual space. For example, the function call *build2D(32,32)* will create a virtual space whose coordinates are in the range (0, 0)… (31, 31). In this example, the coordinates (~1, 1), (32, 2), and (100, 64) all lie outside of the range (0, 0)… (31, 31). (Note that, in Bricklayer a negative number is written using the symbol ~ instead of the symbol -.) We use the term *out-of-bounds* when referring to coordinates that lie outside the virtual space declared for a program.

What would you expect Bricklayer do if you attempt to place a brick at an out-of-bounds coordinate? Bricklayer has been implemented in such a way that it is safe with respect to the placement of bricks. In particular, before trying to place a brick in the virtual space, Bricklayer performs a boundary check to make sure the given coordinate is in the range of the virtual space declared for the program. If the coordinate is out-of-bounds the placement is ignored and a message is printed to the (black) command prompt window.

It is worth noting that the execution of a Bricklayer program will not halt or crash when an attempt is made to place a brick at an out-of-bounds coordinate. Under certain circumstances, this behavior can be used to advantage. For example, the function call:

circleXZ 11 RED (0,0)

will produce a quarter circle having radius 11 and center at (0,0). All other parts of the circle have coordinates that are out-of-bounds.

This exercise involves creating quarter circles consisting of lavender and red bricks (you can use other bricks if you choose). In this pattern, shown below, adjacent quarter circles should be touching, but not overlapping.

## Coding Exercise 8

Prerequisite Concepts |
6, 7, 10, & 12 |

Key Concept |
13 |

The compliment of the LEGO R artifact(s) in a virtual space can be created by replacing (in the virtual space) all non-empty bricks with EMPTY bricks and all EMPTY bricks with non-empty bricks. For example, assuming a virtual space created by *build2D(5,5)*, the two LEGO artifacts shown below are compliments of each other.

This exercise involves using quarter circles and circles of lavender bricks (you can use other bricks if you choose). The artifact shown below is the compliment of the artifact created in the previous project.

## Coding Exercise 9

Prerequisite Concepts |
6, 7, 10, & 12 |

Key Concept |
13 |

How much of the Moon can be seen from the Earth at night depends on the position of the Earth, Moon, and Sun. A new moon and a full moon occurs when the Earth, Moon, and Sun are in alignment – meaning a straight line can be drawn connecting all three bodies. An increasingly crescent-shaped moon is seen when the Earth, Moon, and Sun are close to alignment.

This exercise involves using circles to create a crescent whose shape is similar to what is shown below.

## Coding Exercise 10

Prerequisite Concepts |
6, 7, 10, & 12 |

Key Concept |
13 |

A rainbow is created when the light from the sun passes through water drops. As a ray of white light passes through a water drop it bends (refracts) and separates into the individual wavelengths (i.e., colors) from which it is composed. A signicant portion of this light is reflected back in the general direction in which the light entered the water drop.

Because water reflects light in a certain way, a primary rainbow can only be seen when the sun, the water droplet, and the observer form an angle of 42 as shown in Figure 1. Under good conditions, a secondary rainbow can be seen when the sun-water-observer angle is 50.

This exercise involves using rings to create a rainbow whose shape is similar to what is shown below.

## Coding Exercise 11

Prerequisite Concepts |
6, 7, 10, & 12 |

Key Concept |
13 |

This exercise involves building a sequence of interlaced rings. Ring centers are to located at the four corners of your virtual space. For example, the function call *build2D(32,32)* will create a virtual space whose 4 corners are (0, 0), (0,31), (31, 31), and (31, 0). Your LEGO artifact should be constructed using the following algorithm:

- For a given radius, build 4 rings, having thickness 1, each of whose centers lies at a different corner of your virtual space. Each of these 4 rings should be built using a different brick (e.g., RED, BLUE, etc.).
- Increase (or decrease) the radius by 1 and repeat Step 1. Do this until you have created at least 10 rings at each corner.

The result of this an algorithm is shown below. Notice the pattern that is created when the rings constructed from one type of brick (e.g., BLUE) intersect with the rings constructed from another type of brick (e.g., YELLOW).

**Advice:** In your implementation you should create a helper function, called *onceAround*, that takes a radius r as input (and possibly other things such as coordinates) implements Step 1 in the algorithm above.