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


Golang vg.Inches函數代碼示例

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


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

示例1: TestArcsEPS

func TestArcsEPS() {
	eps := vgeps.New(vg.Inches(4), vg.Inches(4), "arcs")
	DrawArcs(eps)
	if err := eps.Save("arcs.eps"); err != nil {
		panic(err)
	}
}
開發者ID:vron,項目名稱:plotinum,代碼行數:7,代碼來源:main.go

示例2: crosshair

// crosshair draws a plus at the given point.
func crosshair(img draw.Image, x, y int, str string) {
	c := vgimg.NewImage(img)

	// drawPlots here because NewImage
	// clears the canvas.  Instead, the canvas
	// should just be stored instead of being
	// recreated at each redraw.
	drawPlots(img)

	c.SetColor(color.RGBA{R: 255, A: 255})

	xc := vg.Inches(float64(x) / c.DPI())
	yc := vg.Inches(float64(y) / c.DPI())
	radius := vg.Points(5)

	var p vg.Path
	p.Move(xc-radius, yc)
	p.Line(xc+radius, yc)
	c.Stroke(p)

	p = vg.Path{}
	p.Move(xc, yc+radius)
	p.Line(xc, yc-radius)
	c.Stroke(p)

	c.SetColor(color.Black)
	c.FillString(font, vg.Length(0), vg.Length(0), str)
}
開發者ID:vivounicorn,項目名稱:eaburns,代碼行數:29,代碼來源:main.go

示例3: TestFontsPDF

func TestFontsPDF() {
	pdf := vgpdf.New(vg.Inches(4), vg.Inches(4))
	DrawFonts(pdf)
	if err := pdf.Save("fonts.pdf"); err != nil {
		panic(err)
	}
}
開發者ID:vron,項目名稱:plotinum,代碼行數:7,代碼來源:main.go

示例4: DrawFontExtents

// DrawFontExtents draws some text and denotes the
// various extents and width with lines. Expects
// about a 4x4 inch canvas.
func DrawFontExtents(c vg.Canvas) {
	x, y := vg.Inches(1), vg.Inches(2)
	str := "Eloquent"
	font, err := vg.MakeFont("Times-Roman", 18)
	if err != nil {
		panic(err)
	}
	width := font.Width(str)
	ext := font.Extents()
	des := ext.Descent
	asc := ext.Ascent

	c.FillString(font, x, y, str)

	// baseline
	path := vg.Path{}
	path.Move(x, y)
	path.Line(x+width, y)
	c.Stroke(path)

	// descent
	c.SetColor(color.RGBA{G: 255, A: 255})
	path = vg.Path{}
	path.Move(x, y+des)
	path.Line(x+width, y+des)
	c.Stroke(path)

	// ascent
	c.SetColor(color.RGBA{B: 255, A: 255})
	path = vg.Path{}
	path.Move(x, y+asc)
	path.Line(x+width, y+asc)
	c.Stroke(path)
}
開發者ID:vron,項目名稱:plotinum,代碼行數:37,代碼來源:main.go

示例5: TestFontExtentsEPS

func TestFontExtentsEPS() {
	eps := vgeps.New(vg.Inches(4), vg.Inches(4), "extents")
	DrawFontExtents(eps)
	if err := eps.Save("extents.eps"); err != nil {
		panic(err)
	}
}
開發者ID:vron,項目名稱:plotinum,代碼行數:7,代碼來源:main.go

示例6: TestArcsPDF

func TestArcsPDF() {
	pdf := vgpdf.New(vg.Inches(4), vg.Inches(4))
	DrawArcs(pdf)
	if err := pdf.Save("arcs.pdf"); err != nil {
		panic(err)
	}
}
開發者ID:vron,項目名稱:plotinum,代碼行數:7,代碼來源:main.go

示例7: TestArcsSVG

func TestArcsSVG() {
	img := vgsvg.New(vg.Inches(4), vg.Inches(4))
	DrawArcs(img)
	err := img.Save("arcs.svg")
	if err != nil {
		panic(err)
	}
}
開發者ID:vron,項目名稱:plotinum,代碼行數:8,代碼來源:main.go

示例8: TestFontsSVG

func TestFontsSVG() {
	img := vgsvg.New(vg.Inches(4), vg.Inches(4))
	DrawFonts(img)
	err := img.Save("fonts.svg")
	if err != nil {
		panic(err)
	}
}
開發者ID:vron,項目名稱:plotinum,代碼行數:8,代碼來源:main.go

示例9: TestArcsIMG

func TestArcsIMG() {
	img, err := vgimg.New(vg.Inches(4), vg.Inches(4))
	if err != nil {
		panic(err)
	}
	DrawArcs(img)
	err = img.Save("arcs.png", png.Encode)
	if err != nil {
		panic(err)
	}
}
開發者ID:vron,項目名稱:plotinum,代碼行數:11,代碼來源:main.go

示例10: TestFontExtentsIMG

func TestFontExtentsIMG() {
	img, err := vgimg.New(vg.Inches(4), vg.Inches(4))
	if err != nil {
		panic(err)
	}
	DrawFontExtents(img)
	err = img.Save("extents.png", png.Encode)
	if err != nil {
		panic(err)
	}
}
開發者ID:vron,項目名稱:plotinum,代碼行數:11,代碼來源:main.go

示例11: Save

//Save saves the board (i.e. all subplots, appropriately laid out) to the specified filename.
//It basically rips off the implementation of Save in plotinum to support various file formats.
func (b *Board) Save(width, height float64, file string) (err error) {
	w, h := vg.Inches(width), vg.Inches(height)
	var c interface {
		vg.Canvas
		Size() (w, h vg.Length)
		io.WriterTo
	}
	switch ext := strings.ToLower(filepath.Ext(file)); ext {

	case ".eps":
		c = vgeps.NewTitle(w, h, file)

	case ".jpg", ".jpeg":
		c = vgimg.JpegCanvas{Canvas: vgimg.New(w, h)}

	case ".pdf":
		c = vgpdf.New(w, h)

	case ".png":
		c = vgimg.PngCanvas{Canvas: vgimg.New(w, h)}

	case ".svg":
		c = vgsvg.New(w, h)

	case ".tiff":
		c = vgimg.TiffCanvas{Canvas: vgimg.New(w, h)}

	default:
		return fmt.Errorf("Unsupported file extension: %s", ext)
	}

	for _, subplot := range b.SubPlots {
		w, h := c.Size()
		drawArea := plot.DrawArea{
			Canvas: c,
			Rect:   subplot.ScaledRect(float64(w), float64(h)),
		}

		subplot.Plot.Draw(drawArea)
	}

	f, err := os.Create(file)
	if err != nil {
		return err
	}
	if _, err = c.WriteTo(f); err != nil {
		return err
	}

	say.Println(0, say.Yellow("Saved %s", file))
	return f.Close()
}
開發者ID:ematpl,項目名稱:analyzer,代碼行數:54,代碼來源:board.go

示例12: Example_functions

// Example_functions draws some functions.
func Example_functions() *plot.Plot {
	p, err := plot.New()
	if err != nil {
		panic(err)
	}
	p.Title.Text = "Functions"
	p.X.Label.Text = "X"
	p.Y.Label.Text = "Y"

	quad := plotter.NewFunction(func(x float64) float64 { return x * x })
	quad.Color = color.RGBA{B: 255, A: 255}

	exp := plotter.NewFunction(func(x float64) float64 { return math.Pow(2, x) })
	exp.Dashes = []vg.Length{vg.Points(2), vg.Points(2)}
	exp.Width = vg.Points(2)
	exp.Color = color.RGBA{G: 255, A: 255}

	sin := plotter.NewFunction(func(x float64) float64 { return 10*math.Sin(x) + 50 })
	sin.Dashes = []vg.Length{vg.Points(4), vg.Points(5)}
	sin.Width = vg.Points(4)
	sin.Color = color.RGBA{R: 255, A: 255}

	p.Add(quad, exp, sin)
	p.Legend.Add("x^2", quad)
	p.Legend.Add("2^x", exp)
	p.Legend.Add("10*sin(x)+50", sin)
	p.Legend.ThumbnailWidth = vg.Inches(0.5)

	p.X.Min = 0
	p.X.Max = 10
	p.Y.Min = 0
	p.Y.Max = 100
	return p
}
開發者ID:jen6,項目名稱:plotinum,代碼行數:35,代碼來源:main.go

示例13: NewImage

// NewImage returns a new image canvas
// that draws to the given image.  The
// minimum point of the given image
// should probably be 0,0.
func NewImage(img draw.Image) *Canvas {
	w := float64(img.Bounds().Max.X - img.Bounds().Min.X)
	h := float64(img.Bounds().Max.Y - img.Bounds().Min.Y)
	draw.Draw(img, img.Bounds(), image.White, image.ZP, draw.Src)
	gc := draw2d.NewGraphicContext(img)
	gc.SetDPI(dpi)
	gc.Scale(1, -1)
	gc.Translate(0, -h)
	c := &Canvas{
		gc:    gc,
		img:   img,
		w:     vg.Inches(w / dpi),
		h:     vg.Inches(h / dpi),
		color: []color.Color{color.Black},
	}
	vg.Initialize(c)
	return c
}
開發者ID:jen6,項目名稱:plotinum,代碼行數:22,代碼來源:vgimg.go

示例14: Save

// Save saves the plot to an image file.  Width and height
// are specified in inches, and the file format is determined
// by the extension.  Supported extensions are
// .eps, .jpg, .jpeg, .pdf, .png, .svg, and .tiff.
func (p *Plot) Save(width, height float64, file string) (err error) {
	w, h := vg.Inches(width), vg.Inches(height)
	var c interface {
		vg.Canvas
		Size() (w, h vg.Length)
		io.WriterTo
	}
	switch ext := strings.ToLower(filepath.Ext(file)); ext {

	case ".eps":
		c = vgeps.NewTitle(w, h, file)

	case ".jpg", ".jpeg":
		c = vgimg.JpegCanvas{Canvas: vgimg.New(w, h)}

	case ".pdf":
		c = vgpdf.New(w, h)

	case ".png":
		c = vgimg.PngCanvas{Canvas: vgimg.New(w, h)}

	case ".svg":
		c = vgsvg.New(w, h)

	case ".tiff":
		c = vgimg.TiffCanvas{Canvas: vgimg.New(w, h)}

	default:
		return fmt.Errorf("Unsupported file extension: %s", ext)
	}
	p.Draw(MakeDrawArea(c))

	f, err := os.Create(file)
	if err != nil {
		return err
	}
	if _, err = c.WriteTo(f); err != nil {
		return err
	}
	return f.Close()
}
開發者ID:jen6,項目名稱:plotinum,代碼行數:45,代碼來源:plot.go

示例15: dataCoord

// dataCoord returns the plot number and data
// coordinate of a screen coordinate.  A negative
// plot numbers means that the screen coordinate
// is not in the data area of any plot.
func dataCoord(x, y int) (int, float64, float64) {
	dpi := ps[0].dataArea.DPI()
	pt := plot.Point{
		X: vg.Inches(float64(x) / dpi),
		Y: vg.Inches(float64(y) / dpi),
	}
	for i, p := range ps {
		if p.dataArea.Contains(pt) {
			da := p.dataArea
			x := float64((pt.X - da.Min.X) / (da.Max().X - da.Min.X))
			x *= (p.plot.X.Max - p.plot.X.Min)
			x += p.plot.X.Min

			y := float64((pt.Y - da.Min.Y) / (da.Max().Y - da.Min.Y))
			y *= (p.plot.Y.Max - p.plot.Y.Min)
			y += p.plot.Y.Min
			return i, x, y
		}
	}
	return -1, 0, 0
}
開發者ID:vivounicorn,項目名稱:eaburns,代碼行數:25,代碼來源:main.go


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