< Back

Lab 4: Expressions

Variables allow us to store values long term in our program. One of the major uses for them today will be reducing the effort of typing values in our code. But they also aid with readability of a program, and can be very useful in computing values. But we won't see that latter one until Thursday.

For all of our activities, make sure your practice with the new blocks today. Some of the activities you can complete without using the new blocks. They do save some time and headaches. Open up the Practice Area, and take a crack at the following activities.


Activity 1: Parallelogram

Create a blockly program which uses variables angle_1, angle_2, and length to draw a parallelogram on the turtle pond. length can be any value you want, and angle_1 can be any angle you want. The value of angle_2 should be determined by angle_1 through some mathematical expression.

Geometrically speaking, in a parallelogram, opposite angles are congruent (meaning they are equal). Adjacent angles add up to 180.

Examples of Parallelograms

All of the following parallelograms were drawn using 100 as the side length, and varying angle_1. You do not need to match any of these pictures to get checked off, but your could should be able to generate these with the correct values.


Activity 2: Triforce

Create a blockly program which will be able to draw a Triforce roughly centered in the turtle drawing area. A Triforce is a triangle which has a smaller triangle drawn inside, as follows.

You must use the mathematical expression blocks to compute the size of a line in the smaller triangle from the side of a line in the larger triangle. You can use this computation to also determine where to start drawing from for the 2nd triangle.


Activity 3: Bezier Curve

Create a blockly program which will be able to draw a bezier curve between the positive x axis and the positive y axis. In order to get the curve drawn, you need to determine how big the curve will be. If I set the curve to size 100, then I want to connect points \((0, 25), (75, 0)\), \((0, 50), (50, 0)\), and \((0, 75), (25, 0)\).

This might seem intimidating, but I got those values by finding the value that is 25% (.25), 50% (.5) and 75% (.75) along one of the lines (the x axis, for example), and connecting it to the point that is 75%, 50%, and 25% along the other line.

Note that your program should work for any size bezier curve, not just 100! Use a variable and expressions to compute the other points!