//NOT FINISHED package main import ( "image" "image/png" "math/cmplx" "os" ) type Color struct { r uint32 g uint32 b uint32 a uint32 } func (c Color) RGBA() (r, g, b, a uint32) { return c.r, c.g, c.b, c.a } func green() Color { return Color{0, 255, 0, 255} } func blue() Color { return Color{0, 0, 255, 255} } func main() { f, err := os.Create("out.png") if err != nil { os.Exit(1) } const ( xmin, ymin, xmax, ymax = -2, -2, +2, +2 width, height = 1024, 1024 ) img := image.NewRGBA(image.Rect(0, 0, width, height)) for py := 0; py < height; py++ { y := float64(py)/height*(ymax-ymin) + ymin for px := 0; px < width; px++ { x := float64(px)/width*(xmax-xmin) + xmin z := complex(x, y) img.Set(px, py, mandelbrot(z)) } } png.Encode(f, img) f.Close() } func mandelbrot(z complex128) Color { const iterations = 200 const contrast = 15 var v complex128 for n := uint8(0); n < iterations; n++ { v = v*v + z if cmplx.Abs(v) > 2 { return Color{0, uint32(255 - contrast*n), 0, 255} } } return blue() }