diff options
Diffstat (limited to 'mandelbrot.go')
| -rw-r--r-- | mandelbrot.go | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/mandelbrot.go b/mandelbrot.go index 482850a..686625b 100644 --- a/mandelbrot.go +++ b/mandelbrot.go @@ -2,8 +2,23 @@ package main import ( "fmt" + "os" + "syscall" + "unsafe" ) +func terminalSize() (cols int, lines int, err error) { + const tiocgwinsz uintptr = 21523 + + ts := new(struct { + wsRow, wsCol, wsXPixel, wsYPixel uint16 + }) + if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, 1, tiocgwinsz, uintptr(unsafe.Pointer(ts))); err != 0 { + return 0, 0, err + } + return int(ts.wsCol), int(ts.wsRow), nil +} + func mandelbrot(x0, y0 float64) int { var x, y, x2, y2 float64 for i := 0; i < 1000; i++ { @@ -24,13 +39,16 @@ func main() { xRange = 2.47 yMin = -1.12 yRange = 2.24 + ) - width = 80 - height = 25 + width, height, err := terminalSize() + if err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } - xStep = xRange / float64(width) - yStep = yRange / float64(height) - ) + xStep := xRange / float64(width) + yStep := yRange / float64(height) y := yMin for i := 0; i < height; i++ { |
