Download Introduction to Programming in Turing First Edition

Transcript
Chapter 20 : Advanced Pixel Graphics
369
% The "DrawDesign" program
% Repeats a pattern in window
setscreen ("graphics")
(include procedure drawflag here)
% Draw a magenta and green pattern
const width := 20
const height := 10
for xcount : 0 .. 9
for ycount : 0 .. 9
const x := xcount * (width + 2)
const y := ycount * (height + 2)
drawflag (x, y, width, height, green, magenta)
end for
end for
var reply : string (1)
getch (reply)
Another way of programming this design would be to draw the
flag once then use the predefined procedure takepic to record the
pattern in a buffer array and then use drawpic repeatedly to place
the pattern anywhere you want in the window.
The procedure takepic records the pixel values that are in a
rectangle with bottom left and top right corners (x1, y1) and (x2,
y2) in an integer array called buffer. The form of takepic is
takepic (x1, y1, x2, y2, buffer)
To determine what size the integer array buffer should be you can
use the predefined function sizepic in the form
sizepic (x1, y1, x2, y2)
To reproduce a picture stored in buffer by takepic with its lower
left corner at (x, y) you use drawpic in the form
drawpic (x, y, buffer, picmode)
where picmode has a value 0 if you want to reproduce the original
picture exactly, or 1 if you want to superimpose the picture onto
the pixels it is covering. Picmode 1, also called XOR mode,
combines the picture with the covered pixels in a way that