RGBA represents each pixel with red, green, blue, and alpha channels. In Go, it is provided as color.RGBA in the image/color package. section 9.3.1 section 9.7
Use RGBA values to inspect, compare, and modify raster-image pixels:
- Read pixels through image.Image.At, converting the returned color.Color to color.RGBA. section 9.7
- Read image.RGBA pixels directly with RGBAAt and compare them with known colors. section 9.7
- Write a color to image.RGBA with Set(x, y, rgba). section 9.7
Encoding maze categories
A maze solver stores wall, path, entrance, treasure, and solution colors in a palette. For example, a wall can be color.RGBA{R: 0, G: 0, B: 0, A: 255}, while an entrance can be color.RGBA{R: 0, G: 191, B: 255, A: 255}. The solver compares RGBAAt values with the palette to find the entrance. section 9.3.1
Listing 9.7 palette.go: Declaring the list of colors
// palette contains the colours of the different types of pixels in our maze.
type palette struct {
wall color.RGBA
path color.RGBA #1
entrance color.RGBA #2
treasure color.RGBA
solution color.RGBA #3
}
Inspect the palette structure used to keep named RGBA values together. section 9.3.1
