28 lines
617 B
Go
28 lines
617 B
Go
package draw
|
|
|
|
import (
|
|
"image/color"
|
|
"image/draw"
|
|
"math"
|
|
)
|
|
|
|
func Progress(dst Image, c color.Color, x, y, w int, progress float64) {
|
|
Rectangle(dst, c, x, y, w, 8)
|
|
if fill := int(math.Round(float64(w) * progress)); fill > 0 {
|
|
FilledRectangle(dst, c, x+1, y+1, fill, 6)
|
|
}
|
|
}
|
|
|
|
func Sprite(dst draw.Image, c color.Color, x, y int, sprite []uint8) {
|
|
w, h, data := sprite[0], sprite[1], sprite[2:]
|
|
for dy := 0; dy < int(h); dy++ {
|
|
for dx := 0; dx < int(w); dx++ {
|
|
byteOffset := int(dy/8)*int(w) + dx
|
|
bitOffset := dy % 8
|
|
if data[byteOffset]&(1<<bitOffset) != 0 {
|
|
dst.Set(x+dx, y+dy, c)
|
|
}
|
|
}
|
|
}
|
|
}
|