BBS: Inland Empire Archive Date: 07-02-92 (22:21) Number: 230 From: MATT PRITCHARD @ 930/21 Refer#: NONE To: MIKE THAYER Recvd: NO Subj: Icon routines 2 of 2 1/2 Conf: (2) Quik_Bas
___Cont from previous message---
MT> Drawing a straight line is easy. Just find the two end points and
MT>call for the
MT> LINE(x1,y1)-(x2,y2),13
MT>That's easy. But what if you want to draw a zig-zag between those two
MT>points? Straight lines were not always used in Heraldry. There are so
MT>many different line patterns they used. If I could get at least two
MT>different line patterns I would be a happy camper.
MT> I played with the DRAW statement,
Hmm, I think you'll find that lacking in capability.
MT> But I didn't know how to compute the angle. I've received
MT> three postings so far on that problem. One illumanited the inherent
MT> short falls of using that method with SCREEN 9.
MT> For the past week I've been playing using LINE but in short
MT> steps. Getting a dashed line a certain length was easy, but trying
MT> to draw another line underneath that is perplexing.
MT>I'm trying to figure
MT>a way to rotate all points from the first set 90 degrees so that no matter
MT>the angle, the lines always form right angles. As an
MT>example, if points x1,y
MT>and x2,y2 draw a horizontal line then all I need to do is drop down an
MT>increment (let's say 5) on both ends forming x3,y3 and x4,y4 and draw the
MT>line:
MT> x1,y1 x2,y2
MT> .--------------------------------.
MT> 5 5
MT> .--------------------------------.
MT> x3,y3 x4,y4
MT> All lines meet at right angles.
MT> So far, so good. Now if one end of the orginal line drops farther than
MT>the other, i.e. x2,y2 drop 10 units further, than x3,y3
MT>should move to match
MT>(x4,y4 are assumed to have moved as well), ensuring all
MT>lines drawn continue
MT>to be made at right angles.
MT> Any suggestions?
Hell yes! 8)
You need to be thinking vectors. You need to be thinking
relative coordinates. You need to be thinking real
numbers... I am dropping into impromtu mode...
Wheeeeeee... (Eddie Van Halen guitar starts in
background...)
40 seconds and a couple scribbles on a graph paper pad later...
Ah yes, it is all clear to me now!
Oh? Say what? You'd like it to be clear for you... ok.. sure!
A line between point (X1,Y1) and point (X2,Y2) is a vector. The vector we'll
represent as (Vx,Vy) where Vx = X2-X1 and Vy = Y2-Y1.
To make a sqaure pattern out of the line, (or other shaped
line patterns), we break the vector up into N little
vectors. N is how many squares or repeating patterns we
want to make. Instead of drawing a normal, straight, mini-
vector we'll get to the end point by way of other points
that a relative to the starting point.
Let me do a quick bit of code:
SCREEN 9
X1 = 10 : Y1 = 10 ' Line that slants sharply down.
X2 = 40 : Y2 = 100 ' and to the right.
' +---->+----> ... each "+---->" is one mini-vector
'
'Draw +--+ +--+ +-->
' | | | | Pattern
' +--+ +--+
Vx = X2 - X1 : Vy = Y2 - Y1
N = 10 ' Number of patterns to appear.
Vx1! = Vx / N 'size of vector for one pattern
Vy1! = Vy / N
Sx! = X1 : Sy! = Y1 ' Starting coordinates.
'Make sub vectors that make up pattern
Vx2! = Vx1! / 2 ' 1/2 len, parallel to vector
Vy2! = Vy1! / 2
Vx3! = -Vy2! ' 1/2 len, 270 deg to vector
Vy3! = Vx2!
Vx4! = Vy2! ' 1/2 len, 90 deg to vector
Vy4! = -Vx2! '
FOR Z = 1 TO N ' # of patterns to make
'Follow direct line to point B
CALL MOVE.VECTOR( Sx!, Sy!, Vx2!, Vy2!, 7 )
'Hook it 90 deg to right (270 deg)
CALL MOVE.VECTOR( Sx!, Sy!, Vx3!, Vy3!, 7 )
'Now follow parallel to direct line
CALL MOVE.VECTOR( Sx!, Sy!, Vx2!, Vy2!, 7 )
'Hook it 90 deg to left, getting back origional line
CALL MOVE.VECTOR( Sx!, Sy!, Vx4!, Vy4!, 7 )
NEXT Z
DO
LOOP WHILE LEN(INKEY$) = 0
'Sub to move and draw our vector
SUB MOVE.VECTOR( Px!, Py!, Vx!, Vy!, Colour% ) STATIC
Px = INT( Px! + 0.49 )
Py = INT( Py! + 0.49 )
Px! = Px! + Vx!
Py! = Py! + Vy!
Dx = INT( Px! + 0.49 )
Dy = INT( Py! + 0.49 )
LINE (Px,Py)-(Dx,Dy),Colour%
END SUB
>>> Continued to next message
===
* SLMR 2.1a * On a clear disk you can seek forever

Books at Amazon:
Back to BASIC: The History, Corruption, and Future of the Language
Hackers: Heroes of the Computer Revolution (including Tiny BASIC)
Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution
The Advent of the Algorithm: The Idea that Rules the World
Moths in the Machine: The Power and Perils of Programming
Mastering Visual Basic .NET