本文整理匯總了Golang中github.com/julianshen/draw2d.GraphicContext.Rotate方法的典型用法代碼示例。如果您正苦於以下問題:Golang GraphicContext.Rotate方法的具體用法?Golang GraphicContext.Rotate怎麽用?Golang GraphicContext.Rotate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/julianshen/draw2d.GraphicContext
的用法示例。
在下文中一共展示了GraphicContext.Rotate方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Draw
// Draw the image frame with certain parameters.
func Draw(gc draw2d.GraphicContext, png string,
dw, dh, margin, lineWidth float64) error {
// Draw frame
draw2dkit.RoundedRectangle(gc, lineWidth, lineWidth, dw-lineWidth, dh-lineWidth, 100, 100)
gc.SetLineWidth(lineWidth)
gc.FillStroke()
// load the source image
source, err := draw2dimg.LoadFromPngFile(png)
if err != nil {
return err
}
// Size of source image
sw, sh := float64(source.Bounds().Dx()), float64(source.Bounds().Dy())
// Draw image to fit in the frame
// TODO Seems to have a transform bug here on draw image
scale := math.Min((dw-margin*2)/sw, (dh-margin*2)/sh)
gc.Save()
gc.Translate((dw-sw*scale)/2, (dh-sh*scale)/2)
gc.Scale(scale, scale)
gc.Rotate(0.2)
gc.DrawImage(source)
gc.Restore()
return nil
}
示例2: Main
// Main draws a rotated face of the gopher. Afterwards it returns
// the filename. This should only be used during testing.
func Main(gc draw2d.GraphicContext, ext string) (string, error) {
gc.SetStrokeColor(image.Black)
gc.SetFillColor(image.White)
gc.Save()
// Draw a (partial) gopher
gc.Translate(-60, 65)
gc.Rotate(-30 * (math.Pi / 180.0))
Draw(gc, 48, 48, 240, 72)
gc.Restore()
// Return the output filename
return samples.Output("gopher2", ext), nil
}
示例3: Star
// Star draws many lines from a center.
func Star(gc draw2d.GraphicContext, x, y, width, height float64) {
gc.Save()
gc.Translate(x+width/2, y+height/2)
gc.SetLineWidth(width / 40)
for i := 0.0; i < 360; i = i + 10 { // Go from 0 to 360 degrees in 10 degree steps
gc.Save() // Keep rotations temporary
gc.Rotate(i * (math.Pi / 180.0)) // Rotate by degrees on stack from 'for'
gc.MoveTo(0, 0)
gc.LineTo(width/2, 0)
gc.Stroke()
gc.Restore()
}
gc.Restore()
}