Exemple #1
0
func drawClockPane(ctx *canvas.CanvasRenderingContext2D, r int) {
	ctx.Save()
	// cycle
	ctx.StrokeStyle = "black"
	ctx.LineWidth = 4
	ctx.BeginPath()
	ctx.Arc(0, 0, r, 0., float32(2*math.Pi), true)
	ctx.ClosePath()
	ctx.Stroke()
	// hour tick
	itv := 2 * math.Pi / 12.0
	r0 := float64(r - 10)
	r1 := float64(r)
	for i := 0; i < 12; i++ {
		angle := float64(i) * itv
		ctx.MoveTo(int(r0*math.Sin(angle)), int(r0*math.Cos(angle)))
		ctx.LineTo(int(r1*math.Sin(angle)), int(r1*math.Cos(angle)))
		ctx.Stroke()
	}
	// minute tick
	ctx.LineWidth = 2
	itv = 2 * math.Pi / 60.0
	r0 = float64(r - 5)
	r1 = float64(r)
	for i := 0; i < 60; i++ {
		angle := float64(i) * itv
		ctx.MoveTo(int(r0*math.Sin(angle)), int(r0*math.Cos(angle)))
		ctx.LineTo(int(r1*math.Sin(angle)), int(r1*math.Cos(angle)))
		ctx.Stroke()
	}
	ctx.Restore()
}