File: highlight.tig

package info (click to toggle)
kf6-syntax-highlighting 6.13.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 47,568 kB
  • sloc: xml: 197,750; cpp: 12,850; python: 3,023; sh: 955; perl: 546; ruby: 488; pascal: 393; javascript: 161; php: 150; jsp: 132; lisp: 131; haskell: 124; ada: 119; ansic: 107; makefile: 96; f90: 94; ml: 85; cobol: 81; yacc: 71; csh: 62; erlang: 54; sql: 51; java: 47; objc: 37; awk: 31; asm: 30; tcl: 29; fortran: 18; cs: 10
file content (78 lines) | stat: -rw-r--r-- 2,023 bytes parent folder | download | duplicates (5)
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
/* Mandelbrot integer demo
 * Released under the MIT License
 */

let
  /* Basic types.  */
  type bool = int
  type coord = int
  type value = int
  type array2d = array of value
  type image2d = { nrows : coord, ncols : coord, data : array2d }

  /* Image creation.  */
  function image_new (ncols : coord, nrows : coord) : image2d =
    image2d { nrows = nrows, ncols = ncols,
	      data = array2d[nrows * ncols] of 0 }

  function image_set (input : image2d, col : coord, row : coord,
		      value : value) =
    (
      input.data[row * input.ncols + col] := value
    )

  function mandelbrot () =
    let
      type fp = int
      var X : int := 300
      var Y : int := 300
      var ima : image2d := image_new (X, Y)
      var fixsize: int := 16834

      function mul(a : fp, b : fp) : fp = (a*b)/fixsize
      function frac(n : int, d : int) : fp = (n*fixsize)/d

      var xcenter : fp := frac(0016, 10000)
      var ycenter : fp := frac(8224, 10000)
      var xmin : fp := xcenter - frac(5,100)
      var ymin : fp := ycenter - frac(5,100)
      var xmax : fp := xcenter + frac(5,100)
      var ymax : fp := ycenter + frac(5,100)
      var xs   : fp := (xmax - xmin)/X
      var ys   : fp := (ymax - ymin)/Y

    function iterations(x:int, y:int) : int =
    let
        var i : int := 0
        var p : fp := xmin+x*xs
        var q : fp := ymin+y*ys
        var x0 : fp := 0
        var y0 : fp := 0
        var xn : fp := 0
        var four : fp := frac(4,1)
        var two  : fp := frac(2,1)
    in
        while (mul(xn,xn)+mul(y0,y0) < four) & (i < 256) do
        (
            i  := i + 1;
            xn := mul((x0+y0),(x0-y0)) + p;
            y0 := mul(two,mul(x0,y0)) + q;
            x0 := xn
        );
        i
    end

    in

    (for y := 0 to (Y-1) do
        for x := 0 to (X-1) do
            let
                var i : int  := iterations(x,y)
             in
                image_set (ima, x, y, i)
             end);
    end
in
    print("Mandelbrot demo\n");
    mandelbrot()
end