-
Notifications
You must be signed in to change notification settings - Fork 0
/
palette.go
78 lines (65 loc) · 2.15 KB
/
palette.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// (c) 2023 Jacek Olszak
// This code is licensed under MIT license (see LICENSE for details)
package pi
import "github.com/elgopher/pi/image"
// Palette has all colors available in the game. Up to 256.
// Palette is taken from loaded sprite sheet (which must be
// a PNG file with indexed color mode). If sprite-sheet.png was not
// found, then default 16 color palette is used.
//
// Can be freely read and updated when the game is running. Changes will be visible immediately.
var Palette [256]image.RGB = defaultPalette
// Palette swapping variables. Use them to generate new graphics by swapping colors.
var (
// Pal (draw palette) contains mapping of colors used to replace color with
// another one for all subsequent drawings. Affected functions are:
// Set, Spr, SprSize, SprSizeFlip, Circ, CircFill, Line, Rect and RectFill.
//
// The index of array is original color, the value is the color replacement.
// For example,
//
// pi.Pal[7] = 0
//
// will change color 7 to 0.
Pal PalMapping
// Pald (display palette), a mapping of colors used to replace color with
// another one for the entire screen, at the end of a frame.
//
// The index of array is original color, the value is color replacement.
// For example,
//
// pi.Pald[7] = 0
//
// will change color 7 to 0.
Pald PalMapping
)
type PalMapping [256]byte
// Reset resets all swapped colors to defaults (no swapping).
func (p *PalMapping) Reset() {
*p = notSwappedPalette
}
// Palt contains information whether given color is transparent.
// If true then the color will not be drawn for next drawing operations.
// Color transparency is used by Spr, SprSize and SprSizeFlip.
//
// The index of array is a color number. For example,
//
// pi.Palt[7] = true
//
// will make color 7 transparent.
var Palt Transparency = defaultTransparency
var notSwappedPalette [256]byte
func init() {
for i := 0; i < 256; i++ {
c := byte(i)
notSwappedPalette[i] = c
Pal[i] = c
Pald[i] = c
}
}
var defaultTransparency = Transparency{true}
type Transparency [256]bool
// Reset sets all transparent colors to false and makes color 0 transparent.
func (p *Transparency) Reset() {
*p = defaultTransparency
}