Change getting started in Readme and godoc

This commit is contained in:
llgcode 2015-10-08 15:58:39 +02:00
parent d6d74f19f9
commit 56180d8101
4 changed files with 75 additions and 45 deletions

View file

@ -38,6 +38,15 @@ Quick Start
The following Go code generates a simple drawing and saves it to an image file with package draw2d: The following Go code generates a simple drawing and saves it to an image file with package draw2d:
```go ```go
package main
import (
"github.com/llgcode/draw2d/draw2dimg"
"image"
"image/color"
)
func main() {
// Initialize the graphic context on an RGBA image // Initialize the graphic context on an RGBA image
dest := image.NewRGBA(image.Rect(0, 0, 297, 210.0)) dest := image.NewRGBA(image.Rect(0, 0, 297, 210.0))
gc := draw2dimg.NewGraphicContext(dest) gc := draw2dimg.NewGraphicContext(dest)
@ -56,11 +65,20 @@ gc.FillStroke()
// Save to file // Save to file
draw2dimg.SaveToPngFile("hello.png", dest) draw2dimg.SaveToPngFile("hello.png", dest)
}
``` ```
The same Go code can also generate a pdf document with package draw2dpdf: The same Go code can also generate a pdf document with package draw2dpdf:
```go ```go
package main
import (
"github.com/llgcode/draw2d/draw2dpdf"
"image/color"
)
func main() {
// Initialize the graphic context on an RGBA image // Initialize the graphic context on an RGBA image
dest := draw2dpdf.NewPdf("L", "mm", "A4") dest := draw2dpdf.NewPdf("L", "mm", "A4")
gc := draw2dpdf.NewGraphicContext(dest) gc := draw2dpdf.NewGraphicContext(dest)
@ -79,6 +97,7 @@ gc.FillStroke()
// Save to file // Save to file
draw2dpdf.SaveToPdfFile("hello.pdf", dest) draw2dpdf.SaveToPdfFile("hello.pdf", dest)
}
``` ```
There are more examples here: https://github.com/llgcode/draw2d/tree/master/samples There are more examples here: https://github.com/llgcode/draw2d/tree/master/samples

View file

@ -26,6 +26,15 @@
// Package draw2d itself provides a graphic context that can draw vector // Package draw2d itself provides a graphic context that can draw vector
// graphics and text on an image canvas. The following Go code // graphics and text on an image canvas. The following Go code
// generates a simple drawing and saves it to an image file: // generates a simple drawing and saves it to an image file:
// package main
//
// import (
// "github.com/llgcode/draw2d/draw2dimg"
// "image"
// "image/color"
// )
//
// func main() {
// // Initialize the graphic context on an RGBA image // // Initialize the graphic context on an RGBA image
// dest := image.NewRGBA(image.Rect(0, 0, 297, 210.0)) // dest := image.NewRGBA(image.Rect(0, 0, 297, 210.0))
// gc := draw2dimg.NewGraphicContext(dest) // gc := draw2dimg.NewGraphicContext(dest)
@ -43,7 +52,9 @@
// gc.FillStroke() // gc.FillStroke()
// //
// // Save to file // // Save to file
// draw2d.SaveToPngFile("hello.png", dest) // draw2dimg.SaveToPngFile("hello.png", dest)
// }
//
// //
// There are more examples here: // There are more examples here:
// https://github.com/llgcode/draw2d/tree/master/samples // https://github.com/llgcode/draw2d/tree/master/samples

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 41 KiB

After

Width:  |  Height:  |  Size: 41 KiB