File: mandelbrot.jvs

package info (click to toggle)
gambas3 3.20.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 76,984 kB
  • sloc: ansic: 197,178; cpp: 124,076; sh: 18,999; javascript: 7,761; sql: 5,399; makefile: 2,354; perl: 1,397; xml: 490; python: 335
file content (167 lines) | stat: -rwxr-xr-x 3,020 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/usr/bin/java --source 11

public final class mandelbrot
{
  static private final int MAXITER = 50;
  static private final double LIMIT = 4.0;

  private static void mandelbrot(int w, int h)
  {
    double xmin = -1.5;
    double ymin = -1;
    double invn = 2.0 / w;
    boolean checkNext = true;
    int x, y, k;
    double cr, ci, zr, zi, tr, ti, t;

    for (y = 0; y < h; y++)
    {
      ci = y * invn + ymin;

      for (x = 0; x < w; x++)
      {
        zr = 0;
        zi = 0;
        tr = 0;
        ti = 0;
        cr = x * invn + xmin;
        t = 0;

        if (checkNext)
        {
          for (k = 1; k <= MAXITER; k++)
          {
            zi = 2.0 * zr * zi + ci;
            zr = tr - ti + cr;
            ti = zi * zi;
            tr = zr * zr;
            t = tr + ti;
            if (t != t || t > LIMIT)
              break;
          }
          if (k > MAXITER)
          {
            System.out.print("1");
            checkNext = false;
          }
          else
          {
            System.out.print("0");
          }
        }
        else
        {
          for (k = 1; k <= MAXITER; k++)
          {
            zi = 2.0 * zr * zi + ci;
            zr = tr - ti + cr;
            ti = zi * zi;
            tr = zr * zr;
          }

          t = tr + ti;
          if (t != t || t >= LIMIT)
          {
            System.out.print("0");
            checkNext = true;
          }
          else
          {
            System.out.print("1");
          }
        }
      }

      System.out.println();
      System.out.flush();
    }
  }

  public static void main(String[] args)
  {
    for (int i = 1; i <= 20; i++)
      mandelbrot(200, 200);
  }
}

/*#!/usr/bin/env gbs3

Private Const MAXITER As Integer = 50
Private Const LIMIT As Float = 4.0

Sub Mandelbrot(W As Integer, H As Integer)

  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

  For Y = 0 To H - 1

    Ci = Y * InvN + YMin

    For X = 0 To W - 1

      Zr = 0
      Zi = 0
      {Tr} = 0
      Ti = 0
      Cr = X * InvN + XMin

      If CheckNext Then

        For K = 1 To MAXITER
          Zi = 2.0 * Zr * Zi + Ci
          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

      Else

        For K = 1 To MAXITER

          Zi = 2.0 * Zr * Zi + Ci
          Zr = {Tr} - Ti + Cr
          Ti = Zi * Zi
          {Tr} = Zr * Zr

        Next

        T = {Tr} + Ti
        If IsNan(T) Or If T > LIMIT Then
          Print "0";
          CheckNext = True
        Else
          Print "1";
        Endif

      Endif

    Next

    Print

  Next

End

Dim I As Integer

For I = 1 To 20
  Mandelbrot(200, 200)
Next

Error CStr(Jit.Time)

*/