func makeBall(b ball) Ball { img := canvas.Box(ballSize, ballSize, image.NewUniform(b.col), 1, image.Black) p := b.p.point().Sub(image.Pt(ballSize/2, ballSize/2)) item := canvas.NewImage(img, true, p) window.AddItem(item) window.Raise(item, nil, false) return Ball{item} }
func clear() { bbox := cvs.Bbox() output = image.NewRGBA(bbox) for i := 0; i < bbox.Dx(); i++ { for j := 0; j < bbox.Dy(); j++ { output.Set(i, j, color.RGBA{0, 0, 0, 0xff}) } } cvs.AddItem(canvas.NewImage(output, true, image.Point{X: 0, Y: 0})) }
func paint() { world.Lock() cvs.AddItem(canvas.NewImage(output, true, image.Point{X: 0, Y: 0})) cvs.Flush() world.Unlock() }
func makeRect(r image.Rectangle, col color.Color) { img := canvas.Box(r.Dx(), r.Dy(), image.NewUniform(col), 1, image.Black) item := canvas.NewImage(img, opaqueColor(col), r.Min) window.AddItem(canvas.Draggable(item)) }