-
Notifications
You must be signed in to change notification settings - Fork 0
/
arena_image.go
35 lines (30 loc) · 1004 Bytes
/
arena_image.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package main
import (
"image"
"image/color"
"image/draw"
)
// Source data for a PNG image of the current state of the arena.
type ArenaImage struct {
Filename string
Width int
Height int
PixelsPerCell int
Image *image.RGBA
}
func NewArenaImage(name string, width, height, pixelsPerCell int) *ArenaImage {
return &ArenaImage{
name, width, height, pixelsPerCell,
image.NewRGBA(image.Rect(0, 0, width * pixelsPerCell, height * pixelsPerCell)),
}
}
// Fills in a single cell of the arena grid.
func (img *ArenaImage) DrawCell(x, y int, cellColor color.RGBA) {
rect := image.Rect(x * img.PixelsPerCell, y * img.PixelsPerCell, (x + 1) * img.PixelsPerCell, (y + 1) * img.PixelsPerCell)
img.DrawRect(rect, cellColor)
}
// Draws an arbitrary rectangle of a solid color on the image. Doesn't respect opacity.
func (img *ArenaImage) DrawRect(rect image.Rectangle, cellColor color.RGBA) {
swatch := image.NewUniform(cellColor)
draw.Draw(img.Image, rect, swatch, image.Point{0, 0}, draw.Src)
}