Library for drawing snail graphics in Microsoft QuickBasic 4.5 Written by Jonathan H. Connell, April 2000 ======================================================================== Invisible drawing agent can be given a heading and length. Plays a tone corresponding to direction as it draws. Starts out in the center of the screen aimed upward. These commands change the current direction the snail is headed: Aim (dir$) - sets the absolute direction for drawing - use compass directions such as "N" or "NNE" - understands "up", "down", "left", or "right" as well - happens instantaneously AimN (h) - sets the direction directly as an integer o'clock value - "clock" angle 3 means the same as "right" or "east" AimX (hlo, hhi) - sets heading randomly between two clock angles - can handle wrap around if hlo > hhi Turn (num, den) - turns num/den fraction of a circle - num can be positive or negative - happens instantaneously TurnX (nlo, nhi, den) - generates random turn from nlo/den to nhi/den - if nlo > nhi performs appropriate wrap around Twist - sets the current direction to be the new "up" - use to reorient figures drawn with absolute Aim commands Untwist - resets "up" to be toward top of screen These commands draw lines and circles: Trail (len) - makes a trail of the given number of steps (negative OK) - draws slowly and plays a tone as it goes TrailX (dlo, dhi) - draws random length line between dlo and dhi steps TrailHome - draws a line exactly to remembered position (see Remember) - heading reverts to saved heading for home location Vector (dir$, len) - draws a trail of given length in some direction - does an Aim (e.g. "east", "up") then a Trail VectorN (h, len) - draws a trail of some length at given "clock" angle - does an AimN (i.e. "6" = down) followed by a Trail Diagonal (up, rt) - changes heading and draws line to given offset - picks correct length to exactly connect - heading adjusted to aim along this line Nest (factor) - draws a circle at the current position - factor determines diameter versus current step size - negative factor shrinks circle (e.g. -2 = half size) Show - draws the snail at the end of its trail - does not contribute to bounding box computed by "Measure" - useful as a debugging tool halfway through a drawing These commands change the snail's position without drawing: Move (len) - moves the snail along its current heading - length can be negative for moving opposite to heading - does not draw while moving MoveX (dlo, dhi) - generates random displacement between dlo and dhi Displace (dir$, len) - change to given direction then travel - calls Aim (e.g. "nw") then Move DisplaceN (h, len) - turns to given "clock" angle then moves - calls AimN (e.g. "9" = left) then Move Shortcut (rt, up) - moves directly to specified offset - heading adjusted to aim along this path Origin () - returns snail to the center of the screen facing upwards Remember () - records the current position and orientation for later - does not stack, only one position ever remembered Home () - returns to whatever position was recorded Measure () - finds size of drawing that follows - turns off actual drawing temporarily - determines bounding box (min and max of x and y) - MUST call Center to re-enable drawing again Center () - moves so the measured object is centered on this point - only use this on bottom-level graphics primitives - other positions can be referenced via the Flee function - not rotationally invariant, bounding box center can shift These functions affect the style used for drawing: Init () - resets coordinates, headings, and all drawing parameters Speed (persec) - speed at which to draw lines (steps per second) - if never called, default is 9 steps per second - a speed of zero goes very fast with no sound Hue (col$) - what color to draw lines in - "w", "y", "r", "b", "g", "a", "p" (in order) - "white", "yellow", "red", "blue", "green", "aqua", "pink" - can use a number 0-6 like "3" (i.e. means blue) - if never called, default is red HueN (col) - sets a color directly from a numeric specification - 0 = w, 1 = y, 2 = r, 3 = b, 4 = g, 5 = a, 6 = p HueX (hlo, hhi) - picks a hue with number between hlo and hhi - wraps around if hlo > hhi (e.g. 6,0 = pink or white) - for any color: CALL HueX(0, 6) Size (pels) - number of pixels per step - if never called, default is 20 pixels per step SizeX (plo, phi) - picks a step size between plo and phi pixels Grow (factor) - makes the step size temporarily bigger or smaller - multiplies current size by factor (if positive) - if factor negative, divides size by this - can not be stacked (i.e. use only at bottom level) Shrink () - restores size before last Grow was called ----------------------------------------------------------------------- A number of HIDDEN variables control the whole system: tcx = current snail X position tcy = current snail Y position tcd = current snail heading tdd = reorientaton angle of coordinate system tcc = color to draw lines in tcz = size of steps tcs = speed at which to draw lines f = current frequency of sound to play (in Hertz) thx = remembered X position for homing thy = remembered Y position for homing thd = remembered heading for homing thz = remembered previous drawing size tmx = starting X position when measuring tmy = starting Y position when measuring tmd = starting direction when measuring tmz = starting step size when measuring tms = regular speed saved when measuring tmc = drawing color before measuring started tmi = whether measuring has started yet or not tx0 = minimum X of measured drawing so far tx1 = maximum X of measured drawing so far ty0 = minimum Y of measured drawing so far ty1 = maximum Y of measured drawing so far degrad = multiplicative factor to convert degrees to radians --------------------------------------------------------------------- This is file c:\snail\snail.txt