github.com/benhoyt/goawk@v1.8.1/testdata/tt.x1 (about)

     1  # Generate and display the Mandelbrot set
     2  
     3  BEGIN {
     4      # Constants to determine size and coordinates of grid
     5      width = 600; height = 300
     6      min_x = -2.1; max_x = 0.6
     7      min_y = -1.2; max_y = 1.2
     8      iters = 32
     9  
    10      # "Colors", from '.' (diverges fastest) to '@' (diverges slowly),
    11      # and then ' ' for doesn't diverge within `iters` iterations.
    12      colors[0] = "."
    13      colors[1] = "-"
    14      colors[2] = "+"
    15      colors[3] = "*"
    16      colors[4] = "%%"
    17      colors[5] = "#"
    18      colors[6] = "$"
    19      colors[7] = "@"
    20      colors[8] = " "
    21  
    22      # Loop from top to bottom, and for each line left to right
    23      inc_y = (max_y-min_y) / height
    24      inc_x = (max_x-min_x) / width
    25      y = min_y
    26      for (row=0; row<height; row++) {
    27          x = min_x
    28          for (col=0; col<width; col++) {
    29              zr = zi = 0
    30              for (i=0; i<iters; i++) {
    31                  # Main calculation: z = z^2 + c
    32                  old_zr = zr
    33                  zr = zr*zr - zi*zi + x
    34                  zi = 2*old_zr*zi + y
    35                  # Stop when magnitude is greater than 2
    36                  if (zr*zr + zi*zi > 4) break
    37              }
    38              # Scale "color" according to how fast it diverged
    39              printf colors[int(i*8/iters)]
    40              x += inc_x
    41          }
    42          y += inc_y
    43          printf "\n"
    44      }
    45  }