// Written by xojoc . Public domain. package main import ( "image" "image/color" "image/png" "math/cmplx" "os" ) const ( w = 700 h = 500 maxi = 50 ) func main() { img := image.NewRGBA(image.Rect(0, 0, w, h)) // Where the mandelbrot set intersects the x,y axis. setx := -2.5 sety := -1.0 // width/height of the set. setw := 3.5 seth := 2.0 for y := 0; y < h; y++ { for x := 0; x < w; x++ { // Scale in the range (-2.5,1.0) for x and (-1.0,1.0) for y. c := complex(float64(x)/float64(w)*setw+setx, float64(y)/float64(h)*seth+sety) z := 0i i := 0 for ; cmplx.Abs(z) < 2 && i < maxi; i++ { z = cmplx.Pow(z, 2) + c } if i == maxi { // Point is bounded. img.Set(x, y, color.Black) } else { // Point escapes to infinity. img.Set(x, y, color.Transparent) } } } png.Encode(os.Stdout, img) }