# Generate and display the Mandelbrot set BEGIN { # Constants to determine size and coordinates of grid if (!width) width = 600 if (!height) height = 300 min_x = -2.1; max_x = 0.6 min_y = -1.2; max_y = 1.2 iters = 32 # "Colors", from '.' (diverges fastest) to '@' (diverges slowly), # and then ' ' for doesn't diverge within `iters` iterations. colors[0] = "." colors[1] = "-" colors[2] = "+" colors[3] = "*" colors[4] = "%%" colors[5] = "#" colors[6] = "$" colors[7] = "@" colors[8] = " " # Loop from top to bottom, and for each line left to right inc_y = (max_y-min_y) / height inc_x = (max_x-min_x) / width y = min_y for (row=0; row 4) break } # Scale "color" according to how fast it diverged printf colors[int(i*8/iters)] x += inc_x } y += inc_y printf "\n" } }