-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path11_raw_pixels3.go
More file actions
54 lines (48 loc) · 1.19 KB
/
11_raw_pixels3.go
File metadata and controls
54 lines (48 loc) · 1.19 KB
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
// Seriál "Programovací jazyk Go"
// https://www.root.cz/serialy/programovaci-jazyk-go/
//
// Čtrnáctá část
// Programovací jazyk Go a počítačová grafika (úvod)
// https://www.root.cz/clanky/programovaci-jazyk-go-a-pocitacova-grafika-uvod/
//
// Repositář:
// https://github.com/tisnik/go-root/
//
// Seznam demonstračních příkladů ze čtrnácté části:
// https://github.com/tisnik/go-root/blob/master/article_14/README.md
//
// Demonstrační příklad číslo 11:
// Přímý přístup k jednotlivým pixelům; třetí varianta
//
// Dokumentace ve stylu "literate programming":
// https://tisnik.github.io/go-root/article_14/11_raw_pixels3.html
package main
import (
"image"
"image/png"
"os"
)
const width = 256
const height = 256
func main() {
img := image.NewNRGBA(image.Rect(0, 0, width, height))
outfile, err := os.Create("11.png")
if err != nil {
panic(err)
}
defer outfile.Close()
for y := 0; y < height; y++ {
index := img.PixOffset(0, y)
for x := 0; x < width; x++ {
img.Pix[index] = 0
index++
img.Pix[index] = 0
index++
img.Pix[index] = 255
index++
img.Pix[index] = byte(x)
index++
}
}
png.Encode(outfile, img)
}