Advertisement
Guest User

Untitled

a guest
Jan 19th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Const Wi As Long = 200
  2. Const He As Long = 200
  3. Const MaxI As Long = 1023
  4. Dim TLX, TLY, BRX, BRY As Double
  5. Public Sub Init()
  6.     Me.Range(Cells(1, 1), Cells(He, Wi)).ColumnWidth = 0.5
  7.     Me.Range(Cells(1, 1), Cells(He, Wi)).RowHeight = 5
  8.     TLX = -2
  9.     TLY = 2
  10.     BRX = 2
  11.     BRY = -2
  12.     Me.Range(Cells(1, 1), Cells(He, Wi)).Select
  13. End Sub
  14. Private Sub Mandel(ByVal Target As Range)
  15.     Dim x1, y1, zr, zi, cr, ci As Double
  16.     x1 = (BRX - TLX) / Wi
  17.     y1 = (TLY - BRY) / He
  18.     TLX = TLX + x1 * (Target.Columns(1).Column - 1)
  19.     BRX = TLX + x1 * Target.Columns.Count
  20.     TLY = TLY - y1 * (Target.Rows(1).Row - 1)
  21.     BRY = TLY - y1 * Target.Rows.Count
  22.     x1 = (BRX - TLX) / Wi
  23.     y1 = (TLY - BRY) / He
  24.    
  25.     For y = 1 To He
  26.         For x = 1 To Wi
  27.             cr = TLX + x * x1
  28.             ci = TLY - y * y1
  29.             zr = 0
  30.             zi = 0
  31.             For i = 0 To MaxI
  32.                 zrs = zr * zr
  33.                 zis = zi * zi
  34.                 If zrs + zis > 4 Then Exit For
  35.                 zi = 2 * zr * zi + ci
  36.                 zr = zrs - zis + cr
  37.             Next
  38.             Me.Cells(y, x).Interior.Color = RGB((5 * i) Mod 256, (4 * i) Mod 256, (3 * i) Mod 256)
  39.         Next
  40.     Next
  41. End Sub
  42. Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  43.     If (Intersect(Me.Range(Cells(1, 1), Cells(He, Wi)), Target).Rows.Count > 2) And (Intersect(Me.Range(Cells(1, 1), Cells(He, Wi)), Target).Columns.Count > 2) Then
  44.         Call Mandel(Intersect(Me.Range(Cells(1, 1), Cells(He, Wi)), Target))
  45.         Me.Cells(1, 1).Select
  46.     End If
  47. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement