-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdraw_into_canvas.go
45 lines (36 loc) · 1.13 KB
/
draw_into_canvas.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
// Seriál "Programovací jazyk Go"
// https://www.root.cz/serialy/programovaci-jazyk-go/
//
// Devatenáctá část
// Využití WebAssembly z programovacího jazyka Go
// https://www.root.cz/clanky/vyuziti-webassembly-z-programovaciho-jazyka-go/
//
// Repositář:
// https://github.com/tisnik/go-root/
//
// Seznam demonstračních příkladů z devatenácté části:
// https://github.com/tisnik/go-root/blob/master/article_19/README.md
//
// Demonstrační příklad:
// Kreslení na Canvas.
package main
import (
"syscall/js"
)
func main() {
const CanvasWidth = 256
const CanvasHeight = 256
println("started")
window := js.Global()
document := window.Get("document")
canvas := document.Call("createElement", "canvas")
canvas.Set("height", CanvasWidth)
canvas.Set("width", CanvasHeight)
document.Get("body").Call("appendChild", canvas)
context2d := canvas.Call("getContext", "2d")
context2d.Set("fillStyle", "#c0c0c0")
context2d.Call("fillRect", 0, 0, CanvasWidth, CanvasHeight)
context2d.Set("fillStyle", "yellow")
context2d.Call("fillRect", 10, 10, CanvasWidth-20, CanvasHeight-20)
println("finished")
}