當前位置: 首頁>>代碼示例>>Golang>>正文


Golang draw2d.GraphicContext類代碼示例

本文整理匯總了Golang中github.com/sksullivan/draw2d.GraphicContext的典型用法代碼示例。如果您正苦於以下問題:Golang GraphicContext類的具體用法?Golang GraphicContext怎麽用?Golang GraphicContext使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了GraphicContext類的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Main

// Main draws "Hello World" and returns the filename. This should only be
// used during testing.
func Main(gc draw2d.GraphicContext, ext string) (string, error) {
    // Draw hello world
    Draw(gc, fmt.Sprintf("Hello World %d dpi", gc.GetDPI()))

    // Return the output filename
    return samples.Output("helloworld", ext), nil
}
開發者ID:sksullivan,項目名稱:draw2d,代碼行數:9,代碼來源:helloworld.go

示例2: UseImageWithContext

// UseImageWithContext specifies both an image
// and a graphic context to create the canvas from.
// The minimum point of the given image
// should probably be 0,0.
func UseImageWithContext(img draw.Image, gc draw2d.GraphicContext) option {
    return func(c *Canvas) uint32 {
        c.img = img
        c.gc = gc
        c.dpi = gc.GetDPI()
        return setsDPI | setsSize
    }
}
開發者ID:sksullivan,項目名稱:plot,代碼行數:12,代碼來源:vgimg.go

示例3: Draw

// Draw "Hello World"
func Draw(gc draw2d.GraphicContext, text string) {
    // Draw a rounded rectangle using default colors
    draw2dkit.RoundedRectangle(gc, 5, 5, 135, 95, 10, 10)
    gc.FillStroke()

    // Set the font luximbi.ttf
    gc.SetFontData(draw2d.FontData{Name: "luxi", Family: draw2d.FontFamilyMono, Style: draw2d.FontStyleBold | draw2d.FontStyleItalic})
    // Set the fill text color to black
    gc.SetFillColor(image.Black)
    gc.SetFontSize(14)
    // Display Hello World
    gc.FillStringAt("Hello World", 8, 52)
}
開發者ID:sksullivan,項目名稱:draw2d,代碼行數:14,代碼來源:helloworld.go

示例4: Main

// Main draws the tiger
func Main(gc draw2d.GraphicContext, ext string) (string, error) {
    gc.Save()

    // flip the image
    gc.Translate(0, 200)
    gc.Scale(0.35, -0.35)
    gc.Translate(70, -200)

    // Tiger postscript drawing
    tiger := samples.Resource("image", "tiger.ps", ext)

    // Draw tiger
    Draw(gc, tiger)
    gc.Restore()

    // Return the output filename
    return samples.Output("postscript", ext), nil
}
開發者ID:sksullivan,項目名稱:draw2d,代碼行數:19,代碼來源:postscript.go

示例5: Main

// Main draws a left hand and ear of a gopher. Afterwards it returns
// the filename. This should only be used during testing.
func Main(gc draw2d.GraphicContext, ext string) (string, error) {
    gc.Save()
    gc.Scale(0.5, 0.5)
    // Draw a (partial) gopher
    Draw(gc)
    gc.Restore()

    // Return the output filename
    return samples.Output("gopher", ext), nil
}
開發者ID:sksullivan,項目名稱:draw2d,代碼行數:12,代碼來源:gopher.go

示例6: Draw

// Draw the droid on a certain position.
func Draw(gc draw2d.GraphicContext, x, y float64) {
    // set the fill and stroke color of the droid
    gc.SetFillColor(color.RGBA{0x44, 0xff, 0x44, 0xff})
    gc.SetStrokeColor(color.RGBA{0x44, 0x44, 0x44, 0xff})

    // set line properties
    gc.SetLineCap(draw2d.RoundCap)
    gc.SetLineWidth(5)

    // head
    gc.MoveTo(x+30, y+70)
    gc.ArcTo(x+80, y+70, 50, 50, 180*(math.Pi/180), 180*(math.Pi/180))
    gc.Close()
    gc.FillStroke()
    gc.MoveTo(x+60, y+25)
    gc.LineTo(x+50, y+10)
    gc.MoveTo(x+100, y+25)
    gc.LineTo(x+110, y+10)
    gc.Stroke()

    // left eye
    draw2dkit.Circle(gc, x+60, y+45, 5)
    gc.FillStroke()

    // right eye
    draw2dkit.Circle(gc, x+100, y+45, 5)
    gc.FillStroke()

    // body
    draw2dkit.RoundedRectangle(gc, x+30, y+75, x+30+100, y+75+90, 10, 10)
    gc.FillStroke()
    draw2dkit.Rectangle(gc, x+30, y+75, x+30+100, y+75+80)
    gc.FillStroke()

    // left arm
    draw2dkit.RoundedRectangle(gc, x+5, y+80, x+5+20, y+80+70, 10, 10)
    gc.FillStroke()

    // right arm
    draw2dkit.RoundedRectangle(gc, x+135, y+80, x+135+20, y+80+70, 10, 10)
    gc.FillStroke()

    // left leg
    draw2dkit.RoundedRectangle(gc, x+50, y+150, x+50+20, y+150+50, 10, 10)
    gc.FillStroke()

    // right leg
    draw2dkit.RoundedRectangle(gc, x+90, y+150, x+90+20, y+150+50, 10, 10)
    gc.FillStroke()
}
開發者ID:sksullivan,項目名稱:draw2d,代碼行數:51,代碼來源:android.go

示例7: 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
}
開發者ID:sksullivan,項目名稱:draw2d,代碼行數:27,代碼來源:frameimage.go

示例8: Draw

// Draw a left hand and ear of a gopher using a gc thanks to
// https://github.com/golang-samples/gopher-vector/
func Draw(gc draw2d.GraphicContext) {
    // Initialize Stroke Attribute
    gc.SetLineWidth(3)
    gc.SetLineCap(draw2d.RoundCap)
    gc.SetStrokeColor(color.Black)

    // Left hand
    // <path fill-rule="evenodd" clip-rule="evenodd" fill="#F6D2A2" stroke="#000000" stroke-width="3" stroke-linecap="round" d="
    // M10.634,300.493c0.764,15.751,16.499,8.463,23.626,3.539c6.765-4.675,8.743-0.789,9.337-10.015
    // c0.389-6.064,1.088-12.128,0.744-18.216c-10.23-0.927-21.357,1.509-29.744,7.602C10.277,286.542,2.177,296.561,10.634,300.493"/>
    gc.SetFillColor(color.RGBA{0xF6, 0xD2, 0xA2, 0xff})
    gc.MoveTo(10.634, 300.493)
    rCubicCurveTo(gc, 0.764, 15.751, 16.499, 8.463, 23.626, 3.539)
    rCubicCurveTo(gc, 6.765, -4.675, 8.743, -0.789, 9.337, -10.015)
    rCubicCurveTo(gc, 0.389, -6.064, 1.088, -12.128, 0.744, -18.216)
    rCubicCurveTo(gc, -10.23, -0.927, -21.357, 1.509, -29.744, 7.602)
    gc.CubicCurveTo(10.277, 286.542, 2.177, 296.561, 10.634, 300.493)
    gc.FillStroke()

    // <path fill-rule="evenodd" clip-rule="evenodd" fill="#C6B198" stroke="#000000" stroke-width="3" stroke-linecap="round" d="
    // M10.634,300.493c2.29-0.852,4.717-1.457,6.271-3.528"/>
    gc.MoveTo(10.634, 300.493)
    rCubicCurveTo(gc, 2.29, -0.852, 4.717, -1.457, 6.271, -3.528)
    gc.Stroke()

    // Left Ear
    // <path fill-rule="evenodd" clip-rule="evenodd" fill="#6AD7E5" stroke="#000000" stroke-width="3" stroke-linecap="round" d="
    // M46.997,112.853C-13.3,95.897,31.536,19.189,79.956,50.74L46.997,112.853z"/>
    gc.MoveTo(46.997, 112.853)
    gc.CubicCurveTo(-13.3, 95.897, 31.536, 19.189, 79.956, 50.74)
    gc.LineTo(46.997, 112.853)
    gc.Close()
    gc.Stroke()
}
開發者ID:sksullivan,項目名稱:draw2d,代碼行數:36,代碼來源:gopher.go

示例9: Draw

// Draw a line with an angle with specified line cap and join
func Draw(gc draw2d.GraphicContext, cap draw2d.LineCap, join draw2d.LineJoin,
    x0, y0, x1, y1, offset float64) {
    gc.SetLineCap(cap)
    gc.SetLineJoin(join)

    // Draw thick line
    gc.SetStrokeColor(color.NRGBA{0x33, 0x33, 0x33, 0xFF})
    gc.SetLineWidth(30.0)
    gc.MoveTo(x0, y0)
    gc.LineTo((x0+x1)/2+offset, (y0+y1)/2)
    gc.LineTo(x1, y1)
    gc.Stroke()

    // Draw thin helping line
    gc.SetStrokeColor(color.NRGBA{0xFF, 0x33, 0x33, 0xFF})
    gc.SetLineWidth(2.56)
    gc.MoveTo(x0, y0)
    gc.LineTo((x0+x1)/2+offset, (y0+y1)/2)
    gc.LineTo(x1, y1)
    gc.Stroke()
}
開發者ID:sksullivan,項目名稱:draw2d,代碼行數:22,代碼來源:linecapjoin.go

示例10: Draw

// Draw a gopher head (not rotated)
func Draw(gc draw2d.GraphicContext, x, y, w, h float64) {
    h23 := (h * 2) / 3

    blf := color.RGBA{0, 0, 0, 0xff}          // black
    wf := color.RGBA{0xff, 0xff, 0xff, 0xff}  // white
    nf := color.RGBA{0x8B, 0x45, 0x13, 0xff}  // brown opaque
    brf := color.RGBA{0x8B, 0x45, 0x13, 0x99} // brown transparant
    brb := color.RGBA{0x8B, 0x45, 0x13, 0xBB} // brown transparant

    // round head top
    gc.MoveTo(x, y+h*1.002)
    gc.CubicCurveTo(x+w/4, y-h/3, x+3*w/4, y-h/3, x+w, y+h*1.002)
    gc.Close()
    gc.SetFillColor(brb)
    gc.Fill()

    // rectangle head bottom
    draw2dkit.RoundedRectangle(gc, x, y+h, x+w, y+h+h, h/5, h/5)
    gc.Fill()

    // left ear outside
    draw2dkit.Circle(gc, x, y+h, w/12)
    gc.SetFillColor(brf)
    gc.Fill()

    // left ear inside
    draw2dkit.Circle(gc, x, y+h, 0.5*w/12)
    gc.SetFillColor(nf)
    gc.Fill()

    // right ear outside
    draw2dkit.Circle(gc, x+w, y+h, w/12)
    gc.SetFillColor(brf)
    gc.Fill()

    // right ear inside
    draw2dkit.Circle(gc, x+w, y+h, 0.5*w/12)
    gc.SetFillColor(nf)
    gc.Fill()

    // left eye outside white
    draw2dkit.Circle(gc, x+w/3, y+h23, w/9)
    gc.SetFillColor(wf)
    gc.Fill()

    // left eye black
    draw2dkit.Circle(gc, x+w/3+w/24, y+h23, 0.5*w/9)
    gc.SetFillColor(blf)
    gc.Fill()

    // left eye inside white
    draw2dkit.Circle(gc, x+w/3+w/24+w/48, y+h23, 0.2*w/9)
    gc.SetFillColor(wf)
    gc.Fill()

    // right eye outside white
    draw2dkit.Circle(gc, x+w-w/3, y+h23, w/9)
    gc.Fill()

    // right eye black
    draw2dkit.Circle(gc, x+w-w/3+w/24, y+h23, 0.5*w/9)
    gc.SetFillColor(blf)
    gc.Fill()

    // right eye inside white
    draw2dkit.Circle(gc, x+w-(w/3)+w/24+w/48, y+h23, 0.2*w/9)
    gc.SetFillColor(wf)
    gc.Fill()

    // left tooth
    gc.SetFillColor(wf)
    draw2dkit.RoundedRectangle(gc, x+w/2-w/8, y+h+h/2.5, x+w/2-w/8+w/8, y+h+h/2.5+w/6, w/10, w/10)
    gc.Fill()

    // right tooth
    draw2dkit.RoundedRectangle(gc, x+w/2, y+h+h/2.5, x+w/2+w/8, y+h+h/2.5+w/6, w/10, w/10)
    gc.Fill()

    // snout
    draw2dkit.Ellipse(gc, x+(w/2), y+h+h/2.5, w/6, w/12)
    gc.SetFillColor(nf)
    gc.Fill()

    // nose
    draw2dkit.Ellipse(gc, x+(w/2), y+h+h/7, w/10, w/12)
    gc.SetFillColor(blf)
    gc.Fill()
}
開發者ID:sksullivan,項目名稱:draw2d,代碼行數:89,代碼來源:gopher2.go

示例11: 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
}
開發者ID:sksullivan,項目名稱:draw2d,代碼行數:15,代碼來源:gopher2.go


注:本文中的github.com/sksullivan/draw2d.GraphicContext類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。