package numbers import ( "github.com/veandco/go-sdl2/sdl" ) const width = 60 func drawDigit(surface *sdl.Surface, d int, x, y int32) error { const ( height = 100 thickness = 10 ) white := sdl.MapRGB(surface.Format, 245, 245, 245) switch d { case 0: surface.FillRect(&sdl.Rect{X: x, Y: y, W: width, H: thickness}, white) surface.FillRect(&sdl.Rect{X: x + width - thickness, Y: y, W: thickness, H: height}, white) surface.FillRect(&sdl.Rect{X: x, Y: y, W: thickness, H: height}, white) surface.FillRect(&sdl.Rect{X: x, Y: y + height - thickness, W: width, H: thickness}, white) case 1: surface.FillRect(&sdl.Rect{X: x + width - thickness, Y: y, W: thickness, H: height}, white) case 2: surface.FillRect(&sdl.Rect{X: x, Y: y, W: width, H: thickness}, white) surface.FillRect(&sdl.Rect{X: x + width - thickness, Y: y, W: thickness, H: height / 2}, white) surface.FillRect(&sdl.Rect{X: x, Y: y + height/2 - thickness/2, W: width, H: thickness}, white) surface.FillRect(&sdl.Rect{X: x, Y: y + height/2, W: thickness, H: height / 2}, white) surface.FillRect(&sdl.Rect{X: x, Y: y + height - thickness, W: width, H: thickness}, white) case 3: surface.FillRect(&sdl.Rect{X: x, Y: y, W: width, H: thickness}, white) surface.FillRect(&sdl.Rect{X: x + width - thickness, Y: y, W: thickness, H: height}, white) surface.FillRect(&sdl.Rect{X: x, Y: y + height/2 - thickness/2, W: width, H: thickness}, white) surface.FillRect(&sdl.Rect{X: x, Y: y + height - thickness, W: width, H: thickness}, white) case 4: surface.FillRect(&sdl.Rect{X: x, Y: y, W: thickness, H: height / 2}, white) surface.FillRect(&sdl.Rect{X: x, Y: y + height/2 - thickness/2, W: width, H: thickness}, white) surface.FillRect(&sdl.Rect{X: x + width - thickness, Y: y, W: thickness, H: height}, white) case 5: surface.FillRect(&sdl.Rect{X: x, Y: y, W: width, H: thickness}, white) surface.FillRect(&sdl.Rect{X: x, Y: y, W: thickness, H: height / 2}, white) surface.FillRect(&sdl.Rect{X: x, Y: y + height/2 - thickness/2, W: width, H: thickness}, white) surface.FillRect(&sdl.Rect{X: x + width - thickness, Y: y + height/2, W: thickness, H: height / 2}, white) surface.FillRect(&sdl.Rect{X: x, Y: y + height - thickness, W: width, H: thickness}, white) case 6: surface.FillRect(&sdl.Rect{X: x, Y: y, W: width, H: thickness}, white) surface.FillRect(&sdl.Rect{X: x, Y: y, W: thickness, H: height}, white) surface.FillRect(&sdl.Rect{X: x, Y: y + height/2 - thickness/2, W: width, H: thickness}, white) surface.FillRect(&sdl.Rect{X: x + width - thickness, Y: y + height/2, W: thickness, H: height / 2}, white) surface.FillRect(&sdl.Rect{X: x, Y: y + height - thickness, W: width, H: thickness}, white) case 7: surface.FillRect(&sdl.Rect{X: x, Y: y, W: width, H: thickness}, white) surface.FillRect(&sdl.Rect{X: x + width - thickness, Y: y, W: thickness, H: height}, white) case 8: surface.FillRect(&sdl.Rect{X: x, Y: y, W: thickness, H: height}, white) surface.FillRect(&sdl.Rect{X: x, Y: y, W: width, H: thickness}, white) surface.FillRect(&sdl.Rect{X: x + width - thickness, Y: y, W: thickness, H: height}, white) surface.FillRect(&sdl.Rect{X: x, Y: y + height/2 - thickness/2, W: width, H: thickness}, white) surface.FillRect(&sdl.Rect{X: x, Y: y + height - thickness, W: width, H: thickness}, white) case 9: surface.FillRect(&sdl.Rect{X: x, Y: y, W: thickness, H: height / 2}, white) surface.FillRect(&sdl.Rect{X: x, Y: y, W: width, H: thickness}, white) surface.FillRect(&sdl.Rect{X: x + width - thickness, Y: y, W: thickness, H: height}, white) surface.FillRect(&sdl.Rect{X: x, Y: y + height/2 - thickness/2, W: width, H: thickness}, white) surface.FillRect(&sdl.Rect{X: x, Y: y + height - thickness, W: width, H: thickness}, white) default: panic("invalid digit") } return nil } func Draw(surface *sdl.Surface, n int, x, y int32) error { const padding = 20 if n == 0 { return drawDigit(surface, 0, x, y) } digits := make([]int, 0, 19) for ; n > 0; n /= 10 { digits = append(digits, n%10) } for i := len(digits) - 1; i >= 0; i-- { if err := drawDigit(surface, digits[i], x, y); err != nil { return err } x += width + padding } return nil }