Make Mine MAPPER #19 -------------------- by Rob Haeuser Let's Get Primitive, Graphically Speaking ---------------------------------------------------------------- It's cabin fever, I tell ya. Pure and simple. Nobody in their right mind would knowingly just sit there during break and key in this stuff, when, for the first time in ages, the sun is actually shining. ZI...ZT? What the heck is that? A new lotion to treat the acne we got from consuming massive quantities of goodies over the holidays? I think not. Amazingly, his brain was still in communication with his mouth, even though it had been hanging open. "Look at this for a minute. MAPPER primitives are some pretty powerful stuff." Must be. I could sense that an addiction had already set in. "Are you sure you don't need a little vitamin D instead? The sun's out, you know..." "Yeah, but wait a minute. Check this out." He displays a rid with an eye-maiming blob of seemingly meaningless gibberish code: endless streams of either one or two letters usually followed by a number or pair of numbers. Whoa! Definitely martian. "Sanskrit?" I ask. Did he say primitive, or ancient? The cold air is definitely slowing down sound waves, 'cause it sounded like he was talking at half-speed. "I've heard that a vitamin D deficiency can cause slow speech, at least in experimental animals." "Har-de-har and a yuk-yuk, too." At least I had broken through the outer shell of his consciousness. "Have you ever seen MAPPER graphics primitives?" Uh-oh. A trick question. He was more alert than I had realized. "Uh, sure. Why, just the other day I had occasion to run across some fairly primitive graphics somebody had scrawled on a wall downtown. Couldn't make out what they were trying to say, though." "Ok, jerk. Sit down. How's about a little review of some primitives? Needless to say, you seem to be at about the right level for it." Why, I believe I've been insulted. "Think of the computer screen as a two-dimensional surface, with horizontal and vertical coordinates, represented by X and Y, respectively. In theory, each has a maximum value of 32,767, but because most display and print devices think rectangular, the maximum Y is usually a good bit less. For a PC, the maximum Y value is 23,999. So the surface consists of 786,375,233 individual points! "Each individual point can be one of fifteen colors (see Figure 1). Fortunately, you don't have to tell the machine what to do with each point, or you'd be sitting there watching your fingernails grow. That really would be primitive. ---------------------------------------------------------------- FIGURE 1 -------- Number Color Number Color ------ ----------- ------ ----------- 0 Black 8 Grey 1 Red 9 Tan 2 Green 10 Aqua 3 Yellow 11 Lime 4 Blue 12 Violet 5 Magenta 13 Hot pink 6 Cyan 14 Turquoise 7 White 15 Pink ---------------------------------------------------------------- "There are 39 basic primitive commands, grouped into six major categories: Control; Creating shapes; Using characters; Polygon attributes; Marker attributes; and Line attributes." Can you believe the guy said all that in one breath? I'll bet he wants you to check out Figure 2, too. ---------------------------------------------------------------- FIGURE 2 -------- Function Command Syntax Action ----------- ------------------ ------------------------- Control ZAx Activate Workstation ZDx Deactivate Workstation ZIx Initialize graphics ZOx Open Workstation ZCx Close Workstation R Paper size Q Pen speed ZNx Redraw all segments ZSx Set deferral state ZT Terminate graphics Creating *Mr,sa,ea Arc Shapes Or Circle Ax,y Move absolute Bx,y Move relative Cx1,y1[,x2,y2...] Polyline absolute Dx1,y1[,x2,y2...] Polyline relative E " " " " Polymarker absolute F " " " " Polymarker relative G " " " " Polygon absolute H " " " " Polygon relative Ix,y Rectangle absolute Jx,y Rectangle relative Kr,sa,ea Sector *Where "r" is radius, "sa" is starting angle, and "ea" is ending angle Using CFx Set font characters CJx,y Set character justification CPx Set character path CSx Set character space CZx,y Set character size CTx Set character type LTx Text color Polygon LBx Background color attributes LFx Fill color PIx Set fill area interior PHx Set fill area style PEx Set polygon edge style Marker SIx Set marker color attributes Sx Set marker type Line LLx Line color attributes LSx Set line style ---------------------------------------------------------------- "You don't expect me to understand all that, do you? You're talking to someone who has trouble balancing the proverbial checkbook." His smile grew sinister. A dark cloud gathered around his brow, and his eyes began to glow a dull red. His voice dropped a good two octaves, rumbling: "My, my. Aren't we suddenly humble?" I love pretending to be ignorant: it brings out the best in people. Then it was like somebody had upped the juice a few volts. His voice began to speed up, and I swear it jumped a good three and a half octaves in one sentence. "Perhaps if I just wired you up directly to the box and downloaded some primitives to your cerebral cortex, then, maybe, you might grasp the true glory of graphic power unharnished!" He was starting to sound like a comic book character. "Ok, so 'splain me, already." Look out, kid-speak in use. That got his goat, and probably the rest of his herd, 'cause I'm sure I heard a bunch of loud cracks and pops, like his brain was fizzing. No, he was just cracking his knuckles. Gee, this must be about to get serious. "Can you get serious for a minute?" See, I told you. "Remember basic geometry? It all boils down to points on a grid, get it. Connect the dots. "You can move to an "absolute" position on the grid by using the "Ax,y" command. For example, to position yourself at the center of the screen, you would issue the command "A16383,12000". Then, to draw a small red circle, issue the command "LF1O100". The "LF1" sets the fill color to red, and the "O100" draws a circle 100 points in radius. "Wrap all that with a "ZI" in front and a "ZT" in the end, put it in a rid, enter "G -" on the control line, and guess what'll happen? A widdle wed dot will hop on the middle of the screen." Why do I get the feeling that the conversation suddenly degenerated? "Basic shapes like circles, squares, rectangles, and polygons can be created with simple commands. Text can be easily generated and scaled. Color is a snap; fill patterns; even how fast to move the plotter pen. What more could you want? "How's about something goofy? Or what's that mouse's name?" "Nah. A mouse head is just a circle and two arcs, anyway. How about something stupid and colorful?" Now he's talking (about Figure 3, that is). ---------------------------------------------------------------- FIGURE 3 -------- *Description: run to generate a bunch of pretty circles *================================================================ @LDV V1I2=1,V2I5=10 . ZIA16383,12000 LFV1OV2 @5:INC V1 INC,200 V2 IF V1 > 15 LDV V1=1 ;\ IF V2 > 32767 DEC,200 V2 . ;GTO 5 . LFV1OV2 @8:INC V1 DEC,200 V2 IF V2 < 1 . ;\ IF V1 > 15 LDV V1=1 ;GTO 8 . ZT @BRK DSG,-0 . @SC Q MODE,A REL . ---------------------------------------------------------------- "We're gonna use V1 for the color and V2 for the circle radius, so we're starting off with a red circle that has a radius of 10 points. The next line goes into the output area, where the primitives will be accumulated. The "LFV1" sets the fill color to whatever V1 currently represents, and the "OV2" creates a circle of whatever radius is contained in V2. "At label 5, we increment V1 to the next color, and V2 by 200 (arbitrary number chosen for speed of display). If V1 exceeds 15, the highest color available, we roll it back down to one. Then, if V2 exceeds the maximum (32767), we will decrement it and fall to the next section. Otherwise, we loop back up to create another line of primitive code. "The next section does the same thing in reverse, shrinking the circle back a little bit each time. After we finally run V2 into the ground, we issue the "ZT" command to terminate graphics, BRK the output area, and display the graphics code with DSG. "What happens is nothing special, but it's fun to look at. A circle begins to grow in the middle of the screen, constantly changing colors, and then, right when it reaches the screen border, it begins to shrink back down on itself, again changing colors all the while. Like I say, dumb but cute." So what about practical applications? I have a system that periodically analyzes a database, creating and storing graphic primitives for later recall. Apparently, after a new release, one of the graph runs developed a nasty habit of miscalculating the character size for value labels. As we all know, that is controlled with the "CZx,y" command. I displayed the primitives, found the CZ command, modified the "x,y" numbers down a little, and, tah-dah! Perfect graph! But, really, there's nothing magical about it. Like the guy said, a mouse is nothing but a circle and two arcs. Sounds oddly like a familiar hamburger chain, doesn't it?