since Power Basic doesn't support mode 13h directly...
'_|_|_| BRESNHAM.BAS
'_|_|_| This program demonstrates the Bresenham Algorithms
'_|_|_| for the drawing of lines and circles in mode 13h.
'_|_|_| Adapted from BRESNHAM.C in Bob Stout's SNIPPETS.
'_|_|_| No warrantee or guarantee is implied or given.
'_|_|_| Released to PUBLIC DOMAIN by Kurt Kuzba. (4/16/96)
DECLARE SUB BLine (x%, y%, x2%, y2%, c%)
DECLARE SUB BCircle (x%, y%, r%, c%)
Vmode 19
HIGH% = 200 'The PXL and BCircle will need to know the screen
WIDE% = 320 'dimensions, which are found in these SHARED variables
ndx% = 0: RANDOMIZE (TIMER * 100 + INP(64))
DIM xy(412) AS LONG: BCircle 159, 99, 65, 77: DEF SEG = &HA000
FOR t& = 0 TO 63999
IF PEEK(t&) = 77 THEN xy(ndx%) = t&: ndx% = ndx% + 1
NEXT:
WHILE INKEY$ = ""
BCircle 159, 99, RND * 129 + 75, RND * 255
ndx% = (RND * 400 + 5)
l1& = xy(ndx%)
x1% = l1& MOD 320
y1% = l1& \ 320
l2& = xy(ndx% + 3)
x2% = l2& MOD 320
y2% = l2& \ 320
BLine x1%, y1%, x2%, y2%, RND * 255
WEND: Vmode 3: WIDTH 80, 25: end
SUB BCircle (xc%, yc%, r%, c%)
'_|_|_| Bresenham Circle Drawing Algorithm
'_|_|_| Adapted from BRESNHAM.C in Bob Stout's SNIPPETS.
SHARED WIDE%, HIGH%
x% = 0: d% = 2 * (1 - r%): W% = 2 * WIDE% \ HIGH%
WHILE r% >= 0
PXL xc% + x%, yc% + r%, c%
PXL xc% + x%, yc% - r%, c%
PXL xc% - x%, yc% + r%, c%
PXL xc% - x%, yc% - r%, c%
IF (d% + r%) > 0 THEN r% = r% - 1: d% = d% - W% * r% - 1
IF x% > d% THEN x% = x% + 1: d% = d% + 2 * x% + 1
WEND
END SUB
SUB BLine (x%, y%, x2%, y2%, c%)
'_|_|_| Bresenham Line Drawing Algorithm
'_|_|_| Adapted from BRESNHAM.C in Bob Stout's SNIPPETS.
i% = 0: steep% = 0: e% = 0
IF (x2% - x%) > 0 THEN sx% = 1: ELSE sx% = -1
dx% = ABS(x2% - x%)
IF (y2% - y%) > 0 THEN sy% = 1: ELSE sy% = -1
dy% = ABS(y2% - y%)
IF (dy% > dx%) THEN
steep% = 1
SWAP x%, y%
SWAP dx%, dy%
SWAP sx%, sy%
END IF
e% = 2 * dy% - dx%
FOR i% = 0 TO dx% - 1
IF steep% = 1 THEN PXL y%, x%, c%: ELSE PXL x%, y%, c%
WHILE e% >= 0
y% = y% + sy%: e% = e% - 2 * dx%
WEND
x% = x% + sx%: e% = e% + 2 * dy%
NEXT
PXL x2%, y2%, c%
END SUB
SUB Vmode(a%)
dim m as string * 1: m = chr$(a% and 255)
! mov ah, &H00
! mov al, m
! int &H10
end sub
sub PXL (x%, y%, c%)
shared HIGH%, WIDE%
if (x% < 0) or (y% < 0) then exit sub
if (x% >= WIDE%) or (y% >= HIGH%) then exit sub
def seg = &Ha000: poke y% * WIDE% + x%, c%
end sub
'_|_|_| end BRESNHAM.BAS
___
> ] Once you know me better, you'll like me even less...........
--- Maximus/2 3.01
1:278/216)
---------------
* Origin: The Programmer's Mark * Brooklyn, NY, USA: 718-921-9267
|