Download Introduction to Programming in Turing First Edition

Transcript
Chapter 8 : Pixel Graphics
153
% Plots magenta circles of ever increasing radius centered
% in window until the edge of the window is reached
setscreen ("graphics")
const centerx := maxx div 2
const centery := maxy div 2
for radius : 1 .. centery
drawoval (centerx, centery, radius, radius, magenta)
end for
In Turing, the predefined procedure drawfilloval draws a filled
oval without the necessity of using drawfill. It has the form
drawfilloval (x, y, xRadius, yRadius, c)
and causes an oval to be drawn and filled with color c.
8.6
Animation
The effect of animation can be achieved with the Pow
program by erasing each circle after a delay before plotting the
next circle. To erase a circle you can re-plot it using the
background color, number 0. The predefined procedure delay can
be called to waste time between the plot of each circle in magenta
and the plot of the same circle in black. It has the form
delay (duration)
where the duration is in milliseconds. The Pow program can thus
be changed to the Ripple program in which a ripple starting at the
center of the window appears to move out, by adding the two
statements
delay (500) % Delay half a second
drawoval (centerx, centery, radius, radius, 0)
after the drawoval that produces the magenta circle. This method
of animation can be used for any simple form like a dot, line, box,
or oval.