-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
fire.go
76 lines (70 loc) · 1.96 KB
/
fire.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
// http://fabiensanglard.net/doom_fire_psx/
package fire
import (
"image"
"image/color"
"math/rand"
)
type Fire struct {
*image.Paletted
}
func New(w, h int) *Fire {
r := image.Rect(0, 0, w, h)
img := image.NewPaletted(r, palette)
b := r.Bounds().Max
for x := 0; x < b.X; x++ {
img.SetColorIndex(x, b.Y-1, uint8(len(palette)-1))
}
return &Fire{Paletted: img}
}
func (f *Fire) Next() {
b := f.Bounds().Max
for x := 0; x < b.X; x++ {
for y := b.Y - 1; y > 0; y-- {
z := rand.Intn(3) - 1 // -1, 0, 1
n := f.ColorIndexAt(x, y)
if n > 0 && z == 0 {
n-- // next color
}
f.SetColorIndex(x+z, y-1, n)
}
}
}
var palette = color.Palette{
color.RGBA{0x07, 0x07, 0x07, 0xff},
color.RGBA{0x1f, 0x07, 0x07, 0xff},
color.RGBA{0x2f, 0x0f, 0x07, 0xff},
color.RGBA{0x47, 0x0f, 0x07, 0xff},
color.RGBA{0x57, 0x17, 0x07, 0xff},
color.RGBA{0x67, 0x1f, 0x07, 0xff},
color.RGBA{0x77, 0x1f, 0x07, 0xff},
color.RGBA{0x8f, 0x27, 0x07, 0xff},
color.RGBA{0x9f, 0x2f, 0x07, 0xff},
color.RGBA{0xaf, 0x3f, 0x07, 0xff},
color.RGBA{0xbf, 0x47, 0x07, 0xff},
color.RGBA{0xc7, 0x47, 0x07, 0xff},
color.RGBA{0xdf, 0x4f, 0x07, 0xff},
color.RGBA{0xdf, 0x57, 0x07, 0xff},
color.RGBA{0xdf, 0x57, 0x07, 0xff},
color.RGBA{0xd7, 0x5f, 0x07, 0xff},
color.RGBA{0xd7, 0x67, 0x0f, 0xff},
color.RGBA{0xcf, 0x6f, 0x0f, 0xff},
color.RGBA{0xcf, 0x77, 0x0f, 0xff},
color.RGBA{0xcf, 0x7f, 0x0f, 0xff},
color.RGBA{0xcf, 0x87, 0x17, 0xff},
color.RGBA{0xc7, 0x87, 0x17, 0xff},
color.RGBA{0xc7, 0x8f, 0x17, 0xff},
color.RGBA{0xc7, 0x97, 0x1f, 0xff},
color.RGBA{0xbf, 0x9f, 0x1f, 0xff},
color.RGBA{0xbf, 0x9f, 0x1f, 0xff},
color.RGBA{0xbf, 0xa7, 0x27, 0xff},
color.RGBA{0xbf, 0xa7, 0x27, 0xff},
color.RGBA{0xbf, 0xaf, 0x2f, 0xff},
color.RGBA{0xb7, 0xaf, 0x2f, 0xff},
color.RGBA{0xb7, 0xb7, 0x2f, 0xff},
color.RGBA{0xb7, 0xb7, 0x37, 0xff},
color.RGBA{0xcf, 0xcf, 0x6f, 0xff},
color.RGBA{0xdf, 0xdf, 0x9f, 0xff},
color.RGBA{0xef, 0xef, 0xc7, 0xff},
color.RGBA{0xff, 0xff, 0xff, 0xff},
}