About FLL |
Navigation |
Playbook |
Strategy |
Models |
Techniques |
RobotC |
Programming |
Robot News |

genericShapes Module (genericShapes-ModuleScript.htm)

Copy the code from this page into the genericShapes module in your program.

The next step is to go to the Workspace in Roblox and add a Script. Rename that script: **startingScript** and paste the code in the example below.

We will be working with this starting script.

Run the program and try to jump onto the array of squares.

Next, make the computer draw and equal number of columns.

Run the program and try to jump onto the array of squares.

Next, make the computer draw 10 rows, 10 columns, and 10 layers tall. This will draw 1000 squares. If you stay with the value of 20 for the rows, columns and layers, the computer will have to draw 8000 squares. So, to save some time, we will limit the for loops to just 10 iterations.

Run the program and try to jump onto the array of squares.

Next, instead of using random colors for the squares. Try to make the colors related to the positionin the array. Since computer colors can be defined as a combination of Red, Green and Blue, create a value for each color component based on the incrementing variable used in the for loops.

Try to determine the change needed to the algorithm before going on to the next page. Then you can check your answer to see if you coded it the same way I did.

My solution was to use the expression:

There are other ways of doing this. For example, you could have created additional incrementing variables that could have incremented by 0.10.

I try to write expressions that utilize variables that already exist in the code. So writing the expression:

The example below is my solution to this challenge.

Try jumping to higher layers. You may notice that it is difficult to jump beyond the lowest layer. This is because the avatar needs to stand on the edge of the square. Jumping from this point causes the avatar to bump its head on the next layer.

As one possible solution to this problem, try adding discs to the squares. See example below.

Try jumping to higher layers. You may notice that it is impossible to jump beyond the lowest layer. This is because the discs are now blocking the ability to jump higher.

How can you tell the computer to do something for some of the time but not all of the time?

**Hint:** Create a "conditional" expression so that the discs will be drawn -- but only if the condition is **true**. Next, try to create an algorithm that will determine under what circumstances the condition should be **true**.

There are two approaches you can take when writing the algorithm that will determine under what circumstances the condition should be **true**.**Approach 1:** Use a random number function to randomly determine of the condition is true. For example: the expression **math**.**random() < 0.33** tells the computer to evaluate the expression as **true** (only 1/3rd of the time). This is because 0.33 is the decimal equivalent of 1/3rd (i.e., the fraction 1/3).**Approach 2:** Use an expression with the incrementing variables and modulus. For example: the expression **(i + j + k) % 5 == 0** tells the computer to evaluate the expression as **true** (only 1/5th of the time). This is because **n % 5** will evaluate to 0 only when **n** is evenly divisible by 5.

For this project you will use a **while** loop. The **while** and **for** loops are very similar. Both require a condition that must be true to remain in the loop. The main difference between them is the **for** loop usually specifies an incrementing variable whereas the **while** loop may use a variety of (and/or combinations of) conditions to remain in the loop.

For this project we will use a variable to keep track of the x-coordinate of our aqueduct section. We will initialize the variable to the value of our starting x-coordinate. Then we will remain in the loop until the variable is less than the ending x-coordinate. While in the loop we will decrement the variable by the width of the aqueduct section.

Use the example startingScript (below) to get started. *Do you see a section of the aqueduct?*

Now we will add the variable to represent the x-Coordinate of the aquedcut part. Notice that the xCoord variable is also used in the parameters passed to the

Add a loop and be sure to decrement the variable.

Here's my solution (see below). Notice that the arches in each subsequent layer get smaller. And because the arches are smaller, the decrement to the **xCoord** also decreases to match the size of the archway.

Travelling along the x-axis was easy. You only had to modify the value of one coordinate (X).

With diagonal arches, you will need to modify both the

Look at the figure of the triangle.

Around the year 500 B.C. a Greek mathematician (Pythagoras) discovered that the lengths of the sides of right triangles have a specific algorithm:

A^{2} + B^{2} = C^{2}

With this formula, it is possible to determine the lengths of the various sides of a right triangle.

In our Roblox diagonal aqueduct, we will move at a 45-degree angle exactly as it is shown as line "C" in the figure here. Line B will represent the amount of distance we need to move on the x-axis and line A will represent the amount of distance we need to move on the z-axis.

As you can see, both A and B are the same length and both are shorter than C and since we are moving at a 44-degree angle, the lengths of A and B are the same.

Therefore, we could re-write the formula as:

2 * B^{2} = C^{2}

Remember, the length of C is the width of the aqueduct section and the length of B is the distance to move on the x-axis and on the z-axis.

Since our goal is to solve for B, we will need to get the square root of both sides of the equation. This will become:

sqrt(2) * B = C

To get B on one side of the equation, we will divide both sides of the equation by **sqrt(2)**. This will become:

B = C / sqrt(2)

The square root of 2 is: ___????___

Ask the computer before continuing.

The square root of 2 is 1.414

Therefore,

B = C / 1.414

If our aqueduct section is 30 Roblox units wide, the formula becomes:

B = 30 / 1.414

What does B equal?

Ask the computer before continuing.

B = 21

This means that you will need to adjust the X and Z coordinates by 21 for each iteration through the **while** loop.

I could use a numeric literal in the expression to decrement the xCoord (see below).

But it might make more sense (programatically) to use a variable instead. See below:

Using a variable allows me to change the archwayWidth value once and all of the expressions in the loop will be evaluated accordingly.

The next step is to rotate the archways so that they form a straight line. Use the

Next, add the additional layers of archways before continuing. Don't forget...You need to reset the xCoord back to the starting value before each subsequent

The Roman Colesseum was built around the year 600 B.C. and is about 600 feet in diameter.

Build a replica of the Colesseum by creating the archways in a circle using sine and cosine to determine the coordinates of each section.

Before you begin, you need to determine the number of archway sections needed. So, calculate the circumference of the Colesseum, then divide that by the width of the archway.

How many archways will be needed to create the circle of the Colesseum?

Now divide 360 degrees by the number of archways to find out how many degrees of the circle will be used by each archway.

Use a

circumference = pi * diameter

Multiply the diameter of the Colesseum by pi to get its circumference. Then divide that circumference by the width of the archway (30 Roblox units).

One other important variable that we will need to use is:

The basic code for your program should begin to look like the following:

Next, we will need to figure out how to position the archways using the sine and cosine functions in Roblox. These functions in Roblox use

DO NOT JUST COPY AND PASTE THE CODE BELOW. INSTEAD, COPY-AND-PASTE THE CODE FROM THE ABOVE BOX AND THEN POSITION THE CURSOR IN THE LOOP AND TYPE ONLY THE FOLLOWING:

local radians =

The computer should recognize that you are trying to create an algorithm to calculate radians. The computer should then use its intelligence to guide you in the creation of the algorithm. Look at what the computer suggests. If you approve of the computer's suggestion, press the TAB key.

The above code is very close to creating the Colesseum. We now need to rotate the archway parts. Add the following property assignment:

The complete first layer of the Colesseum should appear as:

Add the new value for