Circle drawing for PowerBASIC
Author Message Circle drawing for PowerBASIC

\$if 0
powerbasic v3.50
DASoft
DATE: 1998-06-06
FILE NAME   CIRCLE  .BAS          by
Don Schullian, Jr.

Public Domain

This routine draws a circle or arc with or without a pie wedge. The
parameters are the same as the CIRCLE command with one exception:
Sdeg% and Edeg% are the starting and ending DEGREEs, not radians.
(I don't think in radians!) 0 degree is assumed to be at the top of
the circle and they proceed around the circle clockwise (to the right).
eg: 90 degrees is EAST, 180 is SOUTH and 270 is WEST.

The STEP value in the FOR/NEXT loop can be adjusted as required depending
on which screen you are using. I've found that values from -.005 to -0025
work with most VESA screens but #13 may not require such fine stepping.

Please, let me know if you experience any problems with this routine.

C'ya,

Don
\$endif

'......................................
'

PUBLIC pPi! :  pPi! = ( 4 * ATN(1) )

SCREEN 12

DELAY 1
LINE (320,0)-(320,479), 7
LINE (0,240)-(639,240), 7
DELAY 1

DrawCircle 320, 240, 140, 14,   0,   0, 1.51  ' complete circle
DrawCircle 320, 240, 205, 13,  81, 163, 1.00  ' small arc in lower R quad
DrawCircle 320, 240, 130, 12, 175, -40, 1.00  ' pie shape in upper L quad
DrawCircle 320, 240, 130, 11,  40, 175, 1.00  ' complete the arc above
DrawCircle 320, 240, 319, 10,   0,   0, 0.75  ' one BIG mama

WHILE NOT INSTAT : WEND

SCREEN 0
CLS
END
' -------------------------------------------------------------------------
' -------- see CIRCLE help for parameter details
' -------------------------------------------------------------------------
SUB DRAWcircle (BYVAL Xcen   AS INTEGER , _
BYVAL Ycen   AS INTEGER , _
BYVAL Radius AS INTEGER , _
BYVAL Colour AS INTEGER , _
BYVAL Sdeg   AS INTEGER , _
BYVAL Edeg   AS INTEGER , _
BYVAL Aspect AS SINGLE    ) LOCAL PUBLIC

DIM Erdn  AS LOCAL SINGLE
DIM Rdn   AS LOCAL SINGLE
DIM Srdn  AS LOCAL SINGLE
DIM Steep AS LOCAL SINGLE
DIM X1    AS LOCAL INTEGER
DIM Xo    AS LOCAL INTEGER
DIM Y1    AS LOCAL INTEGER
DIM Yo    AS LOCAL INTEGER

IF Aspect! < 0 THEN
ELSE
END IF
IF Erdn! => Srdn! THEN INCR Srdn!, 6.28

Xo% = -1
Yo% = -1

FOR Rdn! = Srdn! TO Erdn! STEP -.003
X1% = ( Xrad! * COS(Rdn!) )
Y1% = ( Yrad! * SIN(Rdn!) )
IF ( X1% <> Xo% )   OR _
( Y1% <> Yo% ) THEN
Xo% = X1%
Yo% = Y1%
X1% = Xcen% + X1%
Y1% = Ycen% - Y1%
PSET (X1%, Y1%), Colour%
END IF
NEXT

IF ( Sdeg% < 0 )   OR _
( Edeg% < 0 ) THEN
X1% = ( Xrad! * COS(Srdn!) )
Y1% = ( Yrad! * SIN(Srdn!) )
X1% = Xcen% + X1%
Y1% = Ycen% - Y1%
LINE ( Xcen%, Ycen% )-( X1%, Y1% ), Colour%

X1% = ( Xrad! * COS(Erdn!) )
Y1% = ( Yrad! * SIN(Erdn!) )
X1% = Xcen% + X1%
Y1% = Ycen% - Y1%
LINE ( Xcen%, Ycen% )-( X1%, Y1% ), Colour%
END IF

END SUB

' -------------------------------------------------------------------------

FUNCTION fDeg2Rad ( SEG Degree AS SINGLE ) LOCAL PUBLIC AS SINGLE

DIM F AS LOCAL SINGLE

IF Degree! > 89 THEN F! = 2.5 ELSE F! = 0.5
fDeg2Rad! = (F! * pPi!) - (( pPi! / 180 ) * Degree!) + 0.0001

END FUNCTION

____    _    ____      ____  _____
|  _ \  / \  / ___) __ | ___)(_   _)
| |_)  / _ \ \____\/  \|  _)   | |
|____//_/ \_\(____/\__/|_|     |_|

www.basicguru.com/schullian

Wed, 22 Nov 2000 03:00:00 GMT  Circle drawing for PowerBASIC

Quote:

>\$if 0
>                            PowerBASIC v3.50
>          DASoft
>                         DATE: 1998-06-06
>   FILE NAME   CIRCLE  .BAS          by
>                              Don Schullian, Jr.

>
>                                  Public Domain
>
>
>

>  This routine draws a circle or arc with or without a pie wedge. The
>  parameters are the same as the CIRCLE command with one exception:
>  Sdeg% and Edeg% are the starting and ending DEGREEs, not radians.
>  (I don't think in radians!) 0 degree is assumed to be at the top of
>  the circle and they proceed around the circle clockwise (to the right).
>  eg: 90 degrees is EAST, 180 is SOUTH and 270 is WEST.

>  The STEP value in the FOR/NEXT loop can be adjusted as required depending
>  on which screen you are using. I've found that values from -.005 to -0025
>  work with most VESA screens but #13 may not require such fine stepping.

>  Please, let me know if you experience any problems with this routine.

>  C'ya,

>  Don
>\$endif

>'......................................
>'

>PUBLIC pPi! :  pPi! = ( 4 * ATN(1) )

>SCREEN 12

>DELAY 1
>LINE (320,0)-(320,479), 7
>LINE (0,240)-(639,240), 7
>DELAY 1

>DrawCircle 320, 240, 140, 14,   0,   0, 1.51  ' complete circle
>DrawCircle 320, 240, 205, 13,  81, 163, 1.00  ' small arc in lower R quad
>DrawCircle 320, 240, 130, 12, 175, -40, 1.00  ' pie shape in upper L quad
>DrawCircle 320, 240, 130, 11,  40, 175, 1.00  ' complete the arc above
>DrawCircle 320, 240, 319, 10,   0,   0, 0.75  ' one BIG mama

>WHILE NOT INSTAT : WEND

>SCREEN 0
>CLS
>END
>' -------------------------------------------------------------------------
>' -------- see CIRCLE help for parameter details
>' -------------------------------------------------------------------------
>SUB DRAWcircle (BYVAL Xcen   AS INTEGER , _
>                BYVAL Ycen   AS INTEGER , _
>                BYVAL Radius AS INTEGER , _
>                BYVAL Colour AS INTEGER , _
>                BYVAL Sdeg   AS INTEGER , _
>                BYVAL Edeg   AS INTEGER , _
>                BYVAL Aspect AS SINGLE    ) LOCAL PUBLIC

>  DIM Erdn  AS LOCAL SINGLE
>  DIM Rdn   AS LOCAL SINGLE
>  DIM Srdn  AS LOCAL SINGLE
>  DIM Steep AS LOCAL SINGLE
>  DIM X1    AS LOCAL INTEGER
>  DIM Xrad  AS LOCAL SINGLE
>  DIM Xo    AS LOCAL INTEGER
>  DIM Y1    AS LOCAL INTEGER
>  DIM Yrad  AS LOCAL SINGLE
>  DIM Yo    AS LOCAL INTEGER

>  IF Aspect! < 0 THEN
>    ELSE
>  END IF
>  Srdn! = fDeg2Rad!( ABS(Sdeg%) )
>  Erdn! = fDeg2Rad!( ABS(Edeg%) )
>  IF Erdn! => Srdn! THEN INCR Srdn!, 6.28

>  Xo% = -1
>  Yo% = -1

>  FOR Rdn! = Srdn! TO Erdn! STEP -.003
>    X1% = ( Xrad! * COS(Rdn!) )
>    Y1% = ( Yrad! * SIN(Rdn!) )
>    IF ( X1% <> Xo% )   OR _
>       ( Y1% <> Yo% ) THEN
>      Xo% = X1%
>      Yo% = Y1%
>      X1% = Xcen% + X1%
>      Y1% = Ycen% - Y1%
>      PSET (X1%, Y1%), Colour%
>    END IF
>  NEXT

>  IF ( Sdeg% < 0 )   OR _
>     ( Edeg% < 0 ) THEN
>    X1% = ( Xrad! * COS(Srdn!) )
>    Y1% = ( Yrad! * SIN(Srdn!) )
>    X1% = Xcen% + X1%
>    Y1% = Ycen% - Y1%
>    LINE ( Xcen%, Ycen% )-( X1%, Y1% ), Colour%

>    X1% = ( Xrad! * COS(Erdn!) )
>    Y1% = ( Yrad! * SIN(Erdn!) )
>    X1% = Xcen% + X1%
>    Y1% = Ycen% - Y1%
>    LINE ( Xcen%, Ycen% )-( X1%, Y1% ), Colour%
>  END IF

>END SUB

>' -------------------------------------------------------------------------

>FUNCTION fDeg2Rad ( SEG Degree AS SINGLE ) LOCAL PUBLIC AS SINGLE

>  DIM F AS LOCAL SINGLE

>  IF Degree! > 89 THEN F! = 2.5 ELSE F! = 0.5
>  fDeg2Rad! = (F! * pPi!) - (( pPi! / 180 ) * Degree!) + 0.0001

>END FUNCTION

>  ____    _    ____      ____  _____
> |  _ \  / \  / ___) __ | ___)(_   _)
> | |_)  / _ \ \____\/  \|  _)   | |
> |____//_/ \_\(____/\__/|_|     |_|

>     www.basicguru.com/schullian

Hmmm, well I reached into the wayback machine, and found this. Does basically
the same thing in QB45.  If you run it, just press spacebar to stop displaying
the circle. It's not perfect, but was quick and dirty as a subroutine to
something else I was trying at the time.

'program: CIRCLE.BAS
'         JUST A LITTLE ROUTINE WHICH DEMONSTRATES
'         HOW TO DRAW  A CIRCLE ON SCREEN
'         USING ONLY PARTIAL CIRCLE AND ANGLE

SCREEN 9
RD = 57.29577951#
displayfactor = 4 / 5
circlecolor = 3

'just change the value that n loops, in deg, for diff. partial circles
'

FOR N = 0 TO 360 STEP .1
n2 = (360 - N) - 270
IF n2 < 0 THEN n2 = n2 + 360
n2 = n2 / RD:            'n2 is starting point of this step in deg
n3 = n2:                   'n3 is ending pt in deg, in this ex. same as n2
LOCATE 1, 1: PRINT N
CIRCLE (200, 200), 150, circlecolor, n2, n3, displayfactor
NEXT N

Wed, 22 Nov 2000 03:00:00 GMT

 Page 1 of 1 [ 2 post ]

Relevant Pages