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,47 +38,66 @@ Quick Start
The following Go code generates a simple drawing and saves it to an image file with package draw2d:
```go
// Initialize the graphic context on an RGBA image
dest := image.NewRGBA(image.Rect(0, 0, 297, 210.0))
gc := draw2dimg.NewGraphicContext(dest)
package main
// Set some properties
gc.SetFillColor(color.RGBA{0x44, 0xff, 0x44, 0xff})
gc.SetStrokeColor(color.RGBA{0x44, 0x44, 0x44, 0xff})
gc.SetLineWidth(5)
import (
"github.com/llgcode/draw2d/draw2dimg"
"image"
"image/color"
)
// Draw a closed shape
gc.MoveTo(10, 10) // should always be called first for a new path
gc.LineTo(100, 50)
gc.QuadCurveTo(100, 10, 10, 10)
gc.Close()
gc.FillStroke()
func main() {
// Initialize the graphic context on an RGBA image
dest := image.NewRGBA(image.Rect(0, 0, 297, 210.0))
gc := draw2dimg.NewGraphicContext(dest)
// Save to file
draw2dimg.SaveToPngFile("hello.png", dest)
// Set some properties
gc.SetFillColor(color.RGBA{0x44, 0xff, 0x44, 0xff})
gc.SetStrokeColor(color.RGBA{0x44, 0x44, 0x44, 0xff})
gc.SetLineWidth(5)
// Draw a closed shape
gc.MoveTo(10, 10) // should always be called first for a new path
gc.LineTo(100, 50)
gc.QuadCurveTo(100, 10, 10, 10)
gc.Close()
gc.FillStroke()
// Save to file
draw2dimg.SaveToPngFile("hello.png", dest)
}
```
The same Go code can also generate a pdf document with package draw2dpdf:
```go
// Initialize the graphic context on an RGBA image
dest := draw2dpdf.NewPdf("L", "mm", "A4")
gc := draw2dpdf.NewGraphicContext(dest)
package main
// Set some properties
gc.SetFillColor(color.RGBA{0x44, 0xff, 0x44, 0xff})
gc.SetStrokeColor(color.RGBA{0x44, 0x44, 0x44, 0xff})
gc.SetLineWidth(5)
import (
"github.com/llgcode/draw2d/draw2dpdf"
"image/color"
)
// Draw a closed shape
gc.MoveTo(10, 10) // should always be called first for a new path
gc.LineTo(100, 50)
gc.QuadCurveTo(100, 10, 10, 10)
gc.Close()
gc.FillStroke()
func main() {
// Initialize the graphic context on an RGBA image
dest := draw2dpdf.NewPdf("L", "mm", "A4")
gc := draw2dpdf.NewGraphicContext(dest)
// Save to file
draw2dpdf.SaveToPdfFile("hello.pdf", dest)
// Set some properties
gc.SetFillColor(color.RGBA{0x44, 0xff, 0x44, 0xff})
gc.SetStrokeColor(color.RGBA{0x44, 0x44, 0x44, 0xff})
gc.SetLineWidth(5)
// Draw a closed shape
gc.MoveTo(10, 10) // should always be called first for a new path
gc.LineTo(100, 50)
gc.QuadCurveTo(100, 10, 10, 10)
gc.Close()
gc.FillStroke()
// Save to file
draw2dpdf.SaveToPdfFile("hello.pdf", dest)
}
```
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
// graphics and text on an image canvas. The following Go code
// 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
// dest := image.NewRGBA(image.Rect(0, 0, 297, 210.0))
// gc := draw2dimg.NewGraphicContext(dest)
@ -43,7 +52,9 @@
// gc.FillStroke()
//
// // Save to file
// draw2d.SaveToPngFile("hello.png", dest)
// draw2dimg.SaveToPngFile("hello.png", dest)
// }
//
//
// There are more examples here:
// 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