Change getting started in Readme and godoc
This commit is contained in:
parent
d6d74f19f9
commit
56180d8101
4 changed files with 75 additions and 45 deletions
79
README.md
79
README.md
|
@ -38,47 +38,66 @@ 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
|
||||||
// Initialize the graphic context on an RGBA image
|
package main
|
||||||
dest := image.NewRGBA(image.Rect(0, 0, 297, 210.0))
|
|
||||||
gc := draw2dimg.NewGraphicContext(dest)
|
|
||||||
|
|
||||||
// Set some properties
|
import (
|
||||||
gc.SetFillColor(color.RGBA{0x44, 0xff, 0x44, 0xff})
|
"github.com/llgcode/draw2d/draw2dimg"
|
||||||
gc.SetStrokeColor(color.RGBA{0x44, 0x44, 0x44, 0xff})
|
"image"
|
||||||
gc.SetLineWidth(5)
|
"image/color"
|
||||||
|
)
|
||||||
|
|
||||||
// Draw a closed shape
|
func main() {
|
||||||
gc.MoveTo(10, 10) // should always be called first for a new path
|
// Initialize the graphic context on an RGBA image
|
||||||
gc.LineTo(100, 50)
|
dest := image.NewRGBA(image.Rect(0, 0, 297, 210.0))
|
||||||
gc.QuadCurveTo(100, 10, 10, 10)
|
gc := draw2dimg.NewGraphicContext(dest)
|
||||||
gc.Close()
|
|
||||||
gc.FillStroke()
|
|
||||||
|
|
||||||
// Save to file
|
// Set some properties
|
||||||
draw2dimg.SaveToPngFile("hello.png", dest)
|
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:
|
The same Go code can also generate a pdf document with package draw2dpdf:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
// Initialize the graphic context on an RGBA image
|
package main
|
||||||
dest := draw2dpdf.NewPdf("L", "mm", "A4")
|
|
||||||
gc := draw2dpdf.NewGraphicContext(dest)
|
|
||||||
|
|
||||||
// Set some properties
|
import (
|
||||||
gc.SetFillColor(color.RGBA{0x44, 0xff, 0x44, 0xff})
|
"github.com/llgcode/draw2d/draw2dpdf"
|
||||||
gc.SetStrokeColor(color.RGBA{0x44, 0x44, 0x44, 0xff})
|
"image/color"
|
||||||
gc.SetLineWidth(5)
|
)
|
||||||
|
|
||||||
// Draw a closed shape
|
func main() {
|
||||||
gc.MoveTo(10, 10) // should always be called first for a new path
|
// Initialize the graphic context on an RGBA image
|
||||||
gc.LineTo(100, 50)
|
dest := draw2dpdf.NewPdf("L", "mm", "A4")
|
||||||
gc.QuadCurveTo(100, 10, 10, 10)
|
gc := draw2dpdf.NewGraphicContext(dest)
|
||||||
gc.Close()
|
|
||||||
gc.FillStroke()
|
|
||||||
|
|
||||||
// Save to file
|
// Set some properties
|
||||||
draw2dpdf.SaveToPdfFile("hello.pdf", dest)
|
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
|
There are more examples here: https://github.com/llgcode/draw2d/tree/master/samples
|
||||||
|
|
41
draw2d.go
41
draw2d.go
|
@ -26,24 +26,35 @@
|
||||||
// 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:
|
||||||
// // Initialize the graphic context on an RGBA image
|
// package main
|
||||||
// dest := image.NewRGBA(image.Rect(0, 0, 297, 210.0))
|
|
||||||
// gc := draw2dimg.NewGraphicContext(dest)
|
|
||||||
//
|
//
|
||||||
// // Set some properties
|
// import (
|
||||||
// gc.SetFillColor(color.RGBA{0x44, 0xff, 0x44, 0xff})
|
// "github.com/llgcode/draw2d/draw2dimg"
|
||||||
// gc.SetStrokeColor(color.RGBA{0x44, 0x44, 0x44, 0xff})
|
// "image"
|
||||||
// gc.SetLineWidth(5)
|
// "image/color"
|
||||||
|
// )
|
||||||
//
|
//
|
||||||
// // Draw a closed shape
|
// func main() {
|
||||||
// gc.MoveTo(10, 10) // should always be called first for a new path
|
// // Initialize the graphic context on an RGBA image
|
||||||
// gc.LineTo(100, 50)
|
// dest := image.NewRGBA(image.Rect(0, 0, 297, 210.0))
|
||||||
// gc.QuadCurveTo(100, 10, 10, 10)
|
// gc := draw2dimg.NewGraphicContext(dest)
|
||||||
// gc.Close()
|
//
|
||||||
// gc.FillStroke()
|
// // 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)
|
||||||
|
// }
|
||||||
//
|
//
|
||||||
// // Save to file
|
|
||||||
// draw2d.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 |
Loading…
Reference in a new issue