-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path04_gg_alpha_component.go
More file actions
56 lines (43 loc) · 1.36 KB
/
04_gg_alpha_component.go
File metadata and controls
56 lines (43 loc) · 1.36 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
55
56
// Seriál "Programovací jazyk Go"
// https://www.root.cz/serialy/programovaci-jazyk-go/
//
// Šestnáctá část
// Programovací jazyk Go a grafika: další užitečné funkce poskytované knihovnou GG
// https://www.root.cz/clanky/programovaci-jazyk-go-a-grafika-dalsi-uzitecne-funkce-poskytovane-knihovnou-gg/
//
// Repositář:
// https://github.com/tisnik/go-root/
//
// Seznam demonstračních příkladů ze šestnácté části:
// https://github.com/tisnik/go-root/blob/master/article_16/README.md
//
// Demonstrační příklad číslo 4:
// Alfa kanál v barvovém prostoru RGBA.
//
// Dokumentace ve stylu "literate programming":
// https://tisnik.github.io/go-root/article_16/04_gg_alpha_component.html
package main
import "github.com/fogleman/gg"
func main() {
const width = 320
const height = 240
dc := gg.NewContext(width, height)
dc.DrawRectangle(0, 0, width, height/2)
dc.SetRGB(1.0, 1.0, 1.0)
dc.Fill()
dc.DrawRectangle(0, height/2, width, height)
dc.SetRGB(0.0, 0.0, 0.0)
dc.Fill()
for i := 0; i < 256; i += 8 {
x := float64(i + 32)
// průhlednost je hodnota v rozsahu 0.0 až 1.0
alpha := float64(i) / 256.0
dc.SetRGBA(0.0, 0.0, 0.0, alpha)
dc.DrawLine(x, 20, x, height/2-20)
dc.Stroke()
dc.SetRGBA(1.0, 1.0, 1.0, alpha)
dc.DrawLine(x, height/2+20, x, height-20)
dc.Stroke()
}
dc.SavePNG("04.png")
}