# Core Concepts

Graphics deals with images, which are, in their simplest form, nothing more than two-dimensional arrays of pixels, containing color information for each pixel:

![](https://www.researchgate.net/profile/Maria_Lyra/publication/221918148/figure/fig1/AS:305071716880384@1449746173231/A-digital-image-is-a-2D-array-of-pixels-Each-pixel-is-characterised-by-its-x-y.png)

[source: ResearchGate](https://www.researchgate.net/figure/A-digital-image-is-a-2D-array-of-pixels-Each-pixel-is-characterised-by-its-x-y_fig1_221918148)

### Image

At the core, there are two main interfaces: `image.Image` and `image/draw.Image`. One serves as a readable image source, the other is used for drawing:

```go
// image.Image
type Image interface {
    ColorModel() color.Model
    Bounds() Rectangle
    At(x, y int) color.Color
}
```

```go
// draw.Image is an image.Image with a Set method to change a single pixel.
type Image interface {
    image.Image
    Set(x, y int, c color.Color)
}
```

### Color

TBA

### Example: Creating a Circular Mask

This example has been taken from [The Go image/draw package | The Go Blog](https://blog.golang.org/image-draw)

```go
type circle struct {
    p image.Point
    r int
}

func (c *circle) ColorModel() color.Model {
    return color.AlphaModel
}

func (c *circle) Bounds() image.Rectangle {
    return image.Rect(c.p.X-c.r, c.p.Y-c.r, c.p.X+c.r, c.p.Y+c.r)
}

func (c *circle) At(x, y int) color.Color {
    xx, yy, rr := float64(x-c.p.X)+0.5, float64(y-c.p.Y)+0.5, float64(c.r)
    if xx*xx+yy*yy < rr*rr {
        return color.Alpha{255}
    }
    return color.Alpha{0}
}
```

## Resources

### Libraries

* [fogleman/gg](https://github.com/fogleman/gg)
