Groups
Sign in
Groups
GopherJS
Conversations
Labels
About
Send feedback
Help
Draw in Canvas
131 views
Skip to first unread message
Александр Синотов
unread,
May 26, 2016, 7:44:39 PM
5/26/16
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to GopherJS
Hello there!
I have a problem with drawing in canvas from GopherJS.
Without much
preamble:
[q.go]
package main
import (
"
github.com/gopherjs/gopherjs/js
"
)
func Test() {
document := js.Global.Get("document")
cnvs := document.Call("getElementById", "cnvs")
ctx := cnvs.Call("getContext", "2d")
imgData := ctx.Call("createImageData", 128, 128)
for i := 0; i < 128 * 128; i++ {
data := imgData.Call("data")
pD := i * 4
data.SetIndex(pD + 0, 0xff)
data.SetIndex(pD + 1, 0)
data.SetIndex(pD + 2, 0)
data.SetIndex(pD + 3, 0xff)
}
}
func main() {
js.Global.Set("miejs", map[string]interface{}{
"Test": Test,
})
}
[/q.go]
[q.html]
<html>
<head>
<meta charset="utf-8">
<title>MieJS</title>
<script src="q.js" type="text/javascript"></script>
</head>
<body>
<canvas id="cnvs" height="128" width="128"></canvas>
</body>
</html>
[/q.html]
And nothing.
Rusco
unread,
May 27, 2016, 4:40:21 AM
5/27/16
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to GopherJS
Have a look (I renamed your file to canvas.go):
https://play.golang.org/p/dTBftXbVro
Александр Синотов
unread,
May 27, 2016, 10:39:47 AM
5/27/16
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to GopherJS
Thanks a lot!
Reply all
Reply to author
Forward
0 new messages