Exemplo n.º 1
0
func (c *myCanvas) Draw(x *canvas.Context) {
	if true {
		x.SetFillStyle(canvas.RGBA{R: 1, A: 1})
		r := r2.Rect{X: 0, Size: 1 + 1i}
		scale := float64(72)

		x.Save()
		x.Scale(r2.XY(scale, scale))
		x.FillRect(r.X, r.Size)
		x.BeginPath()
		x.Arc(r.Size, .5, 0, r2.AngleMax, true)
		x.SetFillStyle(canvas.RGBA{G: 1, A: 1})
		x.Fill()
		x.LineWidth = .1
		x.SetStrokeStyle(canvas.RGBA{A: .25})
		x.Stroke()
		x.Restore()

		x.Save()
		x.SetFillStyle(canvas.RGBA{A: 1})
		x.Font = "24pt Ariel"
		x.Translate(x.Size / 2)
		x.Rotate(r2.AngleMax / 8)
		w := x.MeasureText(c.greeting)
		x.FillText(c.greeting, -w/2)
		x.Restore()
	} else {
		x.Save()
		x.SetStrokeStyle(canvas.RGBA{A: .8})
		x.LineWidth = 2
		for i := 0; i < 1000; i++ {
			z := r2.XY(
				rand.Float64()*x.Size.X(),
				rand.Float64()*x.Size.Y(),
			)
			x.SetFillStyle(canvas.RGBA{G: rand.Float32(), A: 1})
			x.BeginPath()
			x.Arc(z, 4, 0, r2.AngleMax)
			x.Fill()
			x.Stroke()
		}
		x.Restore()
	}
}