' a little demonstration about WINDOW, VIEW and PMAP
_TITLE "a little demonstration about WINDOW, VIEW and PMAP"
'This example uses the VIEW and WINDOW statements to define a graphics
'viewport and window. The PMAP function is used to convert viewport
'coordinates to window coordinates. The program generates a fractal
'that shows a subset of the complex numbers called the "Mandelbrot Set."
DEFINT A
-Z
'Default variable type is integer.
'Set maximum number of iterations per point.
CONST MAXLOOP
= 30, MAXSIZE
= 1000000 CONST FALSE
= 0, TRUE
= NOT FALSE
'Boolean constants.
' set maximum viewport parameters (whole screen)
CONST VLm
= 0, VUm
= 0, VRm
= 799, VBm
= 599 ' set first viewport parameters
CONST VL1
= 50, VU1
= 50, VR1
= 200, VB1
= 500
' set second viewport parameters
CONST VL2
= 300, VU2
= 300, VR2
= 700, VB2
= 500
'Set window paramters.
CONST WLeft
= -1000, WRight
= 250, WTop
= 625, WBottom
= -625
' declaration global variables
ColorRange = 15
'Define viewport and corresponding window
' the whole window
VIEW (VLm
, VUm
)-(VRm
, VBm
), 0, ColorRange
WINDOW (WLeft
, WTop
)-(WRight
, WBottom
) DrawMandelbrot VLm, VRm, VBm, VUm
' a vertical little window
VIEW (VL1
, VU1
)-(VR1
, VB1
), 0, ColorRange
WINDOW (WLeft
, WTop
)-(WRight
, WBottom
) DrawMandelbrot VL1, VR1, VB1, VU1
' an horizhontal window
VIEW (VL2
, VU2
)-(VR2
, VB2
), 0, ColorRange
WINDOW (WLeft
, WTop
)-(WRight
, WBottom
) DrawMandelbrot VL2, VR2, VB2, VU2
Xlength = Right - Left
Ylength = Bottom - Up
ColorWidth = MAXLOOP \ ColorRange
'Loop through each pixel in viewport and calculate whether or not
'it is in the Mandelbrot Set.
FOR Y
= 0 TO Ylength
'Loop through every line in the viewport. LogicY
= PMAP(Y
, 3) 'Get the pixel's logical y coordinate. PSET (WLeft
, LogicY
) 'Plot leftmost pixel in the line. OldColor = 0 'Start with background color.
FOR X
= 0 TO Xlength
'Loop through every pixel in the line. LogicX
= PMAP(X
, 2) 'Get the pixel's logical x coordinate. MandelX& = LogicX
MandelY& = LogicY
'Do the calculations to see if this point is in the Mandelbrot Set.
RealNum& = MandelX& * MandelX&
ImagNum& = MandelY& * MandelY&
MandelY& = (MandelX& * MandelY&) \ 250 + LogicY
MandelX& = (RealNum& - ImagNum&) \ 500 + LogicX
'Assign a color to the point.
PColor = I \ ColorWidth
'If color has changed, draw a line from the last point
'referenced to the new point, using the old color.
LINE -(LogicX
, LogicY
), (ColorRange
- OldColor
) OldColor = PColor
'Draw the last line segment to the right edge of the viewport.
LINE -(LogicX
, LogicY
), (ColorRange
- OldColor
)