mercredi 9 janvier 2019

Web Assembly drawing gray canvas

I'm using Go and compiling it to web assembly.

I'm trying to render a bunch of rectangles next to eachother with a random colour, but they keep rendering as just gray.

My render function looks something like this:

 for row,_ := range rows {
    for col,_ := range row {
        ctx.Set("fillStyle", fmt.Sprintf("#%06x", rand.Int()))
        ctx.Call("fillRect", 20 + (col * width), maxHeight - (row*height))
    }
 }

With which it renders a big block (all rectangles are next to eachother) but just all in gray, instead of doing them in different colours.

Is this enough code in the example to help further? If not I can post it to a gist, as I'm new to WASM I'm unsure which parts could really be relevant - but those 2 functions are the only ones doing something with rendering as far as I can tell.




Aucun commentaire:

Enregistrer un commentaire