Graphics Reference
In-Depth Information
Figure 2.21.
Animating with “trailing
blank” blocks.
Figure 2.22.
or / xor animation.
without disturbing the background. One can also use xor to do “rubber banding.” For
example, to drag a line anchored to a point around on the screen with the mouse, one
would perform the following two instructions in a loop:
Erase the current line segment.
Draw the line segment from the fixed point to the new location of the mouse.
The advantage of xor ing is speed but its disadvantages are
The background can bleed through because if it is nonzero, then xor operation
will add bits to the image being drawn.
One cannot xor a zero.
One can also use combinations of bit operations. Here is an example using the
or / xor combination. See Figure 2.22. Suppose that one wants to move a ball around
on a grid. Assume that the ball has color c1, the grid has color c2, and the background
is black. Define two blocks A and B as follows: A contains a ball of color c1 on a black
background and B contains a white ball on a black background. See Figure 2.22(a).
If we want to write the ball to block W on the screen, we first save W and then replace
W by ( BorW ) xor A . See Figure 2.22(b). To make this work, we need to assume that
c1 and c2 are complimentary colors in the sense that
(a) c1 or c2 = white (or all 1s)
(b) c1 and c2 = black (or 0)
Search WWH ::




Custom Search