Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Const Wi As Long = 200
- Const He As Long = 200
- Const MaxI As Long = 1023
- Dim TLX, TLY, BRX, BRY As Double
- Public Sub Init()
- Me.Range(Cells(1, 1), Cells(He, Wi)).ColumnWidth = 0.5
- Me.Range(Cells(1, 1), Cells(He, Wi)).RowHeight = 5
- TLX = -2
- TLY = 2
- BRX = 2
- BRY = -2
- Me.Range(Cells(1, 1), Cells(He, Wi)).Select
- End Sub
- Private Sub Mandel(ByVal Target As Range)
- Dim x1, y1, zr, zi, cr, ci As Double
- x1 = (BRX - TLX) / Wi
- y1 = (TLY - BRY) / He
- TLX = TLX + x1 * (Target.Columns(1).Column - 1)
- BRX = TLX + x1 * Target.Columns.Count
- TLY = TLY - y1 * (Target.Rows(1).Row - 1)
- BRY = TLY - y1 * Target.Rows.Count
- x1 = (BRX - TLX) / Wi
- y1 = (TLY - BRY) / He
- For y = 1 To He
- For x = 1 To Wi
- cr = TLX + x * x1
- ci = TLY - y * y1
- zr = 0
- zi = 0
- For i = 0 To MaxI
- zrs = zr * zr
- zis = zi * zi
- If zrs + zis > 4 Then Exit For
- zi = 2 * zr * zi + ci
- zr = zrs - zis + cr
- Next
- Me.Cells(y, x).Interior.Color = RGB((5 * i) Mod 256, (4 * i) Mod 256, (3 * i) Mod 256)
- Next
- Next
- End Sub
- Private Sub Worksheet_SelectionChange(ByVal Target As Range)
- 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
- Call Mandel(Intersect(Me.Range(Cells(1, 1), Cells(He, Wi)), Target))
- Me.Cells(1, 1).Select
- End If
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement