Has anyone made a program that uses applications of chaos?
Printable View
Has anyone made a program that uses applications of chaos?
Here is a little example of a chaos program. Chaos is basically the principal of apparent randomness, that after a while shows a pattern of such mathematical accuracy that it is difficult to believe that randomness features anywhere in it.
This example works with the three points of an equalateral triangle (a triagle with all sides of equal length).
Your program must pick one of the points by random as a starting point.
Then you pick any one of the three points by random, and move your point from it's current position, half way to the selected point, and plot the pixel on the screen. Repeat this process till you are bored. You will see an amazing pattern.
Here's what you do: Create a project with a Form. The form must contain a Picturebox. Make sure that the ScaleMode of the Form and the Picturebox is set to Pixels. Set the AutoRedraw property of the picturebox to true. Add a command button and call it "cmdStartStop".
Now copy the coding below and watch the fun!
Hope this helps.Code:Option Explicit
Private Busy As Boolean
Private Type Coordinates
X As Single
Y As Single
End Type
Private Sub cmdStartStop_Click()
Dim Points(1 To 3) As Coordinates
Dim Position As Coordinates
Dim Index As Integer
Dim TriangleSize As Single
If Busy = False Then
Busy = True
cmdStartStop.Caption = "&Stop"
Else
Busy = False
cmdStartStop.Caption = "&Start"
Exit Sub
End If
'determine how big the triangle can be
TriangleSize = Picture1.ScaleWidth - 20
'set the coords of the points of the triangle
Points(1).X = 10
Points(1).Y = 10
Points(2).X = 10 + TriangleSize
Points(2).Y = 10
Points(3).X = 10 + TriangleSize / 2
Points(3).Y = 10 + Sqr(3) * TriangleSize / 2
'pick a random starting point
Index = Int(Rnd * 3) + 1
Position = Points(Index)
'clear the picturebox
Picture1.Cls
Do
'pick a random point
Index = Int(Rnd * 3) + 1
'Move the current position halfway to
'the selected point
Position.X = Position.X + (Points(Index).X - Position.X) / 2
Position.Y = Position.Y + (Points(Index).Y - Position.Y) / 2
'Plot the point
Picture1.PSet (Position.X, Position.Y)
DoEvents
Loop Until Busy = False
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
'make sure that processing has stopped before exiting
If Busy = True Then Call cmdStartStop_Click
End Sub
Private Sub Form_Resize()
Dim Border As Single
On Error Resume Next
Border = 4
Call cmdStartStop.Move(Border, Me.ScaleHeight - Border - cmdStartStop.Height)
Call Picture1.Move(Border, Border, Me.ScaleWidth - 2 * Border, cmdStartStop.Top - 3 * Border)
End Sub
Shrog