package main import ( "fmt" "os" "strconv" ) const xmin float64 = -2.0 const xmax float64 = 1.0 const ymin float64 = -1.0 const ymax float64 = 1.0 func escapes(cr float64, ci float64, it int) rune { var zr float64 = 0 var zi float64 = 0 var zrtmp float64 for i := 0; i < it; i++ { // z <- z^2 + c zrtmp = zr*zr - zi*zi + cr zi = 2*zr*zi + ci zr = zrtmp if zr*zr+zi*zi > 4 { return ' ' } } return 'X' } func main() { var x, y float64 xstep, _ := strconv.Atoi(os.Args[1]) ystep, _ := strconv.Atoi(os.Args[2]) iters, _ := strconv.Atoi(os.Args[3]) for yc := 0; yc < ystep; yc++ { y = float64(yc)*(ymax-ymin)/float64(ystep) + ymin for xc := 0; xc < xstep; xc++ { x = float64(xc)*(xmax-xmin)/float64(xstep) + xmin fmt.Print(string(escapes(x, y, iters))) } fmt.Println() } }