Пример #1
0
func main() {
	surf := cairo.ImageSurfaceCreate(cairo.FormatRGB24, 640, 480)
	cr := cairo.Create(surf.Surface)

	cr.Arc(320, 240, 40, 0, math.Pi)
	path := cr.CopyPath()
	iter := path.Iter()
	for seg := iter.Next(); seg != nil; seg = iter.Next() {
		log.Printf("seg %s %#v", seg.Type, seg)
	}
}
Пример #2
0
func demo() (success bool) {
	defer func() {
		if err := recover(); err != nil {
			log.Println("recovered error:", err)
			success = true
		}
	}()

	// Normally you should use one of the cairo.FormatXXX constants, but
	// this program is demonstrating a panic.
	cairo.ImageSurfaceCreate(cairo.Format(1000), 640, 480)
	return
}
Пример #3
0
func main() {
	size := 320
	margin := 10
	innerSize := size - (margin * 2)
	step := 15

	surf := cairo.ImageSurfaceCreate(cairo.FormatARGB32, size, size)
	cr := cairo.Create(surf.Surface)

	cr.SetSourceRGB(1, 1, 1)
	cr.Paint()

	cr.SetAntialias(cairo.AntialiasBest)
	// Offset by 0.5 to get pixel-aligned lines.
	cr.Translate(float64(margin)+0.5, float64(margin)+0.5)
	cr.SetSourceRGB(0, 0, 0)
	cr.SetLineWidth(1)
	for i := 0; i <= innerSize; i += step {
		cr.MoveTo(0, float64(i))
		cr.LineTo(float64(i), float64(innerSize))
		cr.Stroke()

		cr.MoveTo(float64(i), 0)
		cr.LineTo(float64(innerSize), float64(i))
		cr.Stroke()
	}
	surf.Flush()

	f, err := os.Create("example.png")
	if err != nil {
		panic(err)
	}
	defer f.Close()
	err = surf.WriteToPNG(f)
	if err != nil {
		panic(err)
	}
}