Appendix 4: Programme Code

Feedback

Programmed in QBasic

Cls

INPUT "INPUT A VALUE FOR X"; X

INPUT "INPUT A VALUE FOR LAMBDA"; LAMBDA

INPUT "INPUT NUMBER OF ITERATIONS"; A#

For i% = 1 To A#

X = LAMBDA * X * (1 - X)

Print X

Next i%

Print ""

Print "Press any key to continue..."

Do

Loop While INKEY$ = ""

Sequential Search Feedback

Programmed in Qbasic.

Graphics code by S. Elliot.

Rem Declare that subsequent arrays are to be allocated dynamically

Rem $DYNAMIC

COMMON x AS DOUBLE

COMMON l AS DOUBLE

COMMON max AS DOUBLE

COMMON min AS DOUBLE

GetInput:

Cls

INPUT "Enter No. of Iterations"; ITERATIONS

INPUT "Enter Search Length"; MATCHRANGE

Print "Enter Delay time: ";

Color 3

Print ; "N";

Color 7

Print ; "o Delay; ";

Color 3

Print ; "W";

Color 7

Print ; "ait for Key; ";

Color 3

Print ; "S";

Color 7

Print ; "leep Delay";

Color 3

INPUT ; DELAYCHOICE$

Color 7

DELAYCHOICE$ = UCase$(DELAYCHOICE$)

Select Case DELAYCHOICE$

Case "N"

Delay = -1

Case "W"

Delay = 0

Case "S"

Delay = 1

Case Else

GoTo GetInput

End Select

Start:

For x = 0.1 To 0.9 Step 0.05

For l = 2 To 4 Step 0.05

I = ITERATIONS

Rem Calculating Points

Dim pt(I) As Double

pt(1) = x

Max = pt(1)

Min = pt(1)

For j = 2 To I

pt(j) = pt(j - 1) * l * (1 - pt(j - 1))

If Max < pt(j) Then Max = pt(j)

If Min > pt(j) Then Min = pt(j)

Next j

Rem Pattern Searching

h = -1

If (I >= MATCHRANGE + 5) Then

h = 0

For j = 1 To (I - (MATCHRANGE + 1))

If pt(j) = pt(I - MATCHRANGE) Then

h = j

j2 = 0

While (j2 < (MATCHRANGE - 1))

j2 = j2 + 1

If pt(j + j2) <> pt(I - MATCHRANGE + j2) Then

h = 0

j2 = MATCHRANGE

End If

Wend

End If

If (h > 0) Then j = I - (MATCHRANGE + 1)

Next j

End If

Screen 12

Cls

WINDOW (0, max + (max * .2))-(I, min - (min * .1))

Print "X=";: Print USING; "#.##"; x;: Print ": L=";: Print USING; "#.##"; l;: Print ": I="; I; ": max=";: Print USING; "#.##"; Max;: Print ": min=";: Print USING; "#.##"; Min

If (h = 0) Then

Print "No match found"

ElseIf (h < 0) Then

Print "No match found (I<15)"

Else

Print "Match found at iteration "; h

End If

PSet (1, pt(1)), 15

For j = 2 To I

If (j >= h + 1) And (j <= h + 10) And (h > 0) Then

Line -(j, pt(j)), 13

ElseIf (h > 0) And (j > I - 10) Then

Line -(j, pt(j)), 13

Else

Line -(j, pt(j)), 7

End If

PSet (j, pt(j)), 15

Next j

Erase pt

If Delay >= 0 Then SLEEP Delay

k$ = INKEY$

If k$ = Chr$(27) Then

GoTo brk

ElseIf UCase$(k$) = "P" Then

Print "...paused...press [Enter] to continue..."

Do

Loop Until INKEY$ = Chr$(13)

End If

Next l

Next x

brk:

End

Julia Sets

Programmed in Visual Basic

Form 1

Private Sub Command1_Click()

plot

End Sub

Private Sub Command2_Click()

End

End Sub

Private Sub Form_Load()

Splash

End Sub

Private Sub mnuAboutItem_Click()

Splash

End Sub

Private Sub mnuExitItem_Click()

End

End Sub

Private Sub mnuPlotItem_Click()

plot

End Sub

Private Sub mnuReadmeItem_Click()

OleReadme.DoVerb

End Sub

Private Sub mnuRestoreDefaultsItem_Click()

inputcx.Text = 0

inputcy.Text = 1

inputx.Text = 0

inputy.Text = 0

iterations.Text = "10,000"

End Sub

Public Sub plot()

Dim x As Single, y As Single, z As Single, m As Single, n As Single

Form2.Visible = True

Form2.ScaleHeight = 600

Form2.ScaleWidth = 800

iterations = iterations.Text

x = 0

y = 0

cx = 0

cy = 0

For a = TextFrom.Text To TextTo.Text Step 0.01

For i = 1 To iterations

If Optioncx.Value = True Then

wx = x - a

wy = y - cy

ElseIf Optioncy.Value = True Then

wx = x - cx

wy = y - a

End If

Select Case wx

Case Is > 0

theta = Atn(wy / wx)

Case Is < 0

theta = 3.14159 + Atn(wy / wx)

Case Is = 0

theta = 1.57079

End Select

theta = theta / 2

r = Sqr(wx * wx + wy * wy)

If Rnd < 0.5 Then

r = Sqr(r)

Else

r = -Sqr(r)

End If

x = r * Cos(theta)

y = r * Sin(theta)

m = -5 + (x + 4) * 80

n = (2 - y) * 80

If i < 50 Then

GoTo nexti

Else

z = a * 400 - 200

c = Abs(a * 200 + 55)

'Form2.ForeColor = RGB(c, c, c)

'Form2.ForeColor = QBColor(15)

'Call plot3d(m, n, z)

Form2.PSet (m, n), RGB(c, c, c)

End If

nexti:

Next i

'Form2.Cls

Next a

End Sub

Private Sub plot3d(x As Single, y As Single, z As Single)

m = x + (SQR2 * y)

n = z + (SQR2 * y)

m = (ScaleWidth / 2) + m

n = (ScaleHeight / 2) + n

'm = m * k

'n = ScaleHeight - n

Form2.PSet (m, n), QBColor(15)

End Sub
 
 

Public Sub Splash()

Form1.Enabled = False

Form1.Visible = False

frmSplash.Visible = True

End Sub

Form 2

Private Sub Form_DblClick()

Form2.Hide

Unload Form2

End Sub

FrmSplash

Option Explicit

Private Sub Form_KeyPress(KeyAscii As Integer)

Unload Me

Form1.Enabled = True

Form1.Visible = True

End Sub

Private Sub Form_Load()

lblVersion.Caption = "Version " & App.Major & "." & App.Minor & "." & App.Revision

End Sub

Private Sub Frame1_Click()

Unload Me

Form1.Enabled = True

Form1.Visible = True

End Sub

3-Dimensional Sequential Julia Sets

Programmed in Visual Basic.

Graphics code by S. Elliot.

Form 1

Const SQR2 = 0.707

Public Sub plot3d(x As Double, y As Double, z As Double, c As Integer)

Dim m As Single, n As Single

m = x + (SQR2 * y)

n = z + (SQR2 * y)

m = (ScaleWidth / 2) + m

n = (ScaleHeight / 2) + n

n = ScaleHeight - n

If c = -1 Then

PSet (m, n), RGB(200, 0, 0)

Else

PSet (m, n), RGB(c, c, c)

End If

End Sub
 
 

Private Sub Form_DblClick()

End

End Sub

Private Sub Form_Load()

ScaleHeight = 600

ScaleWidth = 800

DrawWidth = 1

DrawStyle = 0

DrawMode = 13

End Sub

FrmOptions

Private Sub cboIncrements_Change()

If cboIncrements.Text > 0.01 Then

MsgBox "Please enter a value below 0.01", vbOKOnly, "Error"

cboIncrements.Text = 0.005

End If

End Sub

Private Sub chkContours_Click()

If chkContours.Value = 0 Then

cboContours.Enabled = False

ElseIf chkContours.Value = 1 Then

cboContours.Enabled = True

End If

End Sub

Private Sub cmdExit_Click()

End

End Sub

Private Sub cmdOK_Click()

frmOptions.Hide

Form1.Show

Form1.Cls

If optCx.Value = True Then

Module1.plotcx

ElseIf optCy.Value = True Then

Module1.plotcy

End If

End Sub

Private Sub Form_Load()

cboIncrements.AddItem "0.005", 0

cboIncrements.AddItem "0.001", 1

cboContours.AddItem "15", 0

cboContours.AddItem "30", 1

End Sub

Private Sub fraIterations_DragDrop(Source As Control, X As Single, Y As Single)

End Sub

Module 1

Public Sub plotcx()

Dim X As Double, Y As Double, z As Double, m As Double, n As Double, c As Integer

Dim iterations As Long

j = 0

contourbreak = frmOptions.cboContours.Text

iterations = frmOptions.txtIterations.Text

X = 0

Y = 0

cx = 0

cy = 0

deltacx = frmOptions.txtTo.Text

stepdeltacx = frmOptions.cboIncrements.Text

stepdeltacy = frmOptions.cboIncrements.Text

For cx = frmOptions.txtFrom.Text To frmOptions.txtTo.Text Step stepdeltacx
 
 

j = (j + 1) Mod contourbreak

For i% = 1 To iterations

wx = X - cx

wy = Y - cy

Select Case wx

Case Is > 0

theta = Atn(wy / wx)

Case Is < 0

theta = 3.14159 + Atn(wy / wx)

Case Is = 0

theta = 1.57079

End Select

theta = theta / 2

r = Sqr(wx * wx + wy * wy)

If Rnd < 0.5 Then

r = Sqr(r)

Else

r = -Sqr(r)

End If

X = r * Cos(theta)

Y = r * Sin(theta)

m = X * 300 - 150

n = Y * 300 - 150

If i% < 50 Then GoTo nexti

'determine the z value based on the current cy value

z = (cx / deltacx) * (Form1.ScaleHeight / 2) - (Form1.ScaleHeight / 4)

'determine the scaled colour

c = Int((cx / deltacx) * 200) + 55

If j = 0 Then

If frmOptions.chkContours = 1 Then

c = -1

End If

End If

Call Form1.plot3d(m, n, z, c)

DoEvents

nexti:

Next i%

Next cx

End Sub

Public Sub plotcy()

Dim X As Double, Y As Double, z As Double, m As Double, n As Double, c As Integer

Dim iterations As Long

j = 0

contourbreak = frmOptions.cboContours.Text

iterations = frmOptions.txtIterations.Text

X = 0

Y = 0

cx = 0

cy = 0

deltacy = frmOptions.txtTo.Text

stepdeltacx = frmOptions.cboIncrements.Text

stepdeltacy = frmOptions.cboIncrements.Text

For cy = frmOptions.txtFrom.Text To frmOptions.txtTo.Text Step stepdeltacy

j = (j + 1) Mod contourbreak

For i% = 1 To iterations

wx = X - cx

wy = Y - cy

Select Case wx

Case Is > 0

theta = Atn(wy / wx)

Case Is < 0

theta = 3.14159 + Atn(wy / wx)

Case Is = 0

theta = 1.57079

End Select

theta = theta / 2

r = Sqr(wx * wx + wy * wy)

If Rnd < 0.5 Then

r = Sqr(r)

Else

r = -Sqr(r)

End If

X = r * Cos(theta)

Y = r * Sin(theta)

m = X * 300 - 150

n = Y * 300 - 150

If i% < 50 Then GoTo nexti

'determine the z value based on the current cy value

z = (cy / Abs(deltacy)) * (Form1.ScaleHeight / 2) - (Form1.ScaleHeight / 4)

'determine the scaled colour

c = Int((cy / deltacy) * 200) + 55

If j = 0 Then

If frmOptions.chkContours = 1 Then

c = -1

End If

End If

Call Form1.plot3d(m, n, z, c)

DoEvents

nexti:

Next i%

Next cy

End Sub