func clear(s draw.Image) { b := s.Bounds() for i := b.Min.X; i < b.Max.X; i++ { for j := b.Min.Y; j < b.Max.Y; j++ { s.Set(i, j, black) } } }
func plot(s draw.Image, v []Point) { clear(s) min, max := scale(v) b := s.Bounds() xscale := float64(b.Max.X-b.Min.X) / (max.x - min.x) * Shrink yscale := float64(b.Max.Y-b.Min.Y) / (max.y - min.y) * Shrink xoffset := -(min.x * xscale) + 4 yoffset := -(min.y * yscale) + 4 for _, p := range v { x := int(xscale*p.x + xoffset) y := int(yscale*p.y + yoffset) if x < 0 || y < 0 { fmt.Println(min, max) fmt.Println(x, y) fmt.Println(p.x, xscale, xoffset) fmt.Println(p.y, yscale, yoffset) } s.Set(x, y, Color) } }