Attribute VB_Name = "Module2" Public angle As Double, xpos As Double, ypos As Double Public cosinus As Double, sinus, dx As Double Public compte As Integer, nbreiter As Integer '*************************************************************************** '* FRACTALS: HENON'S ATTRACTORS * '* ----------------------------------------------------------------------- * '* TUTORIAL: * '* * '* The french politician and mathematician Poincaré highlighted the com- * '* plexity of planet trajectories that simple laws of celestial mechanics * '* do not show at first. A typical example is the movement of the Earth * '* around the sun, everybody knows that the period is one year long. This * '* is only true in first approximation, but not if you take into conside- * '* ration all the small perturbations caused by the other planets ! * '* * '* Periodic trajectories are useful for at least two reasons: * '* * '* 1) they can be predicted with accuracy by Kepler's laws, * '* * '* 2) it is possible to describe conveniently the small trajectory * '* variations by using the following: * '* * '* Let be T the basic periodic trajectory that we intercept by a fixed, * '* perpendicular plane, and O the point, taken as origin, of the plane * '* intercepted by the T trajectory. At next periods, the trajectory with * '* its small variations will meet the same plane at nearby points A0, A1, * '* A2 etc. * '* * '* This allows us to replace a complex problem of 3D trajectories by a * '* simpler problem of 2D representation of points. * '* * '* The french mathematician Hénon described in 1969 a dynamic system which * '* illustrates the proposed method: * '* * '* x n+1 = x n cos a - ( y n - x n² ) sin a * '* y n+1 = x n sin a + ( y n - x n² ) cos a * '* * '* a, being the angle of basic trajectory with respect to the observation * '* plane (in radians). * '* * '* The program randomly chooses an angle a (usually between 0.5 and 2.0 * '* radians). The number of iterations equals arbitrarily 200. * '* * '* As one can see, caracreristic figures are obtained, the points have a * '* noticeable tendancy to agglutinate themselves in particular "zones of * '* attraction". * '* ----------------------------------------------------------------------- * '* REFERENCE: * '* "Graphisme dans le plan et dans l'espace avec Turbo Pascal 4.0 * '* By R. Dony - MASSON, Paris 1990" [BIBLI 12]. * '* * '* Microsoft Visual Basic 4,0 release by J-P Moreau * '* (Program to use with Gr2D.bas and Henon.frm) * '* (www.jpmoreau.fr) * '**************************************************************************/ Sub Henon() Dim strangle As String * 8 Form1.Cls compte = 0 MaxX = 9000: MaxY = 6800 strangle = InputBox("Angle (radians):", "Henon") angle = Val(strangle) cosinus = Cos(angle): sinus = Sin(angle) nbreiter = 250: dx = 0.01 Fenetre -1.5, 1.5, -1.4, 1.4 Cloture 750, MaxX, 300, MaxY - 200 Display 1000, 300, "HENON'S ATTRACTORS" Axes Grid 0.25, 0.2 Bordure Graduate 0.25, 0.4 s$ = "Angle =" & Str$(angle) Display MaxX - 1200, MaxY - 750, s$ Form1.AutoRedraw = False 'main loop of Henon's attractor Do xcur% = Int(Rnd * MaxX) ycur% = Int(Rnd * MaxY) xpos = (xcur% / xrapport) + xgfen ypos = (ycur% / yrapport) + ybfen Henon1 xpos, ypos compte = compte + 1 Loop Until compte > 400 Beep Form1.AutoRedraw = True Form1.Command2.Caption = "&Continue" End Sub 'Subroutine called by Henon() Sub Henon1(ByVal x As Double, ByVal y As Double) Dim aux As Double Dim n As Integer For n = 1 To nbreiter If (x > xgfen) And (x < xdfen) And (y > ybfen) And (y < yhfen) Then MoveXY x, y LineXY x + dx, y End If aux = x If x < 1000000000000# Then x = x * cosinus - (y - x * x) * sinus y = aux * sinus + (y - aux * aux) * cosinus End If Next End Sub