Пример #1
0
func main() {
	dom.OnDOMContentLoaded(func() {
		s := dom.GetElementById("gopherjs")
		style := dom.GetComputedStyle(s)

		el := canvas.New(dom.CreateElement("canvas").Object)
		cw, _ = strconv.ParseFloat(style.GetPropertyValue("width")[:3], 64)
		ch, _ = strconv.ParseFloat(style.GetPropertyValue("height")[:3], 64)
		el.Width = int(cw)
		el.Height = int(ch)
		el.AddEventListener(dom.EvtMousemove, func(e *dom.Event) {
			e.PreventDefault()
			x := float64(e.LayerX)
			y := float64(e.LayerY)
			makeParticles(x, y, 5)
		})
		ctx = el.GetContext2D()
		ctx.GlobalCompositeOperation = canvas.CompositeLighter
		s.AppendChild(el.Element)
		raf.RequestAnimationFrame(run)
	})
}
Пример #2
0
func main() {
	dom.OnDOMContentLoaded(func() {
		s := dom.Body()
		// set full window and black background
		s.Style.SetProperty("margin", "0")
		s.Style.SetProperty("background", "#222")

		el := canvas.New(dom.CreateElement("canvas").Object)
		cw = float64(dom.Window().InnerWidth)
		ch = float64(dom.Window().InnerHeight)
		el.Width = int(cw)
		el.Height = int(ch)
		el.AddEventListener(dom.EvtMousemove, func(e *dom.Event) {
			e.PreventDefault()
			x := float64(e.ClientX)
			y := float64(e.ClientY)
			makeParticles(x, y, 5)
		})
		ctx = el.GetContext2D()
		ctx.GlobalCompositeOperation = canvas.CompositeLighter
		dom.Body().AppendChild(el.Element)
		raf.RequestAnimationFrame(run)
	})
}