home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / OldSrc / CH8 / SRC / MAND.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-05-02  |  19.4 KB  |  626 lines

  1. VERSION 4.00
  2. Begin VB.Form MandelbrotForm 
  3.    Caption         =   "Mandelbrot"
  4.    ClientHeight    =   3810
  5.    ClientLeft      =   2370
  6.    ClientTop       =   1320
  7.    ClientWidth     =   3810
  8.    Height          =   4500
  9.    Left            =   2310
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   254
  12.    ScaleMode       =   3  'Pixel
  13.    ScaleWidth      =   254
  14.    Top             =   690
  15.    Width           =   3930
  16.    Begin VB.PictureBox Canvas 
  17.       AutoRedraw      =   -1  'True
  18.       BackColor       =   &H00000000&
  19.       DrawMode        =   6  'Mask Pen Not
  20.       Height          =   3810
  21.       Left            =   0
  22.       MousePointer    =   2  'Cross
  23.       Picture         =   "MAND.frx":0000
  24.       ScaleHeight     =   250
  25.       ScaleMode       =   3  'Pixel
  26.       ScaleWidth      =   250
  27.       TabIndex        =   0
  28.       Top             =   0
  29.       Width           =   3810
  30.    End
  31.    Begin MSComDlg.CommonDialog FileDialog 
  32.       Left            =   240
  33.       Top             =   3600
  34.       _version        =   65536
  35.       _extentx        =   847
  36.       _extenty        =   847
  37.       _stockprops     =   0
  38.       cancelerror     =   -1  'True
  39.    End
  40.    Begin VB.Menu mnuFile 
  41.       Caption         =   "&File"
  42.       Begin VB.Menu mnuFileSaveAs 
  43.          Caption         =   "&Save As..."
  44.          Shortcut        =   ^A
  45.       End
  46.       Begin VB.Menu mnuFileSep 
  47.          Caption         =   "-"
  48.       End
  49.       Begin VB.Menu mnuFileExit 
  50.          Caption         =   "E&xit"
  51.       End
  52.    End
  53.    Begin VB.Menu mnuScaleMnu 
  54.       Caption         =   "&Scale"
  55.       Begin VB.Menu mnuScale 
  56.          Caption         =   "x&2"
  57.          Index           =   2
  58.       End
  59.       Begin VB.Menu mnuScale 
  60.          Caption         =   "x&4"
  61.          Index           =   4
  62.       End
  63.       Begin VB.Menu mnuScale 
  64.          Caption         =   "x&8"
  65.          Index           =   8
  66.       End
  67.       Begin VB.Menu mnuScaleFull 
  68.          Caption         =   "&Full Scale"
  69.       End
  70.    End
  71.    Begin VB.Menu mnuOpt 
  72.       Caption         =   "&Options"
  73.       Begin VB.Menu mnuOptIter 
  74.          Caption         =   "&Iterations..."
  75.       End
  76.       Begin VB.Menu mnuOptColors 
  77.          Caption         =   "&Colors..."
  78.       End
  79.    End
  80.    Begin VB.Menu mnuMovie 
  81.       Caption         =   "&Movie"
  82.       Begin VB.Menu mnuMovieCreate 
  83.          Caption         =   "&Create Movie..."
  84.       End
  85.    End
  86. Attribute VB_Name = "MandelbrotForm"
  87. Attribute VB_Creatable = False
  88. Attribute VB_Exposed = False
  89. Option Explicit
  90. Dim DrawingBox As Boolean
  91. Dim StartX As Single
  92. Dim StartY As Single
  93. Dim CurX As Single
  94. Dim CurY As Single
  95. Dim Xmin As Single
  96. Dim Xmax As Single
  97. Dim Ymin As Single
  98. Dim Ymax As Single
  99. Dim MaxIter As Integer
  100. Dim NumClrs As Integer
  101. Dim ok_clr() As Integer
  102. ' ************************************************
  103. ' Return the number of colors in use.
  104. ' ************************************************
  105. Property Get NumColors() As Integer
  106.     NumColors = NumClrs
  107. End Property
  108. ' ************************************************
  109. ' Return the value of the indicated color.
  110. ' ************************************************
  111. Property Get OkClr(index As Integer) As Integer
  112.     OkClr = ok_clr(index)
  113. End Property
  114. ' ***********************************************
  115. ' Make Canvas's palette contain the system static
  116. ' colors so the colors are saved to files with
  117. ' the image.
  118. ' ***********************************************
  119. Sub PreparePalette(pic As Control)
  120. Dim SysPalSize As Integer
  121. Dim NumStaticColors As Integer
  122. Dim StaticColor1 As Integer
  123. Dim StaticColor2 As Integer
  124. Dim offset As Integer
  125. Dim LogPal As Integer
  126. Dim palentry(0 To 255) As PALETTEENTRY
  127. Dim sys(0 To 255) As PALETTEENTRY
  128. Dim i As Integer
  129.     ' Make sure the screen supports palettes.
  130.     If Not GetDeviceCaps(hdc, RASTERCAPS) And RC_PALETTE Then
  131.         Beep
  132.         MsgBox "This monitor does not support palettes.", _
  133.             vbCritical
  134.         End
  135.     End If
  136.     ' Get system palette size and # static colors.
  137.     SysPalSize = GetDeviceCaps(hdc, SIZEPALETTE)
  138.     NumStaticColors = GetDeviceCaps(hdc, NUMRESERVED)
  139.     StaticColor1 = NumStaticColors \ 2 - 1
  140.     StaticColor2 = SysPalSize - NumStaticColors \ 2
  141.     ' Make sure pic has the foreground palette.
  142.     pic.ZOrder
  143.     i = RealizePalette(pic.hdc)
  144.     DoEvents
  145.     ' Get the system palette entries.
  146.     i = GetSystemPaletteEntries(pic.hdc, 0, SysPalSize, sys(0))
  147.             
  148.     ' Make the logical palette as big as possible.
  149.     LogPal = pic.Picture.hPal
  150.     If ResizePalette(LogPal, NumStaticColors) = 0 Then
  151.         Beep
  152.         MsgBox "Error resizing logical palette.", _
  153.             vbExclamation
  154.         Exit Sub
  155.     End If
  156.     ' Insert the system static colors.
  157.     For i = 0 To StaticColor1
  158.         palentry(i) = sys(i)
  159.     Next i
  160.     offset = StaticColor2 - StaticColor1 - 1
  161.     For i = StaticColor2 To 255
  162.         palentry(i - offset) = sys(i)
  163.     Next i
  164.     i = SetPaletteEntries(LogPal, 0, NumStaticColors, palentry(0))
  165.     ' Realize the new palette.
  166.     i = RealizePalette(pic.hdc)
  167. End Sub
  168. ' ************************************************
  169. ' Adjust the aspect ratio of the selected
  170. ' coordinates so they fit the window properly.
  171. ' ************************************************
  172. Sub AdjustAspect()
  173. Dim want_aspect As Single
  174. Dim canvas_aspect As Single
  175. Dim hgt As Single
  176. Dim wid As Single
  177. Dim mid As Single
  178.     want_aspect = (Ymax - Ymin) / (Xmax - Xmin)
  179.     canvas_aspect = Canvas.ScaleHeight / Canvas.ScaleWidth
  180.     If want_aspect > canvas_aspect Then
  181.         ' The selected area is too tall and thin.
  182.         ' Make it wider.
  183.         wid = (Ymax - Ymin) / canvas_aspect
  184.         mid = (Xmin + Xmax) / 2
  185.         Xmin = mid - wid / 2
  186.         Xmax = mid + wid / 2
  187.     Else
  188.         ' The selected area is too short and wide.
  189.         ' Make it taller.
  190.         hgt = (Xmax - Xmin) * canvas_aspect
  191.         mid = (Ymin + Ymax) / 2
  192.         Ymin = mid - hgt / 2
  193.         Ymax = mid + hgt / 2
  194.     End If
  195. End Sub
  196. ' ************************************************
  197. ' Draw the Mandelbrot set.
  198. ' ************************************************
  199. Sub DrawMandelbrot()
  200. Const MAX_MAG_SQUARED = 4  ' Work until the magnitude squared > 4.
  201. Dim bm As BITMAP
  202. Dim hbm As Integer
  203. Dim status As Long
  204. Dim bytes() As Byte
  205. Dim wid As Long
  206. Dim hgt As Long
  207. Dim clr As Long
  208. Dim i As Integer
  209. Dim j As Integer
  210. Dim ReaC As Double
  211. Dim ImaC As Double
  212. Dim dReaC As Double
  213. Dim dImaC As Double
  214. Dim ReaZ As Double
  215. Dim ImaZ As Double
  216. Dim ReaZ2 As Double
  217. Dim ImaZ2 As Double
  218.     WaitStart
  219.     AdjustAspect
  220.     ' Get the image pixels.
  221.     hbm = Canvas.Image
  222.     status = GetObject(hbm, 14, bm)
  223.     wid = bm.bmWidthBytes
  224.     hgt = bm.bmHeight
  225.     ReDim bytes(1 To wid, 1 To hgt)
  226.     ' dReaC is the change in the real part
  227.     ' (X value) for C. dImaC is the change in the
  228.     ' imaginary part (Y value).
  229.     dReaC = (Xmax - Xmin) / (wid - 1)
  230.     dImaC = (Ymax - Ymin) / (hgt - 1)
  231.     ' Calculate the values.
  232.     ReaC = Xmin
  233.     For i = 1 To wid
  234.         ImaC = Ymin
  235.         For j = 1 To hgt
  236.             ReaZ = 0
  237.             ImaZ = 0
  238.             ReaZ2 = 0
  239.             ImaZ2 = 0
  240.             clr = 1
  241.             Do While clr < MaxIter And _
  242.                     ReaZ2 + ImaZ2 < MAX_MAG_SQUARED
  243.                 ' Calculate Z(clr).
  244.                 ReaZ2 = ReaZ * ReaZ
  245.                 ImaZ2 = ImaZ * ImaZ
  246.                 ImaZ = 2 * ImaZ * ReaZ + ImaC
  247.                 ReaZ = ReaZ2 - ImaZ2 + ReaC
  248.                 clr = clr + 1
  249.             Loop
  250.             bytes(i, j) = ok_clr(clr Mod NumClrs)
  251.             ImaC = ImaC + dImaC
  252.         Next j
  253.         ReaC = ReaC + dReaC
  254.         
  255.         ' Let the user know we're not dead.
  256. '@        If i Mod 10 = 0 Then
  257. '@            status = SetBitmapBits(hbm, wid * hgt, bytes(1, 1))
  258. '@            Canvas.Refresh
  259. '@        End If
  260.     Next i
  261.     ' Update the image.
  262.     status = SetBitmapBits(hbm, wid * hgt, bytes(1, 1))
  263.     Canvas.Refresh
  264.     Caption = "Mandelbrot (" & Format$(Xmin) & ", " & Format$(Ymin) & ")-(" & Format$(Xmax) & ", " & Format$(Ymax) & ")"
  265.     WaitEnd
  266. End Sub
  267. ' ************************************************
  268. ' Fill in an array with the indexes of the static
  269. ' colors we want to use.
  270. ' ************************************************
  271. Sub InitColors()
  272.     NumClrs = 16
  273.     ReDim ok_clr(0 To NumClrs - 1)
  274.     ok_clr(0) = 0       ' Black
  275.     ok_clr(1) = 1       ' Dark red
  276.     ok_clr(2) = 2       ' Dark green
  277.     ok_clr(3) = 3       ' Dark yellow
  278.     ok_clr(4) = 4       ' Dark blue
  279.     ok_clr(5) = 5       ' Dark magenta
  280.     ok_clr(6) = 6       ' Dark cyan
  281. '   ok_clr( ) = 7       ' Light gray
  282. '   ok_clr( ) = 8       ' Money green
  283.     ok_clr(7) = 9       ' Sky blue
  284.     ok_clr(8) = 246     ' Cream
  285. '   ok_clr( ) = 247     ' Light gray
  286. '   ok_clr( ) = 248     ' Medium gray
  287.     ok_clr(9) = 249     ' Red
  288.     ok_clr(10) = 250    ' Green
  289.     ok_clr(11) = 251    ' Yellow
  290.     ok_clr(12) = 252    ' Blue
  291.     ok_clr(13) = 253    ' Magenta
  292.     ok_clr(14) = 254    ' Cyan
  293.     ok_clr(15) = 255    ' White
  294. End Sub
  295. ' ************************************************
  296. ' Start a rubberband box to select a zoom area.
  297. ' ************************************************
  298. Private Sub Canvas_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  299.     DrawingBox = True
  300.     StartX = X
  301.     StartY = Y
  302.     CurX = X
  303.     CurY = Y
  304.     Canvas.Line (StartX, StartY)-(CurX, CurY), , B
  305. End Sub
  306. ' ************************************************
  307. ' Continue the zoom area rubberband box.
  308. ' ************************************************
  309. Private Sub Canvas_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  310.     If Not DrawingBox Then Exit Sub
  311.     Canvas.Line (StartX, StartY)-(CurX, CurY), , B
  312.     CurX = X
  313.     CurY = Y
  314.     Canvas.Line (StartX, StartY)-(CurX, CurY), , B
  315. End Sub
  316. ' ************************************************
  317. ' Zoom in on the selected area.
  318. ' ************************************************
  319. Private Sub Canvas_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  320. Dim x1 As Single
  321. Dim x2 As Single
  322. Dim y1 As Single
  323. Dim y2 As Single
  324. Dim factor As Single
  325.     If Not DrawingBox Then Exit Sub
  326.     DrawingBox = False
  327.     Canvas.Line (StartX, StartY)-(CurX, CurY), , B
  328.     CurX = X
  329.     CurY = Y
  330.     ' Put the coordinates in proper order.
  331.     If CurX < StartX Then
  332.         x1 = CurX
  333.         x2 = StartX
  334.     Else
  335.         x1 = StartX
  336.         x2 = CurX
  337.     End If
  338.     If x1 = x2 Then x2 = x1 + 1
  339.     If CurY < StartY Then
  340.         y1 = CurY
  341.         y2 = StartY
  342.     Else
  343.         y1 = StartY
  344.         y2 = CurY
  345.     End If
  346.     If y1 = y2 Then y2 = y1 + 1
  347.     ' Convert screen coords into drawing coords.
  348.     factor = (Xmax - Xmin) / Canvas.ScaleWidth
  349.     Xmax = Xmin + x2 * factor
  350.     Xmin = Xmin + x1 * factor
  351.     factor = (Ymax - Ymin) / Canvas.ScaleHeight
  352.     Ymax = Ymin + y2 * factor
  353.     Ymin = Ymin + y1 * factor
  354.     DrawMandelbrot
  355. End Sub
  356. ' ************************************************
  357. ' Force Visual Basic to resize the bitmap.
  358. ' ************************************************
  359. Private Sub Canvas_Resize()
  360.     Canvas.Cls
  361. End Sub
  362. ' ************************************************
  363. ' Allow the user to pick the colors in use.
  364. ' ************************************************
  365. Private Sub mnuOptColors_Click()
  366. Dim frm As New ColorForm
  367. Dim i As Integer
  368.     frm.Show vbModal
  369.     If frm.Canceled Then Exit Sub
  370.     ' See which colors were selected.
  371.     NumClrs = 0
  372.     For i = 0 To 9
  373.         If frm.ColorCheck(i).value = vbChecked Then _
  374.             NumClrs = NumClrs + 1
  375.     Next i
  376.     For i = 246 To 255
  377.         If frm.ColorCheck(i).value = vbChecked Then _
  378.             NumClrs = NumClrs + 1
  379.     Next i
  380.     ' If the user didn't pick at least 2 colors,
  381.     ' use black and white.
  382.     If NumClrs < 2 Then
  383.         NumClrs = 2
  384.         frm.ColorCheck(0).value = vbChecked
  385.         frm.ColorCheck(255).value = vbChecked
  386.     End If
  387.     ' Create the ok_clr array.
  388.     ReDim ok_clr(0 To NumClrs - 1)
  389.     NumClrs = 0
  390.     For i = 0 To 9
  391.         If frm.ColorCheck(i).value = vbChecked Then
  392.             ok_clr(NumClrs) = i
  393.             NumClrs = NumClrs + 1
  394.         End If
  395.     Next i
  396.     For i = 246 To 255
  397.         If frm.ColorCheck(i).value = vbChecked Then
  398.             ok_clr(NumClrs) = i
  399.             NumClrs = NumClrs + 1
  400.         End If
  401.     Next i
  402.     Unload frm
  403. End Sub
  404. ' ***********************************************
  405. ' Load a new data file.
  406. ' ***********************************************
  407. Private Sub mnuFileSaveAs_Click()
  408. Dim fname As String
  409.     ' Allow the user to pick a file.
  410.     On Error Resume Next
  411.     FileDialog.filename = "*.BMP"
  412.     FileDialog.Flags = cdlOFNOverwritePrompt + cdlOFNHideReadOnly
  413.     FileDialog.ShowSave
  414.     If Err.Number = cdlCancel Then
  415.         Exit Sub
  416.     ElseIf Err.Number <> 0 Then
  417.         Beep
  418.         MsgBox "Error selecting file.", , vbExclamation
  419.         Exit Sub
  420.     End If
  421.     On Error GoTo 0
  422.     fname = Trim$(FileDialog.filename)
  423.     FileDialog.InitDir = Left$(fname, Len(fname) _
  424.         - Len(FileDialog.FileTitle) - 1)
  425.     ' Save the picture.
  426.     SavePicture Canvas.Image, fname
  427. End Sub
  428. ' ***********************************************
  429. ' Give the form and all the picture boxes an
  430. ' hourglass cursor.
  431. ' ***********************************************
  432. Sub WaitStart()
  433.     MousePointer = vbHourglass
  434.     Canvas.MousePointer = vbHourglass
  435.     DoEvents
  436. End Sub
  437. ' ***********************************************
  438. ' Restore the mouse pointers for the form and all
  439. ' the picture boxes.
  440. ' ***********************************************
  441. Sub WaitEnd()
  442.     MousePointer = vbDefault
  443.     Canvas.MousePointer = vbCrosshair
  444. End Sub
  445. ' ************************************************
  446. ' Draw the initial Mandelbrot set.
  447. ' ************************************************
  448. Private Sub Form_Load()
  449.     Me.Show
  450.     DoEvents
  451.     MaxIter = 64
  452.     ' Put the system static colors in the palette.
  453.     PreparePalette Canvas
  454.     ' Display the first Mandelbrot set.
  455.     InitColors
  456.     mnuScaleFull_Click
  457. End Sub
  458. Private Sub Form_Resize()
  459.     Canvas.Move 0, 0, ScaleWidth, ScaleHeight
  460. End Sub
  461. Private Sub mnuFileExit_Click()
  462.     Unload Me
  463. End Sub
  464. ' ************************************************
  465. ' Let the user set the maximum number of
  466. ' iterations.
  467. ' ************************************************
  468. Private Sub mnuOptIter_Click()
  469. Dim txt As String
  470. Dim value As Integer
  471.     txt = InputBox("Maximum number of iterations:", _
  472.         "Iterations", Format$(MaxIter))
  473.     If txt = "" Then Exit Sub
  474.     If IsNumeric(txt) Then value = CInt(txt)
  475.     If value > 0 Then
  476.         MaxIter = value
  477.     Else
  478.         Beep
  479.     End If
  480. End Sub
  481. ' ************************************************
  482. ' Zoom out to full scale.
  483. ' ************************************************
  484. Private Sub mnuScaleFull_Click()
  485.     Xmin = -2
  486.     Xmax = 1.2
  487.     Ymin = -1.2
  488.     Ymax = 1.2
  489.     DrawMandelbrot
  490. End Sub
  491. ' ************************************************
  492. ' Make a series of images.
  493. ' ************************************************
  494. Private Sub MakeMovie(fname As String)
  495. Dim num_frames As Integer
  496. Dim frame As Integer
  497. Dim fraction As Single  ' Amount to reduce image.
  498. Dim xmid As Single      ' Center of image.
  499. Dim ymid As Single
  500. Dim wid1 As Single      ' Starting dimensions.
  501. Dim hgt1 As Single
  502. Dim wid2 As Single      ' Finishing dimensions.
  503. Dim hgt2 As Single
  504. Dim wid As Single       ' Current dimensions.
  505. Dim hgt As Single
  506. Dim start_time As Single
  507. Dim stop_time As Single
  508. Dim max_time As Single
  509. Dim min_time As Single
  510. Dim txt As String
  511. Dim value As Integer
  512.     ' See how may frames the user wants.
  513.     txt = InputBox("Number of frames:", _
  514.         "Frames", "20")
  515.     If txt = "" Then Exit Sub
  516.     If IsNumeric(txt) Then num_frames = CInt(txt)
  517.     If num_frames < 1 Then num_frames = 20
  518.     WaitStart
  519.     max_time = 0
  520.     min_time = 100000
  521.         
  522.     ' Set the center of focus and dimensions.
  523.     xmid = (Xmin + Xmax) / 2
  524.     ymid = (Ymin + Ymax) / 2
  525.     wid1 = 3
  526.     wid2 = 0.1
  527.     ' Compute start and finish heights.
  528.     hgt1 = wid1 * Canvas.ScaleHeight / Canvas.ScaleWidth
  529.     hgt2 = wid2 * Canvas.ScaleHeight / Canvas.ScaleWidth
  530.     ' Compute the amount to reduce the image for
  531.     ' each frame.
  532.     fraction = Exp(Log(wid2 / wid1) / num_frames)
  533.     ' Start cranking out frames.
  534.     wid = wid1
  535.     hgt = hgt1
  536.     For frame = 0 To num_frames - 1
  537.         Caption = "Mandelbrot" & Str$(frame) & _
  538.             "/" & Format$(num_frames - 1)
  539.         
  540.         Xmin = xmid - wid / 2
  541.         Xmax = xmid + wid / 2
  542.         Ymin = ymid - hgt / 2
  543.         Ymax = ymid + hgt / 2
  544.                 
  545.         start_time = Timer
  546.         DrawMandelbrot
  547.         stop_time = Timer
  548.         
  549.         If min_time > stop_time - start_time Then min_time = stop_time - start_time
  550.         If max_time < stop_time - start_time Then max_time = stop_time - start_time
  551.             
  552.         SavePicture Canvas.Image, _
  553.             fname & Format$(frame) & ".bmp"
  554.         Beep
  555.         DoEvents
  556.                 
  557.         wid = wid * fraction
  558.         hgt = hgt * fraction
  559.     Next frame
  560.     WaitEnd
  561.     MsgBox _
  562.         "Longest:  " & Format$(max_time, "0.00") & _
  563.             " seconds." & vbCrLf & _
  564.         "Shortest: " & Format$(min_time, "0.00") & _
  565.             " seconds." & vbCrLf
  566. End Sub
  567. ' ************************************************
  568. ' Make a series of images.
  569. ' ************************************************
  570. Private Sub mnuMovieCreate_Click()
  571. Dim oldtitle As String
  572. Dim fname As String
  573. Dim pos As Integer
  574.     ' Allow the user to pick a file.
  575.     On Error Resume Next
  576.     oldtitle = FileDialog.DialogTitle
  577.     FileDialog.DialogTitle = "Select base file name (no number)"
  578.     FileDialog.filename = "*.BMP"
  579.     FileDialog.Flags = cdlOFNOverwritePrompt + cdlOFNHideReadOnly
  580.     FileDialog.ShowSave
  581.     FileDialog.DialogTitle = oldtitle
  582.     If Err.Number = cdlCancel Then
  583.         Exit Sub
  584.     ElseIf Err.Number <> 0 Then
  585.         Beep
  586.         MsgBox "Error selecting file.", , vbExclamation
  587.         Exit Sub
  588.     End If
  589.     On Error GoTo 0
  590.     fname = Trim$(FileDialog.filename)
  591.     FileDialog.InitDir = Left$(fname, Len(fname) _
  592.         - Len(FileDialog.FileTitle) - 1)
  593.     ' Trim off the extension if any.
  594.     pos = InStr(fname, ".")
  595.     If pos > 0 Then fname = Left$(fname, pos - 1)
  596.     ' Add a trailing underscore if needed.
  597.     If Right$(fname, 1) <> "_" Then _
  598.         fname = fname & "_"
  599.     ' Make the movie.
  600.     MakeMovie fname
  601. End Sub
  602. ' ************************************************
  603. ' Increase the area shown by a factor of Index.
  604. ' ************************************************
  605. Private Sub mnuScale_Click(index As Integer)
  606. Dim size As Single
  607. Dim mid As Single
  608.     size = index * (Xmax - Xmin)
  609.     If size > 3.2 Then
  610.         mnuScaleFull_Click
  611.         Exit Sub
  612.     End If
  613.     mid = (Xmin + Xmax) / 2
  614.     Xmin = mid - size / 2
  615.     Xmax = mid + size / 2
  616.     size = index * (Ymax - Ymin)
  617.     If size > 2.4 Then
  618.         mnuScaleFull_Click
  619.         Exit Sub
  620.     End If
  621.     mid = (Ymin + Ymax) / 2
  622.     Ymin = mid - size / 2
  623.     Ymax = mid + size / 2
  624.     DrawMandelbrot
  625. End Sub
  626.