func makeStone(name string, circleMask *image.Alpha) (*image.RGBA, *image.Alpha) { stone := get(name, stoneSize0) dst := image.NewRGBA(stone.Bounds()) // Make the whole area black, for the shadow. draw.Draw(dst, dst.Bounds(), image.Black, ZP, draw.Src) // Lay in the stone within the circle so it shows up inside the shadow. draw.DrawMask(dst, dst.Bounds(), stone, ZP, circleMask, ZP, draw.Over) return dst, makeShadowMask(stone) }
func (ig *ImageGraphics) Text(x, y int, t string, align string, rot int, f chart.Font) { if len(align) == 1 { align = "c" + align } var col color.Color if f.Color != nil { col = f.Color } else { col = color.RGBA{0, 0, 0, 0xff} } textImage := ig.textBox(t, f, col) bounds := textImage.Bounds() w, h := bounds.Dx(), bounds.Dy() var centerX, centerY int if rot != 0 { alpha := float64(rot) / 180 * math.Pi cos := math.Cos(alpha) sin := math.Sin(alpha) ax, ay := float64(w), float64(h) // anchor point switch align[0] { case 'b': case 'c': ay /= 2 case 't': ay = 0 } switch align[1] { case 'l': ax = 0 case 'c': ax /= 2 case 'r': } dx := float64(ax)*cos + float64(ay)*sin dy := -float64(ax)*sin + float64(ay)*cos trans := f64.Aff3{ +cos, +sin, float64(x+ig.x0) - dx, -sin, +cos, float64(y+ig.y0) - dy, } draw.BiLinear.Transform(ig.Image, trans, textImage, textImage.Bounds(), draw.Over, nil) return } else { centerX, centerY = w/2, h/2 switch align[0] { case 'b': centerY = h case 't': centerY = 0 } switch align[1] { case 'l': centerX = 0 case 'r': centerX = w } } bounds = textImage.Bounds() w, h = bounds.Dx(), bounds.Dy() x -= centerX y -= centerY x += ig.x0 y += ig.y0 tcol := image.NewUniform(col) draw.DrawMask(ig.Image, image.Rect(x, y, x+w, y+h), tcol, image.ZP, textImage, textImage.Bounds().Min, draw.Over) }
func (b *Board) drawPiece(m *image.RGBA, ij IJ, piece *Piece) { xy := ij.XYStone(&b.Dims) xy = xy.Add(piece.delta) draw.DrawMask(m, xy, piece.stone.image, ZP, piece.stone.mask, ZP, draw.Over) }