当前位置: 首页>>代码示例>>Golang>>正文


Golang PngCanvas.SetLineWidth方法代码示例

本文整理汇总了Golang中github.com/gonum/plot/vg/vgimg.PngCanvas.SetLineWidth方法的典型用法代码示例。如果您正苦于以下问题:Golang PngCanvas.SetLineWidth方法的具体用法?Golang PngCanvas.SetLineWidth怎么用?Golang PngCanvas.SetLineWidth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/gonum/plot/vg/vgimg.PngCanvas的用法示例。


在下文中一共展示了PngCanvas.SetLineWidth方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestGraphicGrobs

func TestGraphicGrobs(t *testing.T) {
	// Output
	file, err := os.Create("grobs.png")
	if err != nil {
		t.Fatalf("%", err)
	}

	pngCanvas := vgimg.PngCanvas{Canvas: vgimg.New(10*vg.Inch, 8*vg.Inch)}
	vg.Initialize(pngCanvas)
	pngCanvas.Translate(-5*vg.Inch, -4*vg.Inch)
	dot := func(x, y float64) {
		pngCanvas.Push()
		pngCanvas.SetColor(BuiltinColors["red"])
		pngCanvas.SetLineWidth(5)
		var p vg.Path
		xr := vg.Length(x) * vg.Inch
		yr := vg.Length(y) * vg.Inch
		p.Move(xr-5, yr-5)
		p.Line(xr-5, yr+5)
		p.Line(xr+5, yr+5)
		p.Line(xr+5, yr-5)
		p.Close()
		pngCanvas.Fill(p)
		pngCanvas.Pop()
	}

	dot(0, 0)
	dot(5, 0)
	dot(0, 4)

	allVP := Viewport{
		X0:     0,
		Y0:     0,
		Width:  10 * vg.Inch,
		Height: 8 * vg.Inch,
		Canvas: pngCanvas,
	}
	innerVP := allVP.Sub(0.05, 0.05, 0.9, 0.9)
	bg := GrobRect{xmin: 0, ymin: 0, xmax: 1, ymax: 1, fill: BuiltinColors["gray80"]}
	bg.Draw(innerVP)

	cols := []string{"red", "green", "blue", "cyan", "magenta", "yellow",
		"white", "gray", "black"}

	// Draw points in all shapes, three sizes and all builtin colors.
	points := []Grob{}
	x, y := 0.1, 0.1
	for shape := DotPoint; shape <= StarPoint; shape++ {
		for size := 2; size < 7; size += 2 {
			y = 0.05
			for _, col := range cols {
				g := GrobPoint{
					x:     x,
					y:     y,
					size:  float64(size),
					shape: shape,
					color: BuiltinColors[col],
				}
				points = append(points, g)
				y += 0.035
			}
			x += 0.021
		}
	}
	x, y = 0.02, 0.05
	for _, col := range cols {
		g := GrobText{
			x:     x,
			y:     y,
			text:  col,
			size:  10,
			color: BuiltinColors[col],
			vjust: 0.5,
			hjust: 0,
		}
		points = append(points, g)
		y += 0.035
	}
	x, y = 0.121, 0.36
	for shape := DotPoint; shape <= StarPoint; shape++ {
		dy := float64(shape%2) * 0.015
		g := GrobText{
			x:     x,
			y:     y + dy,
			text:  shape.String(),
			size:  10,
			color: BuiltinColors["black"],
			vjust: 0.5,
			hjust: 0.5,
		}
		points = append(points, g)
		x += 3 * 0.021
	}
	for _, grob := range points {
		grob.Draw(innerVP)
	}

	// Draw lines with different styles and widths.
	lines := []Grob{}
	x, y = 0.1, 0.45
//.........这里部分代码省略.........
开发者ID:vdobler,项目名称:plot,代码行数:101,代码来源:grob_test.go


注:本文中的github.com/gonum/plot/vg/vgimg.PngCanvas.SetLineWidth方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。