Tutorial 9 is an exercise in using CGA to recreate a building (Figure 1) from a real-world photograph. The building has an irregular window layout and a recessed balcony at the top that require more complex CGA coding.
As I worked through the exercise, I was reminded of the similarities between the façade on this building and on my Willis Tower model. Both require “tiling” on individual floors, the divisions that create windows and other surfaces, but where the Willis façade has a regular pattern that repeats the same way on each floor, the Tutorial 9 model has an irregular window pattern on alternating floors. One of the first things I noticed was use of the “modulus” operator in a line of code for a “DoubleTile” rule:
DoubleTile(floorIndex,tileIndex) --> case tileIndex%2 + floorIndex%2 == 1:
Alternating Patterns with Modulus
Modulus is an operation that produces a remainder after dividing one number by another: for example with 4%3 (4mod3 or 4^3), 3 goes into 4 one time with a remainder of 1; 3 goes 8 twice with a remainder of 2. If you want to play with this in Excel, the formula is =MOD(A1,3) with A1 as the number to be processed and 3 as the divisor. Modulus is used when dealing with repetitive patterns. I often used the Modulus operator in web design for coloring dynamically generated table rows. As seen in Figure 2, if I wanted to color rows in groups of three, I would apply Mod 3 (or %3) to the row number. For groups of four, Mod 4 is used.
The two alternating window patterns for the building in Tutorial 9 are generated based on a modulus operation using the tile number (horizontally) Mod 2 plus the floor index (vertically) Mod 2. As seen in Figure 3, the two possible values either equal 1 or do not equal 1. Two different tile separations are generated based on the result.
The building face is repeatedly split into windows and frames as shown in Figure 4 above, to create fine details which are later clad with colors and materials. The code below uses the three texturing operations —setupProjection( ), set() and projectUV( ) — to project, texture and color surfaces.
The set() operation uses three of the material shape attributes that control shading, texturing and the model’s appearance after export:
material.specular.r|g|b – specular color is the color of shiny highlights on the surface as they reflect the color of lights that illuminate that surface.
material.shininess – dull to glossy, range 0-128.
material.reflectivity – 0 is no reflection and 1 is full reflection of the designated reflection map, which might contain imagery like clouds or other buildings.
Glass --> projectUV(0) texture(window_tex) color(white) set(material.specular.r, 0.4) set(material.specular.g, 0.4) set(material.specular.b, 0.4) set(material.shininess, 4) set(material.reflectivity,0.3) MilkGlass --> s('1,'1,frameW*1.2) i("builtin:cube") color(brightblue) setupProjection(0, scope.xy, scope.sx, scope.sy) texture(milkGlass_tex) projectUV(0) set(material.specular.r, 0.7) set(material.specular.g, 0.7) set(material.specular.b, 0.7) set(material.shininess, 20) set(material.reflectivity,0.05)