Coding Exercise 1

Prerequisite Concepts 7, 12
Key Concepts 20, 21, 22, 23

Write a Bricklayer program that uses traverseWithin and brick functions to graph the line whose slope-intercept formula is:

z = 23x + 4

Your program should graph the line in two different ways. The first line should be created using BLUE bricks and its formula should delay the integer division operation. The second line should be created using YELLOW bricks and should be calculated using conversion (from integer to real). Important: places where the lines overlap should be constructed using GREEN bricks. The result for a 16 16 baseplate is shown in Figure 1.

level_5_01
Figure 1: Two different line formulas (BLUE and YELLOW) with overlap shown in GREEN.

Coding Exercise 2

Prerequisite Concepts 7, 12
Key Concepts 20, 21, 22, 23

Any triangle that is not a right triangle is an oblique triangle. Write a Bricklayer program that uses traverseWithin and brick functions to create an oblique triangle whose interior is filled-in. The triangle you create must be oblique and may not contain a vertical or horizontal line as one of its sides. All other properties of the triangle are left unspecified. An example of an oblique triangle is shown in Figure 2.

level_5_02
Figure 2: An oblique triangle.

Coding Exercise 3

Prerequisite Concepts 7, 12
Key Concepts 20, 21, 22, 23

A hexagon is a polygon having 6 sides. An example of a hexagon is shown in Figure 3. Write a Bricklayer program that uses traverseWithin and brick functions to create a hexagon whose interior is filled-in. The dimensions of the hexagon are left unspecied.

level_5_03
Figure 3: A hexagon.

Coding Exercise 4

Prerequisite Concepts 7, 12
Key Concepts 20, 21, 22, 23

Write a Bricklayer program that uses traverseWithin and brick functions to create a wire-frame cube such as the one shown in Figure 4.

level_5_04
Figure 4: A wire-frame cube.

Coding Exercise 5

Prerequisite Concepts 7, 12
Key Concepts 20, 21, 22, 23

Write a Bricklayer program that uses traverseWithin and brick functions to create a cube such as the one shown in Figure 5.

level_5_05
Figure 5: A cube constructed from straight lines.

Coding Exercise 6

Prerequisite Concepts 7, 12
Key Concepts 20, 21, 22, 23

Write a Bricklayer program that uses traverseWithin and brick functions to create a cube such as the one shown in Figure 6.

level_5_06
Figure 6: A cube constructed from diagonal lines.

Coding Exercise 7

Prerequisite Concepts 7, 12
Key Concepts 20, 21, 22, 23

Write a Bricklayer program that uses traverseWithin and brick functions to create a storage cube such as the one shown in Figure 7.

level_5_07
Figure 7: A storage cube.

Coding Exercise 8

Prerequisite Concepts 7, 12
Key Concepts 20, 21, 22, 23

Write a Bricklayer program that uses traverseWithin and brick functions to create a wedge similar to the one shown in Figure 8.

level_5_08
Figure 8: A wedge.

Coding Exercise 9

Prerequisite Concepts 7, 12
Key Concepts 20, 21, 22, 23

Write a Bricklayer program that uses traverseWithin and brick functions to create a tent-like wedge similar to the one shown in Figure 9.

level_5_09.png
Figure 9: A tent-like wedge.

Coding Exercise 10

Prerequisite Concepts 7, 12
Key Concepts 20, 21, 22, 23

Write a Bricklayer program that uses traverseWithin and brick functions to create a pyramid similar to the one shown in Figure 10. Note that the top of this pyramid consists of four 1-bit bricks.

level_5_10
Figure 10: A pyramid.

Coding Exercise 11

Prerequisite Concepts 7, 12
Key Concepts 20, 21, 22, 23

Write a Bricklayer program that uses traverseWithin and brick functions to create the artifact shown in Figure 11. Your solution should be general in the sense that it can be used (within minimal changes) to make an artifact of any size. More specifically, it should make use of the div operator.

level_5_11
Figure 11: Diagonal squares.

Coding Exercise 12

Prerequisite Concepts 7, 12
Key Concepts 20, 21, 22, 23

Write a Bricklayer program that uses traverseWithin and brick functions to create the artifact shown in Figure 12.

level_5_12
Figure 12: Vertical stripes.

Coding Exercise 13

Prerequisite Concepts 7, 12
Key Concepts 20, 21, 22, 23

Write a Bricklayer program that uses traverseWithin and brick functions to create the target-like artifact shown in Figure 1. Your solution should have the property that additional rings will automatically be created as the radius of the target gets larger. Specifically, other than changing the radius no additional coding is necessary to create additional rings. Hint: adapt the conditional expression used to place red/black bricks along the x-axis to the radius of the circle you are creating. In other words, the properties asked of the x values are now asked of radius values.

level_5_13
Figure 13: A target.

Coding Exercise 14

Prerequisite Concepts 7, 12
Key Concepts 20, 21, 22, 23

LEGO bricks are taller than they are wide/deep. If you look down on the top of a brick the shape of a 1-bit brick will be a square (i.e., the x and z lengths of a brick are equal). In contrast, if you look at a brick from the side the shape of a 1-bit brick is rectangular. Specifically, the y length of the brick is larger than the x/z length. When building a circle in the xy-plane or yz-plane this difference needs to be compensated for, otherwise circles will appear (slightly) oval. Figure 14a shows a target in the xy-plane whose radius is 11 and whose bands have a width of 3. In Figure 14a no compensation is performed to take
into account the dierence in brick lengths along the x-dimension and y-dimension. Even though the target appears fairly round, measuring the width and height with a ruler confirms that the target is indeed taller than it is wide. In contrast, the target shown in Figure 14b has an appearance that is more circular. The target shown in Figure 14b has a radius of 15 and a band width of 4.

Write a Bricklayer program that uses traverseWithin and brick functions to create the target-like artifact shown in Figure 14b. Your solution should have the property that additional rings will automatically be created as the radius of the target gets larger. Specifically, other than changing the radius no additional coding is necessary to create additional rings. Please consult on-line documentation to find out the dimensions of LEGO bricks.

level_5_14
Figure 14a: A slightly oval target.
level_5_14_b
Figure 14b: A circular target.

Coding Exercise 15

Prerequisite Concepts 7, 12
Key Concepts 20, 21, 22, 23

In the Basic Properties code-along an example was given showing how an artifact could be constructed by using a traversal and a brick function to slice a hollow sphere – keeping the desired parts and eliminating the rest. Adapt the techniques shown in the Basic Properties code-along to create the artifact shown in Figure 15.

level_5_15
Figure 15: An atomic sphere.

Coding Exercise 16

Prerequisite Concepts 7, 12
Key Concepts 20, 21, 22, 23

A celestial globe is projection of the sky onto the surface of a globe. At the center of a celestial globe resides the Earth. An armillary sphere is a celestial globe constructed from rings. As shown in Figures 16a and 16b, the number and kind of rings used to construct an armillary sphere can vary greatly from one sphere to another.

spherical astrolabe isolated on white background
Figure 16a: An armillary sphere.
Armillary sphere
Figure 16b: An armillary sphere.

In the Basic Properties code-along an example was given showing how an artifact could be constructed by using a traversal and a brick function to slice a hollow sphere – keeping the desired parts and eliminating the rest. Adapt the techniques shown in the Basic Properties code-along to create the artifact shown in Figure 16c.

level_5_16
Figure 16c: A Bricklayer rendition of a hollow armillary sphere.

Coding Exercise 17

Prerequisite Concepts 7, 12
Key Concepts 20, 21, 22, 23

A celestial globe is projection of the sky onto the surface of a globe. At the center of a celestial globe resides the Earth. An armillary sphere is a celestial globe constructed from rings. See exercise 16 for examples of actual armillary spheres.

In the Basic Properties code-along an example was given showing how an artifact could be constructed by using a traversal and a brick function to slice a hollow sphere – keeping the desired parts and eliminating the rest. Adapt the techniques shown in the Basic Properties code-along to create the artifact shown in Figure 17.

level_5_17
Figure 17: A Bricklayer rendition of a hollow armillary sphere.

Coding Exercise 18

Prerequisite Concepts 7, 12
Key Concepts 20, 21, 22, 23

A celestial globe is projection of the sky onto the surface of a globe. At the center of a celestial globe resides the Earth. An armillary sphere is a celestial globe constructed from rings. See exercise 16 for examples of actual armillary spheres.

In the Basic Properties code-along an example was given showing how an artifact could be constructed by using a traversal and a brick function to slice a hollow sphere – keeping the desired parts and eliminating the rest. Adapt the techniques shown in the Basic Properties code-along to create the artifact shown in Figure 18.

level_5_18
Figure 18: A Bricklayer rendition of a hollow armillary sphere.

Coding Exercise 19

Prerequisite Concepts 7, 12
Key Concepts 20, 21, 22, 23

When combined with traverseWithin, the mod operator can be used to create repeating patterns. The artifact shown in Figure 19 is a composition of three distinct repeating artifacts. The GREEN artifact is a vertical xy-plane that is positioned diagonally across the z-axis. The mod operator is used to create three repetitions of the GREEN artifact. The BLUE and YELLOW artifacts are slanted xy-planes in which the mod operator is also used to create three repetitions of each artifact.

Write a Bricklayer program that creates an artifact similar to the one shown in Figure 19. Hint, first focus on creating a single GREEN plane. Then focus on creating a single BLUE/YELLOW plane. After this has been accomplished introduce the mod operator to create repeating planes. An example of how the mod operator can be used to create a repeating pattern can be found here. Note that the mod operator also can be applied to x, y or z individually.

level_5_19
Figure 19: A composition of planes.

Coding Exercise 20

Prerequisite Concepts 7, 12
Key Concepts 20, 21, 22, 23

In the Slanted Triangles code-along, ideas were discussed and examples given on how to create slanted triangles having various orientations. Adapt the ideas discussed in that code-along to create the artifact shown in Figure 20.

level_5_20
Figure 20: Slanted triangles.

Coding Exercise 21

Prerequisite Concepts 7, 12
Key Concepts 20, 21, 22, 23

In the Slanted Triangles code-along, ideas were discussed and examples given on how to create slanted triangles having various orientations. Adapt the ideas discussed in that code-along to create the artifact shown in Figures 21a and 21b.

level_5_21a
Figure 21a: View 1 – the BLUE base runs along the x-axis with z = 0.
level_5_21b
Figure 21b: View 2 – the YELLOW base runs along the z-axis with x = max.

Coding Exercise 22

Prerequisite Concepts 7, 12
Key Concepts 20, 21, 22, 23

The ninth episode of the third (and sadly final) season of the original Star Trek series was titled  “The Tholian Web“. In this episode two Tholian ships attempt to capture the Enterprise in an energy web consisting of criss-crossed lines. The Enterprise must figure out a way to save Captain Kirk and escape before the Tholian ships complete their energy web.

level_5_22_tholian_web
Figure 22a: The Enterprise being slowly enclosed in a Tholian web.

Write a Bricklayer program that creates a 2D Tholian Web-like artifact similar to the one shown in Figure 22b. Recall that when combined with traverseWithin, the mod operator can be used to create repeating patterns.

level_5_22
Figure 22b: A 2D Tholian web.

Coding Exercise 23

Prerequisite Concepts 7, 12
Key Concepts 20, 21, 22, 23

Write a Bricklayer program that creates a four-color sphere similar to the one shown in Figure 23. Your program should NOT make use of the setMySpace function. Instead, the traverseWithin function should be used. The basic idea is to create a hollow sphere consisting of a single color and to then use one or more traversals to replace portions of the sphere with different colored bricks. Note how all four colors come together at the front of the sphere.

level_5_23
Figure 23: A four-color sphere.

Coding Exercise 24

Prerequisite Concepts 7, 12
Key Concepts 20, 21, 22, 23

When combined with traversals, the mod operator can be used to create repeating patterns. In this context, the div operator can be used to control the size of the pattern that is to be repeated.

Write a Bricklayer program that creates a chess cube shown in Figure 24. One way to approach this problem is to first figure out how to use mod to create a chess cube whose individual BLACK/WHITE cubes are 1x1x1 bricks. Then experiment with how the div operator can be used to increase the size of the individual BLACK/WHITE cubes.

level_5_24
Figure 24: A chess cube constructed using 5x5x5 BLACK/WHITE cubes.

Coding Exercise 25

Prerequisite Concepts 7, 12
Key Concepts 20, 21, 22, 23

Pokémon Go is a game for iPhone and Android devices that combines the virtual world in which Pokémon live with the real world in which the players live. The main activities of the game include the following: (1) hunting and catching Pokémon, (2) visiting  PokéStops to gather supplies, (3) battling and joining PokéGyms, and (4) hatching eggs. The game overlays the virtual world of the Pokémon on the real world. Positional data is used to track a player’s position and relate this position to objects in the Pokémon world.

The primary activity in the game is to catch Pokémon, which can be caught using a variety of balls. The most common ball is the Poké Ball. Write a Bricklayer program that creates a Poké Ball similar to the one shown in Figure 25. This Poké Ball was was created using hollowSphere, ringY, ringZ, and traverseWithin functions.

level_5_25
Figure 25: A Poké Ball.

Coding Exercise 26

Prerequisite Concepts 7, 12
Key Concepts 20, 21, 22, 23

Pokémon Go is a game for iPhone and Android devices that combines the virtual world in which Pokémon live with the real world in which the players live. The main activities of the game include the following: (1) hunting and catching Pokémon, (2) visiting  PokéStops to gather supplies, (3) battling and joining PokéGyms, and (4) hatching eggs. The game overlays the virtual world of the Pokémon on the real world. Positional data is used to track a player’s position and relate this position to objects in the Pokémon world.

The primary activity in the game is to catch Pokémon, which can be caught using a variety of balls. One such ball is the Great Ball which becomes available when a player reaches level 12. Write a Bricklayer program that creates a Great Ball similar to the one shown in Figure 26. This Great Ball was was created using hollowSphere, ringY, ringZ, and traverseWithin functions.

level_5_26.png
Figure 26: A Great Ball.

Coding Exercise 27

Prerequisite Concepts 7, 12
Key Concepts 20, 21, 22, 23

Pokémon Go is a game for iPhone and Android devices that combines the virtual world in which Pokémon live with the real world in which the players live. The main activities of the game include the following: (1) hunting and catching Pokémon, (2) visiting  PokéStops to gather supplies, (3) battling and joining PokéGyms, and (4) hatching eggs. The game overlays the virtual world of the Pokémon on the real world. Positional data is used to track a player’s position and relate this position to objects in the Pokémon world.

The primary activity in the game is to catch Pokémon, which can be caught using a variety of balls. One such ball is the Ultra Ball which becomes available when a player reaches level 20. Write a Bricklayer program that creates an Ultra Ball similar to the one shown in Figure 27. This Ultra Ball was was created using hollowSphere, ringY, ringZ, and traverseWithin functions.

level_5_27.png
Figure 27: An Ultra Ball.