@@ -8,31 +8,42 @@ import (
8
8
"github.com/setanarut/apng"
9
9
)
10
10
11
- const FrameCount int = 40
11
+ const FrameCount int = 30
12
12
13
13
func main () {
14
-
15
14
frames := make ([]image.Image , FrameCount )
15
+ // frames2 := make([]image.Image, FrameCount)
16
+
16
17
for i := range FrameCount {
17
- frames [i ] = generateNoiseImage (600 , 200 )
18
+ frames [i ] = generatePalettedFrames (600 , 200 )
19
+ // frames2[i] = generateRGBAFrames(600, 200)
18
20
}
19
- apng .Save ("out.png" , frames , 3 )
21
+ apng .Save ("outPaletted.png" , frames , 7 )
22
+ // apng.Save("outRGBA.png", frames2, 7)
20
23
}
21
24
22
- func generateNoiseImage (width , height int ) * image.RGBA {
25
+ func generateRGBAFrames (width , height int ) * image.RGBA {
23
26
img := image .NewRGBA (image .Rect (0 , 0 , width , height ))
24
27
for y := range height {
25
28
for x := range width {
26
- col := noisePalette [rand .IntN (4 )]
27
- img .SetRGBA (x , y , col )
29
+ c := plt [rand .IntN (3 )]
30
+ img .SetRGBA (x , y , c .(color.RGBA ))
31
+ }
32
+ }
33
+ return img
34
+ }
35
+ func generatePalettedFrames (width , height int ) * image.Paletted {
36
+ img := image .NewPaletted (image .Rect (0 , 0 , width , height ), plt )
37
+ for y := range height {
38
+ for x := range width {
39
+ img .SetColorIndex (x , y , uint8 (rand .IntN (3 )))
28
40
}
29
41
}
30
42
return img
31
43
}
32
44
33
- var noisePalette = []color.RGBA {
34
- {R : 0 , G : 0 , B : 0 , A : 255 }, // Black
35
- {R : 255 , G : 0 , B : 0 , A : 255 }, // Red
36
- {R : 0 , G : 255 , B : 0 , A : 255 }, // Green
37
- {R : 0 , G : 0 , B : 255 , A : 255 }, // Blue
45
+ var plt = []color.Color {
46
+ color.RGBA {R : 0 , G : 0 , B : 0 , A : 255 }, // Black
47
+ color.RGBA {R : 255 , G : 255 , B : 255 , A : 255 }, // White
48
+ color.RGBA {R : 255 , G : 0 , B : 255 , A : 255 }, // White
38
49
}
0 commit comments