Merge pull request #52 from stanim/doc

improve README.md
This commit is contained in:
Laurent Le Goff 2015-07-09 16:12:14 +02:00
commit ed5fa0e5a7
2 changed files with 86 additions and 16 deletions

View File

@ -1,12 +1,14 @@
draw2d draw2d
====== ======
Package draw2d is a pure [go](http://golang.org) 2D vector graphics library with support for multiple output devices such as [images](http://golang.org/pkg/image) (draw2d), pdf documents (draw2dpdf) and opengl (draw2dopengl), which can also be used on the google app engine. Package draw2d is a pure [go](http://golang.org) 2D vector graphics library with support for multiple output devices such as [images](http://golang.org/pkg/image) (draw2d), pdf documents (draw2dpdf) and opengl (draw2dopengl), which can also be used on the google app engine. It can be used as a pure go [Cairo](http://www.cairographics.org/) alternative.
This library is inspired by [postscript](http://www.tailrecursive.org/postscript) and [HTML5 canvas](http://www.w3.org/TR/2dcontext/).
See the [documentation](http://godoc.org/github.com/llgcode/draw2d) for more details. See the [documentation](http://godoc.org/github.com/llgcode/draw2d) for more details.
The package depends on [freetype-go](http://code.google.com/p/freetype-go) package for its rasterization algorithm. Features
--------
Operations in draw2d include stroking and filling polygons, arcs, Bézier curves, drawing images and text rendering with truetype fonts. All drawing operations can be transformed by affine transformations (scale, rotation, translation).
Installation Installation
------------ ------------
@ -17,14 +19,75 @@ Install [golang](http://golang.org/doc/install). To install or update the packag
go get -u github.com/llgcode/draw2d go get -u github.com/llgcode/draw2d
``` ```
and start coding using one of the [Samples](https://github.com/llgcode/draw2d.samples). 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 := draw2d.NewGraphicContext(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
draw2d.SaveToPngFile(fn, 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 := draw2d.NewGraphicContext(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(fn, dest)
```
There are more examples here: https://github.com/llgcode/draw2d.samples
Drawing on opengl is provided by the draw2dgl package.
Acknowledgments
---------------
[Laurent Le Goff](https://github.com/llgcode) wrote this library, inspired by [Postscript](http://www.tailrecursive.org/postscript) and [HTML5 canvas](http://www.w3.org/TR/2dcontext/). He implemented the image and opengl backend with the [freetype-go](https://code.google.com/p/freetype-go/) package. Also he created a pure go [Postscript interpreter](https://github.com/llgcode/ps), which can read postscript images and draw to a draw2d graphic context. [Stani Michiels](https://github.com/stanim) implemented the pdf backend with the [gofpdf](https://github.com/jung-kurt/gofpdf) package.
Softwares and Packages using draw2d
-----------------------------------
- [golang postscript interpreter](https://github.com/llgcode/ps) Packages using draw2d
- [gonum plot](https://github.com/gonum/plot) ---------------------
- [ps](https://github.com/llgcode/ps): Postscript interpreter written in Go
- [gonum/plot](https://github.com/gonum/plot): drawing plots in Go
- [go.uik](https://github.com/skelterjohn/go.uik): a concurrent UI kit written in pure go.
- [smartcrop](https://github.com/muesli/smartcrop): content aware image cropping
- [karta](https://github.com/peterhellberg/karta): drawing Voronoi diagrams
- [chart](https://github.com/vdobler/chart): basic charts in Go
References References
--------- ---------

View File

@ -4,7 +4,7 @@
// Package draw2d is a pure go 2D vector graphics library with support // Package draw2d is a pure go 2D vector graphics library with support
// for multiple output devices such as images (draw2d), pdf documents // for multiple output devices such as images (draw2d), pdf documents
// (draw2dpdf) and opengl (draw2dopengl), which can also be used on the // (draw2dpdf) and opengl (draw2dopengl), which can also be used on the
// google app engine. // google app engine. It can be used as a pure go Cairo alternative.
// //
// Features // Features
// //
@ -51,18 +51,25 @@
// //
// Acknowledgments // Acknowledgments
// //
// Laurent Le Goff wrote this library, inspired by postscript and // Laurent Le Goff wrote this library, inspired by Postscript and
// HTML5 canvas. He implemented the image and opengl backend. Also // HTML5 canvas. He implemented the image and opengl backend with the
// he created a pure go Postscripter interpreter which can draw to a // freetype-go package. Also he created a pure go Postscript
// draw2d graphic context (https://github.com/llgcode/ps). Stani // interpreter, which can read postscript images and draw to a draw2d
// Michiels implemented the pdf backend. // graphic context (https://github.com/llgcode/ps). Stani Michiels
// implemented the pdf backend with the gofpdf package.
// //
// The package depends on freetype-go package for its rasterization // The package depends on freetype-go package for its rasterization
// algorithm. // algorithm.
// //
// Packages using draw2d // Packages using draw2d
// //
// - https://github.com/llgcode/ps // - https://github.com/llgcode/ps: Postscript interpreter written in Go
// //
// - https://github.com/gonum/plot // - https://github.com/gonum/plot: drawing plots in Go
//
// - https://github.com/muesli/smartcrop: content aware image cropping
//
// - https://github.com/peterhellberg/karta: drawing Voronoi diagrams
//
// - https://github.com/vdobler/chart: basic charts in Go
package draw2d package draw2d