close

 

了参加TI的应用比赛,研究了半天

一开始,自己按照定义来画,平台是vb

算法 很简单,因为已知 abs(c)<=2 ,那么我就循环代入c

然后再迭代,不会溢出的就画上去

迭代256次,delta c = 0.1 的结果是,有3%的地方出现明显错误,边缘不细腻

看图

运算2.PNG 

我进行更高精确的计算时,计算所需的时间是按指数级增长的,于是我放弃了

然后,我就画了画Julia集合,精度越高,时间越长,这里有超级计算机就好了

运算3.PNG 

再画下去,我的电脑要崩溃了。。

享一个我的 vb 源码

Option Explicit
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long '用来发送信息,因为画画的时间比较长,所以发送给另一个程序来监测完成度
Private p As COMPLEX, tP As COMPLEX
Private C As COMPLEX
Private MAXN As Long
Private EachStep As Double
Private i As Long, n As Long
Private p1 As Long, q1 As Long
Private ZoomV1 As Integer
Private Draw As Boolean
Private hMonitor As Long
Private Const SC_MAXIMIZE = &HF030


Private Type COMPLEX
x As Double
y As Double
End Type

 

Private Sub Command1_Click()
On Error Resume Next

MAXN = Text3.Text
EachStep = Text4.Text
PIC.Scale (CSng(Text(0).Text), CSng(Text(1).Text))-(CSng(Text(2).Text), CSng(Text(3).Text))  ‘pic是一个picturebox
PIC.Cls

For C.x = Text(0).Text To Text(2).Text Step EachStep
For C.y = Text(3).Text To Text(1).Text Step EachStep
p1 = VarPtr(C.x)
q1 = VarPtr(C.y)
SendMessage ByVal hMonitor, 0, p1, q1 '发送消息

p.x = C.x
p.y = C.y
Draw = True

For n = 1 To MAXN Step 1
FUNC p, tP
p = tP
If (p.x ^ 2 + p.y ^ 2) > 4 Then
Draw = False
Exit For
End If
Next

If Draw = True Then PIC.PSet (C.x, C.y)

Next
Next

End Sub

 

Private Function FUNC(ByRef iP As COMPLEX, ByRef oP As COMPLEX)
oP.x = iP.x ^ 2 - iP.y ^ 2 + C.x
oP.y = 2 * iP.x * iP.y + C.y
End Function

 

Private Sub Command2_Click()
hMonitor = Text1.Text
End Sub

Private Sub Command3_Click()
Text(0).Text = -2
Text(1).Text = 1.5
Text(2).Text = 1
Text(3).Text = -1.5
Command1_Click
End Sub

 

Private Sub Form_Initialize()
Me.Caption = "Mandelbrot , Julia Set by Магсн v" & App.Major & "." & App.Minor & "." & App.Revision
End Sub

Private Sub Form_Resize()
On Error Resume Next
PIC.Width = Me.ScaleWidth - (8670 - 6315)
PIC.Height = Me.ScaleHeight - (6300 - 5835)
End Sub '无关紧要的东西

 

Private Sub PIC_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
If ZoomV1 <> 1 Then
Text(0).Text = x
Text(1).Text = y
ZoomV1 = 1
Else
Text(2).Text = x
Text(3).Text = y
Command1_Click
ZoomV1 = 0
End If
End Sub

Private Sub PIC_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
Text2(0).Text = x
Text2(1).Text = y
End Sub

arrow
arrow
    全站熱搜

    Магсн 發表在 痞客邦 留言(0) 人氣()