liveBook · Manning

RGBA color

As explained in Learn Go with Pocket-Sized Projects

RGBA is a color representation that specifies red, green, blue, and alpha channels for each pixel.

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

How Learn Go with Pocket-Sized Projects covers it

How deep it goes
Explains channel representation, Go accessors, comparisons, writing, and palette design, but defers other color models.
Examples
Demonstrates maze walls, paths, entrances, treasure, and solutions as named RGBA palette entries.
What it assumes
Assumes familiarity with Go structures and image files while teaching pixel grids, channel values, and palette organization.
What you can do after
Apply it via Go image APIs to inspect, compare, classify, and modify raster-image pixels.
How it connects
Connects RGBA color with raster images, image.Image, image.RGBA, NRGBA, color.Color, and PNG encoding.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Go with Pocket-Sized Projects. The section links point to the parts of the book it draws on.