
Use a toggle variable when
you need to alternate
between two values.
SOFTWARE
ENGINEERING TIP
342 CHAPTER 6 Flow of Control,Part 2: Looping
(diameter / 2). So, the upper-left x value is the x value of the center point
minus half the diameter (
centerX – diameter / 2). Similarly, the upper-left y
value is the y value of the center point minus half the diameter (
centerY –
diameter / 2
).
Thus, we instantiate each circle using the following statement:
circle = new Circle( centerX - diameter / 2,
centerY - diameter / 2,
diameter, toggleColor );
To alternate between red and black circles, we use a toggle variable, which
is a variable whose value alternates between ...