Back to index
The student may experience a small amount of frustration when it comes to
centering squares in a square applet area. Let's say that we are dealing
with a 200 x 200 applet area and that we want to center a square in this
area so that there is ten units between it and the applet edge on all
sides. Here is the line that would work for this:
ctx.fillRect(10,10,180,180);The student might, at first, think that the last two numbers should both be 190. Upon reflection the student will realize that these numbers must both be 180 since 10 units on the right and the left make a total of 20 units and 200 minus 20 is 180. The same thing goes for the top and the bottom of the square.
EXAMPLE: Inspect the code for this applet. You will notice the embedding of the filled rectangles was accomplished using a for-loop. Also you will notice that color values were stored in an array for easy access within the for-loop. You will not be expected to create an array or a for-loop in this assignment, but note these features for future reference. ASSIGNMENT: You will alter this applet in the following ways:
|