2012-10-08 00:38:44 +02:00
|
|
|
#!/usr/bin/env gbs3
|
|
|
|
|
|
|
|
Private Const MAXITER As Integer = 50
|
2015-11-15 00:22:10 +01:00
|
|
|
Private Const LIMIT As Float = 4.0
|
2012-10-08 00:38:44 +02:00
|
|
|
|
|
|
|
Sub Mandelbrot(W As Integer, H As Integer)
|
2015-10-31 02:02:58 +01:00
|
|
|
|
2012-10-08 00:38:44 +02:00
|
|
|
Dim XMin As Float = -1.5
|
|
|
|
Dim YMin As Float = -1
|
|
|
|
Dim InvN As Float = 2.0 / W
|
|
|
|
Dim CheckNext As Boolean = True
|
|
|
|
Dim X, Y, K As Integer
|
|
|
|
Dim Cr, Ci, Zr, Zi, {Tr}, Ti, T As Float
|
2015-10-31 02:02:58 +01:00
|
|
|
|
2012-10-08 00:38:44 +02:00
|
|
|
For Y = 0 To H - 1
|
2015-10-31 02:02:58 +01:00
|
|
|
|
2012-10-08 00:38:44 +02:00
|
|
|
Ci = Y * InvN + YMin
|
2015-10-31 02:02:58 +01:00
|
|
|
|
2012-10-08 00:38:44 +02:00
|
|
|
For X = 0 To W - 1
|
2015-10-31 02:02:58 +01:00
|
|
|
|
2012-10-08 00:38:44 +02:00
|
|
|
Zr = 0
|
|
|
|
Zi = 0
|
|
|
|
{Tr} = 0
|
|
|
|
Ti = 0
|
|
|
|
Cr = X * InvN + XMin
|
2015-10-31 02:02:58 +01:00
|
|
|
|
2012-10-08 00:38:44 +02:00
|
|
|
If CheckNext Then
|
2015-10-31 02:02:58 +01:00
|
|
|
|
2012-10-08 00:38:44 +02:00
|
|
|
For K = 1 To MAXITER
|
2015-11-15 00:22:10 +01:00
|
|
|
Zi = 2.0 * Zr * Zi + Ci
|
2012-10-08 00:38:44 +02:00
|
|
|
Zr = {Tr} - Ti + Cr
|
|
|
|
Ti = Zi * Zi
|
|
|
|
{Tr} = Zr * Zr
|
|
|
|
T = {Tr} + Ti
|
|
|
|
If IsNan(T) Or If T > LIMIT Then Break
|
|
|
|
Next
|
|
|
|
If K > MAXITER Then
|
|
|
|
Print "1";
|
|
|
|
CheckNext = False
|
|
|
|
Else
|
|
|
|
Print "0";
|
|
|
|
Endif
|
2015-10-31 02:02:58 +01:00
|
|
|
|
2012-10-08 00:38:44 +02:00
|
|
|
Else
|
2015-10-31 02:02:58 +01:00
|
|
|
|
2012-10-08 00:38:44 +02:00
|
|
|
For K = 1 To MAXITER
|
2015-10-31 02:02:58 +01:00
|
|
|
|
2015-11-15 00:22:10 +01:00
|
|
|
Zi = 2.0 * Zr * Zi + Ci
|
2012-10-08 00:38:44 +02:00
|
|
|
Zr = {Tr} - Ti + Cr
|
|
|
|
Ti = Zi * Zi
|
|
|
|
{Tr} = Zr * Zr
|
2015-10-31 02:02:58 +01:00
|
|
|
|
2012-10-08 00:38:44 +02:00
|
|
|
Next
|
2015-10-31 02:02:58 +01:00
|
|
|
|
2012-10-08 00:38:44 +02:00
|
|
|
T = {Tr} + Ti
|
|
|
|
If IsNan(T) Or If T > LIMIT Then
|
2015-10-31 02:02:58 +01:00
|
|
|
Print "0";
|
2012-10-08 00:38:44 +02:00
|
|
|
CheckNext = True
|
|
|
|
Else
|
|
|
|
Print "1";
|
|
|
|
Endif
|
2015-10-31 02:02:58 +01:00
|
|
|
|
2012-10-08 00:38:44 +02:00
|
|
|
Endif
|
2015-10-31 02:02:58 +01:00
|
|
|
|
2012-10-08 00:38:44 +02:00
|
|
|
Next
|
2015-10-31 02:02:58 +01:00
|
|
|
|
2012-10-08 00:38:44 +02:00
|
|
|
Print
|
2015-10-31 02:02:58 +01:00
|
|
|
|
2012-10-08 00:38:44 +02:00
|
|
|
Next
|
2015-10-31 02:02:58 +01:00
|
|
|
|
2012-10-08 00:38:44 +02:00
|
|
|
End
|
|
|
|
|
|
|
|
Dim I As Integer
|
|
|
|
|
2015-10-31 02:02:58 +01:00
|
|
|
For I = 1 To 20
|
2012-10-08 00:38:44 +02:00
|
|
|
Mandelbrot(200, 200)
|
|
|
|
Next
|