'**
'** Maze Generator V1.0
'**
'** by Terry Ritchie - 02/06/13
'**
'** This code can generate random braided looping, non-looping or custom mazes by supplying a string of HEX characters.
'**
'** Mazes can be saved and loaded using the SAVEMAZE and LOADMAZE commands.
'**
'** An example of how to draw mazes is included as DRAWMAZE. The syntax for drawmaze is as follows:
'**
'** DRAWMAZE MazeType%, Thickness%, MazeColor~&
'**
'** - MazeType% : 0 (or constant SQUARE) for a square maze, 1 (or constant ROUND) for a round maze
'** - Thickness% : the wall thickness of the maze
'** - MazeColor~&: the color of the maze walls
'**
'** DRAWMAZE draws the maze image to the image handle MazeImage&
'**
'** To generate a random maze use the MAKEMAZE command as follows:
'**
'** +--------- R specifies a random maze
'** MAKEMAZE "RL0A0A15" |+-------- L specifies a looping maze (use N for non-looping maze)
'** +-------------------+ || +------ 0A the next two characters in HEX specifies the horizontal width of maze, in this case 10
'** | the command above | || |
'** | will produce a | vv v The largest HEX value that can be used is FF, or 255, therefore the maximum width and height
'** | random maze of 20 | RL0A0A15 of the maze can't exceed 255x255 and the maximum cell size can't exceed 255.
'** | cells wide by 20 | ^ ^
'** | cells high with | | |
'** | each cell being | | +-- 15 the last two characters in HEX specifies the size of each cell in maze, in this case 21
'** | 21 pixels in size | +---- 0A the next two characters in HEX specifies the vertical height of maze, in this case 10
'** +-------------------+
'**
'** To generate a maze of your own design use the MAKEMAZE command as follows:
'**
'** MAKEMAZE "050515<maze_string>"
'** +-------------------+ +------- 05 the first two HEX digits specifies the horizontal width of the maze, in this case 5
'** | the command above | | +----- 05 the second two HEX digits specifies the vertical height of the maze, in this case 5
'** | will produce a | | |
'** | custom maze of 5 | v v A sample maze string that creates a spiraling inward maze would be:
'** | cells wide by 5 | 050515<maze_string>
'** | cells high with | ^ ^ "0505152AAAC6AAC55685553A953AAA9"
'** | each cell being | | |
'** | 21 pixels in size | | +- <maze_string> is a string of HEX digits that describes the actual maze (see illustration below)
'** +-------------------+ +--- 15 the last two HEX digits specifies the size of each pixel in the maze, in this case 21
'**
'** NOTE: Round mazes will look best if you keep the size of the cells at ODD numbers. The included DRAWMAZE example
'** subroutine was optimized to make sure that round mazes have a definite center line inside the maze, because these maze
'** rotuines are a spinoff of a game in progress that needs random round maze generation with defined center lines.
'**
'** After you have created a maze with MAKEMAZE you can use the SAVEMAZE command to save the maze to a file. This will allow you to
'** use the generated mazes in your own programs. The SAVEMAZE command is used as follows:
'**
'** SAVEMAZE "mymaze"
'**
'** There is no need to supply an extension. ".MAZ" will automagically be added to the name you gave your maze.
'**
'** You can load a previously saved maze using LOADMAZE as follows:
'**
'** LOADMAZE "mymaze", mymaze$
'**
'** The maze will be loaded and placed into the variable specified, in this case mymaze$
'**
'*****************************************************************************************************************************************
'** *
'** The following is an illustration of the 16 cell conditions and their corresponding HEX values: *
'** *
'*****************************************************************************************************************************************
'** | | Cell 1 * | | Cell 2 * | | Cell 3 * | | Cell 4 *
'** --| |-- North door open * --+-------- East door open * --| +-- North door open * --+-----+-- South door open *
'** | | * | * | East door open * | | *
'** | | * | * | * | | *
'** --+-----+-- * --+-------- * --+-------- * --| |-- *
'** | | HEX - 1 * | | HEX - 2 * | | HEX - 3 * | | HEX - 4 *
'*****************************************************************************************************************************************
'** | | Cell 5 * | | Cell 6 * | | Cell 7 * | | Cell 8 *
'** --| |-- North door open * --+-------- East door open * --| +-- North door open * --------+-- West door open *
'** | | South door open * | South door open * | South door open * | *
'** | | * | * | East door open * | *
'** --| |-- * --| +-- * --| +-- * --------+-- *
'** | | HEX - 5 * | | HEX - 6 * | | HEX - 7 * | | HEX - 8 *
'*****************************************************************************************************************************************
'** | | Cell 9 * | | Cell 10 * | | Cell 11 * | | Cell 12 *
'** --+ |-- North door open * ----------- East door open * --+ +-- North door open * --+-----+-- South door open *
'** | West door open * West door open * East door open * | West door open *
'** | * * West door open * | *
'** --------+-- * ----------- * ----------- * --+ +-- *
'** | | HEX - 9 * | | HEX - A * | | HEX - B * | | HEX - C *
'*****************************************************************************************************************************************
'** | | Cell 13 * | | Cell 14 * | | Cell 15 * \ | | / Cell 0 *
'** --+ |-- North door open * ----------- East door open * --+ +-- North door open * --+-----+-- No doors open *
'** | South door open * South door open * East door open * | \ / | (nothing will be *
'** | West door open * West door open * South door open * | / \ | drawn to the *
'** --+ |-- * --+ +-- * --+ +-- West door open * --+-----+-- maze image) *
'** | | HEX - D * | | HEX - E * | | HEX - F * / | | \ HEX - 0 *
'*****************************************************************************************************************************************
'** *
'** Each open door is treated as a digit in a binary nibble: North = 2^0 East = 2^1 South = 2^2 West = 2^3 *
'** *
'** Therefore, one hexadecimal digit can store the state of all four doors of a cell. i.e. F = 2^0+2^1+2^2+2^3 = 15 = all doors open. *
'** *
'*****************************************************************************************************************************************
CONST FALSE
= 0, TRUE
= NOT FALSE
' boolean truth testers CONST PI
= 3.1415926 ' would you like a piece? CONST PIUP
= 1.5707963 ' radian pointing up CONST PIDOWN
= 4.7123889 ' radian pointing down
Xpos
AS INTEGER ' the X screen coordinate of this cell Ypos
AS INTEGER ' the Y screen coordinate of this cell Doors
AS INTEGER ' the doors that are open in this cell (1-up, 2-right, 4-down, 8-left)
Hor
AS INTEGER ' horizontal X position of this cell Ver
AS INTEGER ' vertical Y position of this cell
Xpos
AS INTEGER ' horizontal X position of cell in stack Ypos
AS INTEGER ' vertical Y position of cell in stack
Hcell
AS INTEGER ' number of horizontal cells in maze Vcell
AS INTEGER ' number of vertical cells in maze CellSize
AS INTEGER ' the size of each maze cell Thickness
AS INTEGER ' the wall thickness of the maze MazeType
AS INTEGER ' the type of maze (0-square, 1-round) Looping
AS INTEGER ' 0 for non looping, 1 for looping
REDIM Cell
(0, 0) AS CELL
' an array of maze cells DIM Maze
AS MAZE
' the maze properties DIM MazeImage&
' the maze image holder
MAKEMAZE "0505152AAAC6AAC55685553A953AAA9" ' create a custom maze
DRAWMAZE ROUND
, 6, _RGB32(64, 64, 64) ' draw the custom round maze to the screenSAVEMAZE "mymaze" ' save the maze as MYMAZE.MAZ
_PUTIMAGE (0, 0), MazeImage&
' this puts maze on screen in real size SLEEP ' wait for a key press MAKEMAZE "RL141429" ' create a 20 x 20 random looping maze with a cell size of 41 pixels
DRAWMAZE SQUARE
, 6, _RGB32(64, 64, 64) ' draw the random square maze to the screen_PUTIMAGE (0, 0), MazeImage&
' this puts maze on screen in real size LOCATE 2, 2:
PRINT " A random 20x20 square looping maze with 41 pixel sized cells (too big for screen)" SLEEP ' wait for a keypress MAKEMAZE "RN0A0A1F" ' create a 10 x 10 random non-looping maze with a cell size of 31 pixels
DRAWMAZE ROUND
, 6, _RGB32(64, 64, 64) ' draw the random round maze to the screen_PUTIMAGE (0, 0), MazeImage&
' this puts maze on screen in real size LOCATE 2, 2:
PRINT " A random 10x10 round non-looping maze with 31 pixel sized cells" SLEEP ' wait for a keypress LOADMAZE "mymaze", MyMaze$ ' load previously saved maze and place maze in MyMaze$
MAKEMAZE MyMaze$ ' create the loaded maze
DRAWMAZE SQUARE
, 6, _RGB32(64, 64, 64) ' draw the loaded maze, this time in square style_PUTIMAGE (0, 0), MazeImage&
' this puts maze on screen in real size LOCATE 2, 2:
PRINT " The first maze loaded from HDD and now displayed as a square maze" SLEEP ' wait for a keypress
'** NOTE: _PUTIMAGE , MazeImage& ' this will always squeeze maze onto screen
'----------------------------------------------------------------------------------------------------------------------
SUB LOADMAZE
(MazeFile$
, MazeString$
)
'**
'** Loads a maze from HDD
'**
OPEN MazeFile$
+ ".MAZ" FOR INPUT AS #1 ' open the maze file for input LINE INPUT #1, MazeString$
' get the maze string from the file CLOSE #1 ' close the file
'----------------------------------------------------------------------------------------------------------------------
'**
'** Saves a maze to HDD
'**
SHARED Cell
() AS CELL
' we need access to the cell array SHARED Maze
AS MAZE
' we need access to the maze properties
DIM v%
, h%
' generic counters to keep track of current cell DIM MazeString$
' the string generated that represents the maze
'**
'** save the number of horizontal cells, vertical cells and cell size to the maze string
'** make sure that each HEX value saved is at least two digits in length by padding a zero at the
'** beginning of each HEX value
'**
FOR v%
= 1 TO Maze.Vcell
' cycle through all vertical cells FOR h%
= 1 TO Maze.Hcell
' cycle through all horizontal cells MazeString$
= MazeString$
+ HEX$(Cell
(h%
, v%
).Doors
) ' save this cell's door conditions to maze stringPRINT #1, MazeString$
' write the maze string to the file CLOSE #1 ' close the maze file
'----------------------------------------------------------------------------------------------------------------------
SUB DRAWMAZE
(Mtype%
, Thick%
, Mcolor~&
)
'**
'** Draws the maze to the maze image holder
'**
'** This command is included as an example of how you can draw custom or random mazes for use in your own programs.
'** See the DRAWCELL subroutine for the complete picture.
'**
SHARED Cell
() AS CELL
' we need access to the cell array SHARED MazeImage&
' we need access to the maze image holder SHARED Maze
AS MAZE
' we need access to the maze properties
DIM OriginalDest&
' the saved destination of the calling routine DIM v%
, h%
' current horizontal and vertical cell being drawn
Maze.Thickness = Thick% ' wall thickness of maze
Maze.Colour = Mcolor~& ' maze wall color
Maze.MazeType = Mtype% ' type of maze
IF MazeImage&
THEN _FREEIMAGE MazeImage&
' free previous maze image created if one exists MazeImage&
= _NEWIMAGE(Maze.CellSize
* (Maze.Hcell
+ 1.5) * 2, Maze.CellSize
* (Maze.Vcell
+ 1.5) * 2, 32) ' calculate maze image sizeOriginalDest&
= _DEST ' save calling routine destination_DEST MazeImage&
' maze image is new destination FOR v%
= 1 TO Maze.Vcell
' cycle through all cell vertical locations FOR h%
= 1 TO Maze.Hcell
' cycle through all cell horizontal locations DRAWCELL Cell(h%, v%).Xpos, Cell(h%, v%).Ypos, Cell(h%, v%).Doors ' draw the cell at this location
_DEST OriginalDest&
' restore calling routine destination
'----------------------------------------------------------------------------------------------------------------------
'**
'** Creates a random braided optional-looping maze
'**
SHARED Cell
() AS CELL
' we need access to the cell array SHARED Maze
AS MAZE
' we need access to the maze properties
DIM CurrentCell
AS STACK
' the current cell we are working with DIM Pointer%
' the stack pointer DIM ValidCells%
' contains the valid adjacent cells we can move to DIM RandomDir%
' a random direction to move DIM Forward%
' TRUE if we are moving forward through the maze DIM CellX%
' generic counter used to initiate cells DIM CellY%
' generic counter used to initiate cells DIM VisitedCells%
' number of cells visited by subroutine DIM Remove%
' TRUE if it's ok to open a looping door DIM Mz$
' the string holding the maze DIM Custom%
' -1 (TRUE) if custom maze, 0 (FALSE) if random DIM Mzpointer%
' maze string position pointer
Mz$
= UCASE$(Maze$
) ' convert passed maze string to uppercaseMzpointer% = 0 ' reset maze string position pointer
Custom% = -1 ' assume this will be a custom maze
IF LEFT$(Mz$
, 1) = "R" THEN ' should we create a random maze? Custom% = 0 ' yes, remove custom flag
IF MID$(Mz$
, 2, 1) = "L" THEN ' should this be a looping maze? Maze.Looping = 1 ' yes, make it so number one
Maze.Looping = 0 ' this will not be a looping maze
Mz$
= RIGHT$(Mz$
, LEN(Mz$
) - 2) ' remove the first two characters from maze stringMaze.Hcell
= VAL("&H" + LEFT$(Mz$
, 2)) ' set the number of horizontal cells in mazeMaze.Vcell
= VAL("&H" + MID$(Mz$
, 3, 2)) ' set the number of vertical cells in mazeMaze.CellSize
= VAL("&H" + MID$(Mz$
, 5, 2)) ' set the size of each cellREDIM Cell
(Maze.Hcell
, Maze.Vcell
) AS CELL
' create an array of maze cells IF Custom%
THEN ' are we creating a custom maze? Mz$
= RIGHT$(Mz$
, LEN(Mz$
) - 6) ' yes, remove first six characters from maze stringELSE ' no, we are creating a random maze DIM Stack
(Maze.Hcell
* Maze.Vcell
) AS STACK
' create a LIFO stack array FOR CellY%
= 1 TO Maze.Hcell
' cycle through all vertical cells FOR CellX%
= 1 TO Maze.Vcell
' cycle through all horizontal cells Mzpointer% = Mzpointer% + 1 ' increment the maze string position pointer
Cell(CellX%, CellY%).Xpos = CellX% * Maze.CellSize * 2 ' upper left X location of this cell
Cell(CellX%, CellY%).Ypos = CellY% * Maze.CellSize * 2 ' upper left Y location of this cell
IF Custom%
THEN ' is this a custom maze? Cell
(CellX%
, CellY%
).Doors
= VAL("&H" + MID$(Mz$
, Mzpointer%
, 1)) 'yes, get this cell's door conditions from maze string ELSE ' no, this will be a random maze Cell(CellX%, CellY%).Doors = 0 ' set all cell doors closed
IF Custom%
THEN EXIT SUB ' no need to go further if this is a custom maze '**
'** Start of random maze generation algorithm *********************************
'**
CurrentCell.Xpos
= INT(RND(1) * Maze.Hcell
) + 1 ' random horizontal position of cell to start atCurrentCell.Ypos
= INT(RND(1) * Maze.Vcell
) + 1 ' random vertical position of cell to start atVisitedCells% = 1 ' keep track of how many cells visited
Pointer% = 0 ' initiate the stack pointer
Forward% = 0 ' not moving forward through maze yet
WHILE VisitedCells%
< Maze.Hcell
* Maze.Vcell
' make sure we visit all cells ValidCells% = 0 ' initiate number of valid neighbor cells
IF CurrentCell.Ypos
<> 1 THEN ' are we at top of maze? IF Cell
(CurrentCell.Xpos
, CurrentCell.Ypos
- 1).Doors
= 0 THEN ' no, does cell above have all doors closed? ValidCells% = ValidCells% + 1 ' yes, remember this cell
IF CurrentCell.Xpos
<> Maze.Hcell
THEN ' are we at right side of maze? IF Cell
(CurrentCell.Xpos
+ 1, CurrentCell.Ypos
).Doors
= 0 THEN ' no, does cell to right have all doors closed? ValidCells% = ValidCells% + 2 ' yes, remember this cell
IF CurrentCell.Ypos
<> Maze.Vcell
THEN ' are we at bottom of maze? IF Cell
(CurrentCell.Xpos
, CurrentCell.Ypos
+ 1).Doors
= 0 THEN ' no, does cell below have all doors closed? ValidCells% = ValidCells% + 4 ' yes, remember this cell
IF CurrentCell.Xpos
<> 1 THEN ' are we at left side of maze? IF Cell
(CurrentCell.Xpos
- 1, CurrentCell.Ypos
).Doors
= 0 THEN ' no, does cell to left have all doors closed? ValidCells% = ValidCells% + 8 ' yes, remember this cell
IF ValidCells%
<> 0 THEN ' did at least one cell have all doors closed? DO ' yes, one or more of the cells have all doors closed RandomDir%
= INT(RND(1) * 4) ' choose a random cell direction LOOP UNTIL ValidCells%
AND 2 ^ RandomDir%
' continue if this is a valid move Stack(Pointer%) = CurrentCell ' push our current location into the LIFO stack
Pointer% = Pointer% + 1 ' increment the stack pointer
VisitedCells% = VisitedCells% + 1 ' increment the number of cells visited so far
Forward% = -1 ' we are moving forward in the maze
OPENDOORS CurrentCell.Xpos, CurrentCell.Ypos, RandomDir% ' open current and adjacent cell doors
SELECT CASE RandomDir%
' which direction did we move forward? CurrentCell.Ypos = CurrentCell.Ypos - 1 ' make this the new current cell
CurrentCell.Xpos = CurrentCell.Xpos + 1 ' make this the new current cell
CurrentCell.Ypos = CurrentCell.Ypos + 1 ' make this the new current cell
CurrentCell.Xpos = CurrentCell.Xpos - 1 ' make this the new current cell
ELSE ' no, all adjacent cells had at least one door open IF Forward%
THEN ' were we previously moving forward in the maze? Forward% = 0 ' yes, we are not any longer
IF Maze.Looping
= 1 THEN ' should this be a looping maze? 'IF INT(RND(1) * 2) = 1 THEN ' yes, flip a coin to see if a loop structure built here
Remove% = 0 ' assume no doors will be opened
SELECT CASE RandomDir%
' which direction were we traveling in? IF CurrentCell.Ypos
<> 1 THEN Remove%
= -1 ' if not at top of maze upper door can be opened IF CurrentCell.Xpos
<> Maze.Hcell
THEN Remove%
= -1 ' if not at right side of maze right door can be opened IF CurrentCell.Ypos
<> Maze.Vcell
THEN Remove%
= -1 ' if not at bottom of maze bottom door can be opened IF CurrentCell.Xpos
<> 1 THEN Remove%
= -1 ' if not at left side of maze left door can be opened IF Remove%
THEN ' is it ok to open a door? OPENDOORS CurrentCell.Xpos, CurrentCell.Ypos, RandomDir% ' yes, open current and adjacent cell doors
'END IF
Pointer% = Pointer% - 1 ' decrement the stack pointer
CurrentCell = Stack(Pointer%) ' pop the previous cell position from the LIFO stack
REDIM Stack
(0) AS STACK
' clear the memory used by the stack
'----------------------------------------------------------------------------------------------------------------------
SUB OPENDOORS
(x%
, y%
, Direction%
)
'**
'** Opens a door in the current cell and the corresponding door in the adjacent cell
'**
SHARED Cell
() AS CELL
' we need access to the cell array
SELECT CASE Direction%
' which direction are we going? Cell(x%, y%).Doors = Cell(x%, y%).Doors + 1 ' open the current cell's up door
Cell(x%, y% - 1).Doors = Cell(x%, y% - 1).Doors + 4 ' open the adjacent cell's south door
Cell(x%, y%).Doors = Cell(x%, y%).Doors + 2 ' open the current cell's right door
Cell(x% + 1, y%).Doors = Cell(x% + 1, y%).Doors + 8 ' open the adjacent cell's left door
Cell(x%, y%).Doors = Cell(x%, y%).Doors + 4 ' open the current cell's down door
Cell(x%, y% + 1).Doors = Cell(x%, y% + 1).Doors + 1 ' open the adjacent cell's up door
Cell(x%, y%).Doors = Cell(x%, y%).Doors + 8 ' open this cell's left door
Cell(x% - 1, y%).Doors = Cell(x% - 1, y%).Doors + 2 ' open the adjacent cell's right door
'----------------------------------------------------------------------------------------------------------------------
SUB DRAWCELL
(x%
, y%
, n%
)
'**
'** Draws a maze cell
'**
'** The drawing routines below can produce either a square maze (0) or a round maze (1) as defined by Maze.MazeType
'** These drawing routines are included to act as an example of how you can create custom maze drawing routines for
'** the mazes you generate and use in your programs.
'**
SHARED Maze
AS MAZE
' we need access to the maze properties
DIM xc%
' center X coordinate of cell DIM yc%
' center Y coordiante of cell DIM Radius!
' radius of various maze corners
xc% = x% + Maze.CellSize \ 2 ' calculate center X coordinate of cell
yc% = y% + Maze.CellSize \ 2 ' calculate center Y coordinate of cell
FOR Radius!
= 1 TO Maze.Thickness
- .5 STEP .5 CIRCLES x% - 1, y% + Maze.CellSize, Radius!, Maze.Colour, PI, PIDOWN, 0
CIRCLES x% + Maze.CellSize, y% + Maze.CellSize, Radius!, Maze.Colour, PIDOWN, 0, 0
LINE (x%
- 1, y%
+ Maze.CellSize
)-(x%
- Maze.Thickness
, yc%
- Maze.CellSize
), Maze.Colour
, BF
LINE (x%
+ Maze.CellSize
, y%
+ Maze.CellSize
)-(x%
+ Maze.CellSize
+ Maze.Thickness
- 1, yc%
- Maze.CellSize
), Maze.Colour
, BF
LINE (x%
- 1, y%
+ Maze.CellSize
)-(x%
+ Maze.CellSize
, y%
+ Maze.CellSize
+ Maze.Thickness
- 1), Maze.Colour
, BF
FOR Radius!
= Maze.CellSize
/ 2 + 1 TO Maze.CellSize
/ 2 + Maze.Thickness
STEP .5 CIRCLES xc%, yc%, Radius!, Maze.Colour, PI, 0, 0
LINE (x%
- 1, yc%
)-(x%
- Maze.Thickness
, yc%
- Maze.CellSize
), Maze.Colour
, BF
LINE (x%
+ Maze.CellSize
, yc%
)-(x%
+ Maze.CellSize
+ Maze.Thickness
- 1, yc%
- Maze.CellSize
), Maze.Colour
, BF
CASE 2 ' ** right door open FOR Radius!
= 1 TO Maze.Thickness
- .5 STEP .5 CIRCLES x% - 1, y% - 1, Radius!, Maze.Colour, PIUP, PI, 0
CIRCLES x% - 1, y% + Maze.CellSize, Radius!, Maze.Colour, PI, PIDOWN, 0
LINE (x%
- 1, y%
- 1)-(xc%
+ Maze.CellSize
, y%
- Maze.Thickness
), Maze.Colour
, BF
LINE (x%
- 1, y%
+ Maze.CellSize
)-(xc%
+ Maze.CellSize
, y%
+ Maze.CellSize
+ Maze.Thickness
- 1), Maze.Colour
, BF
LINE (x%
- 1, y%
- 1)-(x%
- Maze.Thickness
, y%
+ Maze.CellSize
), Maze.Colour
, BF
FOR Radius!
= Maze.CellSize
/ 2 + 1 TO Maze.CellSize
/ 2 + Maze.Thickness
STEP .5 CIRCLES xc%, yc%, Radius!, Maze.Colour, PIUP, PIDOWN, 0
LINE (xc%
, y%
- 1)-(xc%
+ Maze.CellSize
, y%
- Maze.Thickness
), Maze.Colour
, BF
LINE (xc%
, y%
+ Maze.CellSize
)-(xc%
+ Maze.CellSize
, y%
+ Maze.CellSize
+ Maze.Thickness
- 1), Maze.Colour
, BF
CASE 3 ' ** up and right doors open FOR Radius!
= 1 TO Maze.Thickness
- .5 STEP .5 CIRCLES x% + Maze.CellSize + Maze.Thickness - 1, y% - Maze.Thickness, Radius!, Maze.Colour, PI, PIDOWN, 0
CIRCLES x% - 1, y% + Maze.CellSize, Radius!, Maze.Colour, PI, PIDOWN, 0
LINE (x%
- 1, y%
+ Maze.CellSize
)-(x%
- Maze.Thickness
, yc%
- Maze.CellSize
), Maze.Colour
, BF
LINE (x%
- 1, y%
+ Maze.CellSize
)-(xc%
+ Maze.CellSize
, y%
+ Maze.CellSize
+ Maze.Thickness
- 1), Maze.Colour
, BF
LINE (x%
+ Maze.CellSize
, yc%
- Maze.CellSize
)-(x%
+ Maze.CellSize
+ Maze.Thickness
- 1, y%
- Maze.Thickness
), Maze.Colour
, BF
LINE (x%
+ Maze.CellSize
+ Maze.Thickness
- 1, y%
- 1)-(xc%
+ Maze.CellSize
, y%
- Maze.Thickness
), Maze.Colour
, BF
FOR Radius!
= Maze.CellSize
/ 2 - Maze.Thickness
TO Maze.CellSize
/ 2 STEP .5 CIRCLES xc% + Maze.CellSize, yc% - Maze.CellSize, Radius!, Maze.Colour, PI, PIDOWN, 0
FOR Radius!
= Maze.CellSize
* 1.5 + Maze.Thickness
TO Maze.CellSize
* 1.5 + 1 STEP -.5 CIRCLES xc% + Maze.CellSize, yc% - Maze.CellSize, Radius!, Maze.Colour, PI, PIDOWN, 0
CASE 4 ' ** down door open FOR Radius!
= 1 TO Maze.Thickness
- .5 STEP .5 CIRCLES x% - 1, y% - 1, Radius!, Maze.Colour, PIUP, PI, 0
CIRCLES x% + Maze.CellSize, y% - 1, Radius!, Maze.Colour, 0, PIUP, 0
LINE (x%
- 1, y%
- 1)-(x%
- Maze.Thickness
, yc%
+ Maze.CellSize
), Maze.Colour
, BF
LINE (x%
+ Maze.CellSize
, y%
- 1)-(x%
+ Maze.CellSize
+ Maze.Thickness
- 1, yc%
+ Maze.CellSize
), Maze.Colour
, BF
LINE (x%
- 1, y%
- 1)-(x%
+ Maze.CellSize
, y%
- Maze.Thickness
), Maze.Colour
, BF
FOR Radius!
= Maze.CellSize
/ 2 + 1 TO Maze.CellSize
/ 2 + Maze.Thickness
STEP .5 CIRCLES xc%, yc%, Radius!, Maze.Colour, 0, PI, 0
LINE (x%
- 1, yc%
)-(x%
- Maze.Thickness
, yc%
+ Maze.CellSize
), Maze.Colour
, BF
LINE (x%
+ Maze.CellSize
, yc%
)-(x%
+ Maze.CellSize
+ Maze.Thickness
- 1, yc%
+ Maze.CellSize
), Maze.Colour
, BF
CASE 5 ' ** up and down doors open LINE (x%
- 1, yc%
- Maze.CellSize
)-(x%
- Maze.Thickness
, yc%
+ Maze.CellSize
), Maze.Colour
, BF
LINE (x%
+ Maze.CellSize
, yc%
- Maze.CellSize
)-(x%
+ Maze.CellSize
+ Maze.Thickness
- 1, yc%
+ Maze.CellSize
), Maze.Colour
, BF
CASE 6 ' ** down and right doors open FOR Radius!
= 1 TO Maze.Thickness
- .5 STEP .5 CIRCLES x% - 1, y% - 1, Radius!, Maze.Colour, PIUP, PI, 0
CIRCLES x% + Maze.CellSize + Maze.Thickness - 1, y% + Maze.CellSize + Maze.Thickness - 1, Radius!, Maze.Colour, PIUP, PI, 0
LINE (x%
- 1, y%
- 1)-(x%
- Maze.Thickness
, yc%
+ Maze.CellSize
), Maze.Colour
, BF
LINE (x%
- 1, y%
- 1)-(xc%
+ Maze.CellSize
, y%
- Maze.Thickness
), Maze.Colour
, BF
LINE (x%
+ Maze.CellSize
+ Maze.Thickness
- 1, y%
+ Maze.CellSize
)-(xc%
+ Maze.CellSize
, y%
+ Maze.CellSize
+ Maze.Thickness
- 1), Maze.Colour
, BF
LINE (x%
+ Maze.CellSize
, y%
+ Maze.CellSize
+ Maze.Thickness
- 1)-(x%
+ Maze.CellSize
+ Maze.Thickness
- 1, yc%
+ Maze.CellSize
), Maze.Colour
, BF
FOR Radius!
= Maze.CellSize
/ 2 - Maze.Thickness
TO Maze.CellSize
/ 2 STEP .5 CIRCLES xc% + Maze.CellSize, yc% + Maze.CellSize, Radius!, Maze.Colour, PIUP, PI, 0
FOR Radius!
= Maze.CellSize
* 1.5 + Maze.Thickness
TO Maze.CellSize
* 1.5 + 1 STEP -.5 CIRCLES xc% + Maze.CellSize, yc% + Maze.CellSize, Radius!, Maze.Colour, PIUP, PI, 0
CASE 7 ' ** up and down and right doors open FOR Radius!
= 1 TO Maze.Thickness
- .5 STEP .5 CIRCLES x% + Maze.CellSize + Maze.Thickness - 1, y% - Maze.Thickness, Radius!, Maze.Colour, PI, PIDOWN, 0
CIRCLES x% + Maze.CellSize + Maze.Thickness - 1, y% + Maze.CellSize + Maze.Thickness - 1, Radius!, Maze.Colour, PIUP, PI, 0
LINE (x%
- 1, yc%
- Maze.CellSize
)-(x%
- Maze.Thickness
, yc%
+ Maze.CellSize
), Maze.Colour
, BF
LINE (x%
+ Maze.CellSize
+ Maze.Thickness
- 1, y%
+ Maze.CellSize
)-(xc%
+ Maze.CellSize
, y%
+ Maze.CellSize
+ Maze.Thickness
- 1), Maze.Colour
, BF
LINE (x%
+ Maze.CellSize
, y%
+ Maze.CellSize
+ Maze.Thickness
- 1)-(x%
+ Maze.CellSize
+ Maze.Thickness
- 1, yc%
+ Maze.CellSize
), Maze.Colour
, BF
LINE (x%
+ Maze.CellSize
, yc%
- Maze.CellSize
)-(x%
+ Maze.CellSize
+ Maze.Thickness
- 1, y%
- Maze.Thickness
), Maze.Colour
, BF
LINE (xc%
+ Maze.CellSize
, y%
- 1)-(x%
+ Maze.CellSize
+ Maze.Thickness
- 1, y%
- Maze.Thickness
), Maze.Colour
, BF
FOR Radius!
= Maze.CellSize
/ 2 - Maze.Thickness
TO Maze.CellSize
/ 2 STEP .5 CIRCLES xc% + Maze.CellSize, yc% - Maze.CellSize, Radius!, Maze.Colour, PI, PIDOWN, 0
CIRCLES xc% + Maze.CellSize, yc% + Maze.CellSize, Radius!, Maze.Colour, PIUP, PI, 0
LINE (x%
- 1, yc%
- Maze.CellSize
)-(x%
- Maze.Thickness
, yc%
+ Maze.CellSize
), Maze.Colour
, BF
CASE 8 ' ** left door open FOR Radius!
= 1 TO Maze.Thickness
- .5 STEP .5 CIRCLES x% + Maze.CellSize, y% - 1, Radius!, Maze.Colour, 0, PIUP, 0
CIRCLES x% + Maze.CellSize, y% + Maze.CellSize, Radius!, Maze.Colour, PIDOWN, 0, 0
LINE (xc%
- Maze.CellSize
, y%
- 1)-(x%
+ Maze.CellSize
, y%
- Maze.Thickness
), Maze.Colour
, BF
LINE (xc%
- Maze.CellSize
, y%
+ Maze.CellSize
)-(x%
+ Maze.CellSize
, y%
+ Maze.CellSize
+ Maze.Thickness
- 1), Maze.Colour
, BF
LINE (x%
+ Maze.CellSize
, y%
- 1)-(x%
+ Maze.CellSize
+ Maze.Thickness
- 1, y%
+ Maze.CellSize
), Maze.Colour
, BF
FOR Radius!
= Maze.CellSize
/ 2 + 1 TO Maze.CellSize
/ 2 + Maze.Thickness
STEP .5 CIRCLES xc%, yc%, Radius!, Maze.Colour, PIDOWN, PIUP, 0
LINE (xc%
- Maze.CellSize
, y%
- 1)-(xc%
, y%
- Maze.Thickness
), Maze.Colour
, BF
LINE (xc%
- Maze.CellSize
, y%
+ Maze.CellSize
)-(xc%
, y%
+ Maze.CellSize
+ Maze.Thickness
- 1), Maze.Colour
, BF
CASE 9 ' ** up and left doors open FOR Radius!
= 1 TO Maze.Thickness
- .5 STEP .5 CIRCLES x% - Maze.Thickness, y% - Maze.Thickness, Radius!, Maze.Colour, PIDOWN, 0, 0
CIRCLES x% + Maze.CellSize, y% + Maze.CellSize, Radius!, Maze.Colour, PIDOWN, 0, 0
LINE (xc%
- Maze.CellSize
, y%
+ Maze.CellSize
)-(x%
+ Maze.CellSize
, y%
+ Maze.CellSize
+ Maze.Thickness
- 1), Maze.Colour
, BF
LINE (x%
+ Maze.CellSize
, yc%
- Maze.CellSize
)-(x%
+ Maze.CellSize
+ Maze.Thickness
- 1, y%
+ Maze.CellSize
), Maze.Colour
, BF
LINE (xc%
- Maze.CellSize
, y%
- 1)-(x%
- Maze.Thickness
, y%
- Maze.Thickness
), Maze.Colour
, BF
LINE (x%
- 1, yc%
- Maze.CellSize
)-(x%
- Maze.Thickness
, y%
- Maze.Thickness
), Maze.Colour
, BF
FOR Radius!
= Maze.CellSize
/ 2 - Maze.Thickness
TO Maze.CellSize
/ 2 STEP .5 CIRCLES xc% - Maze.CellSize, yc% - Maze.CellSize, Radius!, Maze.Colour, PIDOWN, 0, 0
FOR Radius!
= Maze.CellSize
* 1.5 + Maze.Thickness
TO Maze.CellSize
* 1.5 + 1 STEP -.5 CIRCLES xc% - Maze.CellSize, yc% - Maze.CellSize, Radius!, Maze.Colour, PIDOWN, 0, 0
CASE 10 ' ** left and right doors open LINE (xc%
- Maze.CellSize
, y%
- 1)-(xc%
+ Maze.CellSize
, y%
- Maze.Thickness
), Maze.Colour
, BF
LINE (xc%
- Maze.CellSize
, y%
+ Maze.CellSize
)-(xc%
+ Maze.CellSize
, y%
+ Maze.CellSize
+ Maze.Thickness
- 1), Maze.Colour
, BF
CASE 11 ' ** up and left and right doors open FOR Radius!
= 1 TO Maze.Thickness
- .5 STEP .5 CIRCLES x% - Maze.Thickness, y% - Maze.Thickness, Radius!, Maze.Colour, PIDOWN, 0, 0
CIRCLES x% + Maze.CellSize + Maze.Thickness - 1, y% - Maze.Thickness, Radius!, Maze.Colour, PI, PIDOWN, 0
LINE (xc%
- Maze.CellSize
, y%
+ Maze.CellSize
)-(xc%
+ Maze.CellSize
, y%
+ Maze.CellSize
+ Maze.Thickness
- 1), Maze.Colour
, BF
LINE (xc%
- Maze.CellSize
, y%
- 1)-(x%
- Maze.Thickness
, y%
- Maze.Thickness
), Maze.Colour
, BF
LINE (x%
- 1, yc%
- Maze.CellSize
)-(x%
- Maze.Thickness
, y%
- Maze.Thickness
), Maze.Colour
, BF
LINE (x%
+ Maze.CellSize
, yc%
- Maze.CellSize
)-(x%
+ Maze.CellSize
+ Maze.Thickness
- 1, y%
- Maze.Thickness
), Maze.Colour
, BF
LINE (xc%
+ Maze.CellSize
, y%
- 1)-(x%
+ Maze.CellSize
+ Maze.Thickness
- 1, y%
- Maze.Thickness
), Maze.Colour
, BF
FOR Radius!
= Maze.CellSize
/ 2 - Maze.Thickness
TO Maze.CellSize
/ 2 STEP .5 CIRCLES xc% - Maze.CellSize, yc% - Maze.CellSize, Radius!, Maze.Colour, PIDOWN, 0, 0
CIRCLES xc% + Maze.CellSize, yc% - Maze.CellSize, Radius!, Maze.Colour, PI, PIDOWN, 0
LINE (xc%
- Maze.CellSize
, y%
+ Maze.CellSize
)-(xc%
+ Maze.CellSize
, y%
+ Maze.CellSize
+ Maze.Thickness
- 1), Maze.Colour
, BF
CASE 12 ' ** down and left doors open FOR Radius!
= 1 TO Maze.Thickness
- .5 STEP .5 CIRCLES x% + Maze.CellSize, y% - 1, Radius!, Maze.Colour, 0, PIUP, 0
CIRCLES x% - Maze.Thickness, y% + Maze.CellSize + Maze.Thickness - 1, Radius!, Maze.Colour, 0, PIUP, 0
LINE (xc%
- Maze.CellSize
, y%
- 1)-(x%
+ Maze.CellSize
, y%
- Maze.Thickness
), Maze.Colour
, BF
LINE (x%
+ Maze.CellSize
, y%
- 1)-(x%
+ Maze.CellSize
+ Maze.Thickness
- 1, yc%
+ Maze.CellSize
), Maze.Colour
, BF
LINE (xc%
- Maze.CellSize
, y%
+ Maze.CellSize
)-(x%
- Maze.Thickness
, y%
+ Maze.CellSize
+ Maze.Thickness
- 1), Maze.Colour
, BF
LINE (x%
- 1, yc%
+ Maze.CellSize
)-(x%
- Maze.Thickness
, y%
+ Maze.CellSize
+ Maze.Thickness
- 1), Maze.Colour
, BF
FOR Radius!
= Maze.CellSize
/ 2 - Maze.Thickness
TO Maze.CellSize
/ 2 STEP .5 CIRCLES xc% - Maze.CellSize, yc% + Maze.CellSize, Radius!, Maze.Colour, 0, PIUP, 0
FOR Radius!
= Maze.CellSize
* 1.5 + Maze.Thickness
TO Maze.CellSize
* 1.5 + 1 STEP -.5 CIRCLES xc% - Maze.CellSize, yc% + Maze.CellSize, Radius!, Maze.Colour, 0, PIUP, 0
CASE 13 ' ** up and down and left doors open FOR Radius!
= 1 TO Maze.Thickness
- .5 STEP .5 CIRCLES x% - Maze.Thickness, y% - Maze.Thickness, Radius!, Maze.Colour, PIDOWN, 0, 0
CIRCLES x% - Maze.Thickness, y% + Maze.CellSize + Maze.Thickness - 1, Radius!, Maze.Colour, 0, PIUP, 0
LINE (x%
+ Maze.CellSize
, yc%
- Maze.CellSize
)-(x%
+ Maze.CellSize
+ Maze.Thickness
- 1, yc%
+ Maze.CellSize
), Maze.Colour
, BF
LINE (xc%
- Maze.CellSize
, y%
- 1)-(x%
- Maze.Thickness
, y%
- Maze.Thickness
), Maze.Colour
, BF
LINE (x%
- 1, yc%
- Maze.CellSize
)-(x%
- Maze.Thickness
, y%
- Maze.Thickness
), Maze.Colour
, BF
LINE (xc%
- Maze.CellSize
, y%
+ Maze.CellSize
)-(x%
- Maze.Thickness
, y%
+ Maze.CellSize
+ Maze.Thickness
- 1), Maze.Colour
, BF
LINE (x%
- 1, yc%
+ Maze.CellSize
)-(x%
- Maze.Thickness
, y%
+ Maze.CellSize
+ Maze.Thickness
- 1), Maze.Colour
, BF
FOR Radius!
= Maze.CellSize
/ 2 - Maze.Thickness
TO Maze.CellSize
/ 2 STEP .5 CIRCLES xc% - Maze.CellSize, yc% + Maze.CellSize, Radius!, Maze.Colour, 0, PIUP, 0
CIRCLES xc% - Maze.CellSize, yc% - Maze.CellSize, Radius!, Maze.Colour, PIDOWN, 0, 0
LINE (x%
+ Maze.CellSize
, yc%
- Maze.CellSize
)-(x%
+ Maze.CellSize
+ Maze.Thickness
- 1, yc%
+ Maze.CellSize
), Maze.Colour
, BF
CASE 14 ' ** down and left and right doors open FOR Radius!
= 1 TO Maze.Thickness
- .5 STEP .5 CIRCLES x% + Maze.CellSize + Maze.Thickness - 1, y% + Maze.CellSize + Maze.Thickness - 1, Radius!, Maze.Colour, PIUP, PI, 0
CIRCLES x% - Maze.Thickness, y% + Maze.CellSize + Maze.Thickness - 1, Radius!, Maze.Colour, 0, PIUP, 0
LINE (xc%
- Maze.CellSize
, y%
- 1)-(xc%
+ Maze.CellSize
, y%
- Maze.Thickness
), Maze.Colour
, BF
LINE (xc%
- Maze.CellSize
, y%
+ Maze.CellSize
)-(x%
- Maze.Thickness
, y%
+ Maze.CellSize
+ Maze.Thickness
- 1), Maze.Colour
, BF
LINE (xc%
+ Maze.CellSize
, y%
+ Maze.CellSize
)-(x%
+ Maze.CellSize
+ Maze.Thickness
- 1, y%
+ Maze.CellSize
+ Maze.Thickness
- 1), Maze.Colour
, BF
LINE (x%
- 1, yc%
+ Maze.CellSize
)-(x%
- Maze.Thickness
, y%
+ Maze.CellSize
+ Maze.Thickness
- 1), Maze.Colour
, BF
LINE (x%
+ Maze.CellSize
, yc%
+ Maze.CellSize
)-(x%
+ Maze.CellSize
+ Maze.Thickness
- 1, y%
+ Maze.CellSize
+ Maze.Thickness
- 1), Maze.Colour
, BF
FOR Radius!
= Maze.CellSize
/ 2 - Maze.Thickness
TO Maze.CellSize
/ 2 STEP .5 CIRCLES xc% - Maze.CellSize, yc% + Maze.CellSize, Radius!, Maze.Colour, 0, PIUP, 0
CIRCLES xc% + Maze.CellSize, yc% + Maze.CellSize, Radius!, Maze.Colour, PIUP, PI, 0
LINE (xc%
- Maze.CellSize
, y%
- 1)-(xc%
+ Maze.CellSize
, y%
- Maze.Thickness
), Maze.Colour
, BF
CASE 15 ' ** all doors open FOR Radius!
= 1 TO Maze.Thickness
- .5 STEP .5 CIRCLES x% - Maze.Thickness, y% - Maze.Thickness, Radius!, Maze.Colour, PIDOWN, 0, 0
CIRCLES x% + Maze.CellSize + Maze.Thickness - 1, y% - Maze.Thickness, Radius!, Maze.Colour, PI, PIDOWN, 0
CIRCLES x% + Maze.CellSize + Maze.Thickness - 1, y% + Maze.CellSize + Maze.Thickness - 1, Radius!, Maze.Colour, PIUP, PI, 0
CIRCLES x% - Maze.Thickness, y% + Maze.CellSize + Maze.Thickness - 1, Radius!, Maze.Colour, 0, PIUP, 0
LINE (xc%
- Maze.CellSize
, y%
- 1)-(x%
- Maze.Thickness
, y%
- Maze.Thickness
), Maze.Colour
, BF
LINE (x%
- 1, yc%
- Maze.CellSize
)-(x%
- Maze.Thickness
, y%
- Maze.Thickness
), Maze.Colour
, BF
LINE (x%
+ Maze.CellSize
, yc%
- Maze.CellSize
)-(x%
+ Maze.CellSize
+ Maze.Thickness
- 1, y%
- Maze.Thickness
), Maze.Colour
, BF
LINE (xc%
+ Maze.CellSize
, y%
- 1)-(x%
+ Maze.CellSize
+ Maze.Thickness
- 1, y%
- Maze.Thickness
), Maze.Colour
, BF
LINE (xc%
- Maze.CellSize
, y%
+ Maze.CellSize
)-(x%
- Maze.Thickness
, y%
+ Maze.CellSize
+ Maze.Thickness
- 1), Maze.Colour
, BF
LINE (xc%
+ Maze.CellSize
, y%
+ Maze.CellSize
)-(x%
+ Maze.CellSize
+ Maze.Thickness
- 1, y%
+ Maze.CellSize
+ Maze.Thickness
- 1), Maze.Colour
, BF
LINE (x%
- 1, yc%
+ Maze.CellSize
)-(x%
- Maze.Thickness
, y%
+ Maze.CellSize
+ Maze.Thickness
- 1), Maze.Colour
, BF
LINE (x%
+ Maze.CellSize
, yc%
+ Maze.CellSize
)-(x%
+ Maze.CellSize
+ Maze.Thickness
- 1, y%
+ Maze.CellSize
+ Maze.Thickness
- 1), Maze.Colour
, BF
FOR Radius!
= Maze.CellSize
/ 2 - Maze.Thickness
TO Maze.CellSize
/ 2 STEP .5 CIRCLES xc% - Maze.CellSize, yc% - Maze.CellSize, Radius!, Maze.Colour, PIDOWN, 0, 0
CIRCLES xc% - Maze.CellSize, yc% + Maze.CellSize, Radius!, Maze.Colour, 0, PIUP, 0
CIRCLES xc% + Maze.CellSize, yc% - Maze.CellSize, Radius!, Maze.Colour, PI, PIDOWN, 0
CIRCLES xc% + Maze.CellSize, yc% + Maze.CellSize, Radius!, Maze.Colour, PIUP, PI, 0
'----------------------------------------------------------------------------------------------------------------------
SUB CIRCLES
(cx%
, cy%
, r!
, c~&
, s!
, e!
, a!
)
'**
'** QB64 temporary replacement CIRCLE command.
'**
'** The CIRCLE command in QB64 has a few bugs listed below:
'**
'** - radian end points are not calculate properly when creating arcs
'** - center line to radian end points do not close properly due to previous bug listed
'**
'** This circle command replacement works very similiarly to the native CIRCLE command:
'**
'** SYNTAX: CIRCLES x%, y%, radius!, color~&, start_radian!, end_radian!, aspect_ratio!
'**
'** x% - center X coordinate of circle
'** y% - center Y coordinate of circle
'** radius! - the radius of the circle
'** color~& - the circle's color
'** start_radian! - the radian on circle curcunference to begin drawing at
'** end_radian! - the radian on circle circumference to end drawing at
'** aspect_ratio! - the aspect ratio of the circle
'**
'** NOTE: unlike the native CIRCLE command, all arguments MUST be supplied. For example,
'** with the native command this will draw a perfect circle with the default color,
'** start radian, end radian and aspect ratio:
'**
'** CIRCLE (319, 239), 100
'**
'** To do the same thing with this replacement command you must supply everything:
'**
'** CIRCLES 319, 239, 100, _RGB32(255, 255, 255), 0, 0, 0
'**
'** ACKNOWLEGEMENTS: The FOR/NEXT step formula was was written by Codeguy for Unseen
'** Machine's Visual library EllipseXS command. Specifically:
'** MinStep! = 1 / (2 * PI535 * Radius!)
'** NOTE: The FOR/NEXT loop was replaced with a DO/LOOP by SMcNeill - 02/02/-13
'**
'** Includes performance tweaks made by SMcNeill on 02/02/13 - specifically removing a few redundant * -1
'** statements and converting the FOR/NEXT loop to a DO loop for a ~3% increase in performance.
'**
'** Corrected bug in which variables being passed in were being modified and passed back - 02/02/13
'**
DIM s%
, e%
, nx%
, ny%
, xr!
, yr!
, st!
, en!
, asp!
' local variables used
st! = s! ' copy start radian to local variable
en! = e! ' copy end radian to local variable
asp! = a! ' copy aspect ratio to local variable
IF asp!
<= 0 THEN asp!
= 1 ' keep aspect ratio between 0 and 4 IF asp!
< 1 THEN xr!
= r!
* asp!
* 4 ELSE xr!
= r!
' calculate x/y radius based on aspect ratio IF st!
< 0 THEN s%
= -1: st!
= -st!
' remember if line needs drawn from center to start radian IF en!
< 0 THEN e%
= -1: en!
= -en!
' remember if line needs drawn from center to end radian IF s%
THEN ' draw line from center to start radian? nx%
= cx%
+ xr!
* COS(st!
) ' yes, compute starting point on circle's circumference ny%
= cy%
+ yr!
* -SIN(st!
) LINE (cx%
, cy%
)-(nx%
, ny%
), c~&
' draw line from center to radian IF en!
<= st!
THEN en!
= en!
+ 6.2831852 ' come back around to proper location (draw counterclockwise) stepp! = 0.159154945806 / r!
c! = st! ' cycle from start radian to end radian
nx%
= cx%
+ xr!
* COS(c!
) ' compute next point on circle's circumfrerence ny%
= cy%
+ yr!
* -SIN(c!
) PSET (nx%
, ny%
), c~&
' draw the point c! = c! + stepp!
IF e%
THEN LINE -(cx%
, cy%
), c~&
' draw line from center to end radian if needed
'----------------------------------------------------------------------------------------------------------------------