diff --git a/GettingStarted.md b/GettingStarted.md index 8d0bc44..c4b636a 100644 --- a/GettingStarted.md +++ b/GettingStarted.md @@ -1,7 +1,7 @@ ## Getting Started -see http://code.google.com/p/draw2d/source/browse/cmd/gettingStarted.go -Writing to a png file +Draw2d Hello World, initialize a graphic context on a image and save it in apng file. + ```go package main @@ -17,40 +17,50 @@ import ( "image/png" ) -func saveToPngFile(filePath string, m image.Image) error { - // Create the file - f, err := os.Create(filePath) - if err != nil { - return err - } - defer f.Close() - // Create Writer from file - b := bufio.NewWriter(f) - // Write the image into the buffer - err = png.Encode(b, m) - if err != nil { - return err - } - err = b.Flush() - if err != nil { - return err - } - return nil -} func main() { - i := image.NewRGBA(image.Rect(0, 0, 200, 200)) - gc := draw2d.NewGraphicContext(i) - gc.MoveTo(10.0, 10.0) - gc.LineTo(100.0, 10.0) - gc.Stroke() - filePath := "TestPath.png" - saveToPngFile(filePath, i) - fmt.Printf("Wrote %s OK.\n", filePath) + // Create a 200x200 RGBA image + img := image.NewRGBA(image.Rect(0, 0, 200, 200)) + // Initialize a graphic context on this image + gc := draw2d.NewGraphicContext(img) + // Create a new path + gc.BeginPath() + // start the path at (10, 10) + gc.MoveTo(10.0, 10.0) + // add a lineto the path to (100.0, 10.0) + gc.LineTo(100.0, 10.0) + // Stroke + gc.Stroke() + // Save image to disk + filePath := "TestGettingStarted.png" + saveToPngFile(filePath, img) + fmt.Printf("Wrote %s OK.\n", filePath) } +// Save image to a file path using PNG format +func saveToPngFile(filePath string, m image.Image) error { + // Create the file + f, err := os.Create(filePath) + if err != nil { + return err + } + defer f.Close() + // Create Writer from file + b := bufio.NewWriter(f) + // Write the image into the buffer + err = png.Encode(b, m) + if err != nil { + return err + } + err = b.Flush() + if err != nil { + return err + } + return nil +} + + ``` -# Where to go next # -Now you are ready to start using the draw2d package. Go to [Samples](Samples.md) or [GettingStartedGUI](GettingStartedGUI.md). +See [Samples](Samples) to go further. diff --git a/Samples.md b/Samples.md index 910e709..7e723fa 100644 --- a/Samples.md +++ b/Samples.md @@ -1,24 +1,15 @@ -# Test results # +### Test results + -You can find samples here generated by these program: -> http://code.google.com/p/draw2d/source/browse/cmd/testdraw2d.go Those samples are largely inspired by this page: > http://cairographics.org/samples/ -Please see the corresponding HTML canvas, Postscript and svg results from [ajstarks](http://groups.google.com/group/golang-nuts/browse_thread/thread/62288215d63e263a/6d1159b2f965289c#6d1159b2f965289c) (for comparison purpose): - * http://draw2d.googlecode.com/hg/resource/image/Tests.html - * http://draw2d.googlecode.com/hg/resource/image/test.js - * http://draw2d.googlecode.com/hg/resource/image/Tests.ps - * http://www.flickr.com/photos/ajstarks/5207943227/ -There's already some bugs please refer to [issue tracking](http://code.google.com/p/draw2d/issues/list) +## Test Rectangle +![test_results/TestRectangle.png](test_results/TestPath.png) - - -## Test Path ## -![http://draw2d.googlecode.com/hg/resource/result/TestPath.png](http://draw2d.googlecode.com/hg/resource/result/TestPath.png) -``` -func TestPath() { +```go +func TestRectangle() { i, gc := initGc(w, h) gc.MoveTo(10.0, 10.0) gc.LineTo(100.0, 10.0) @@ -26,14 +17,14 @@ func TestPath() { gc.LineTo(10.0, 100.0) gc.LineTo(10.0, 10.0) gc.FillStroke() - saveToPngFile("TestPath", i) + saveToPngFile("TestRectangle", i) } ``` +## Test Draw Arc +![test_results/TestDrawArc.png](test_results/TestDrawArc.png) -## Test Draw Arc ## -![http://draw2d.googlecode.com/hg/resource/result/TestDrawArc.png](http://draw2d.googlecode.com/hg/resource/result/TestDrawArc.png) -``` +```go func TestDrawArc() { i, gc := initGc(w, h) // draw an arc @@ -63,9 +54,11 @@ func TestDrawArc() { } ``` -## Test Draw Arc Negative ## -![http://draw2d.googlecode.com/hg/resource/result/TestDrawArcNegative.png](http://draw2d.googlecode.com/hg/resource/result/TestDrawArcNegative.png) -``` +## Test Draw Arc Negative +![test_results/TestDrawArcNegative.png](test_results/TestDrawArcNegative.png) + + +```go func TestDrawArcNegative() { i, gc := initGc(w, h) // draw an arc @@ -95,9 +88,10 @@ func TestDrawArcNegative() { } ``` -## Test Curve Rectangle ## -![http://draw2d.googlecode.com/hg/resource/result/TestCurveRectangle.png](http://draw2d.googlecode.com/hg/resource/result/TestCurveRectangle.png) -``` +## Test Curve Rectangle +![test_results/TestCurveRectangle.png](test_results/TestCurveRectangle.png) + +```go func TestCurveRectangle() { i, gc := initGc(w, h) @@ -154,10 +148,10 @@ func TestCurveRectangle() { } ``` +## Test Draw Cubic Curve +![test_results/TestDrawCubicCurve.png](test_results/TestDrawCubicCurve.png) -## Test Draw Cubic Curve ## -![http://draw2d.googlecode.com/hg/resource/result/TestDrawCubicCurve.png](http://draw2d.googlecode.com/hg/resource/result/TestDrawCubicCurve.png) -``` +```go func TestDrawCubicCurve() { i, gc := initGc(w, h) // draw a cubic curve @@ -186,10 +180,10 @@ func TestDrawCubicCurve() { ``` - ## Test Dash ## -![http://draw2d.googlecode.com/hg/resource/result/TestDash.png](http://draw2d.googlecode.com/hg/resource/result/TestDash.png) -``` +![test_results/TestDash.png](test_results/TestDash.png) + +```go func TestDash() { i, gc := initGc(w, h) gc.SetLineDash([]float{50, 10, 10, 10}, -50.0) @@ -209,8 +203,9 @@ func TestDash() { ``` ## Test Fill Stroke ## -![http://draw2d.googlecode.com/hg/resource/result/TestFillStroke.png](http://draw2d.googlecode.com/hg/resource/result/TestFillStroke.png) -``` +![test_results/TestFillStroke.png](test_results/TestFillStroke.png) + +```go func TestFillStroke() { i, gc := initGc(w, h) gc.MoveTo(128.0, 25.6) @@ -233,9 +228,10 @@ func TestFillStroke() { } ``` -## Test Fill Style ## -![http://draw2d.googlecode.com/hg/resource/result/TestFillStyle.png](http://draw2d.googlecode.com/hg/resource/result/TestFillStyle.png) -``` +## Test Fill Style +![test_results/TestFillStyle.png](test_results/TestFillStyle.png) + +```go func TestFillStyle() { i, gc := initGc(w, h) gc.SetLineWidth(6) @@ -266,9 +262,10 @@ func TestFillStyle() { } ``` -## Test Multi Segment Caps ## -![http://draw2d.googlecode.com/hg/resource/result/TestMultiSegmentCaps.png](http://draw2d.googlecode.com/hg/resource/result/TestMultiSegmentCaps.png) -``` +## Test Multi Segment Caps +![test_results/TestMultiSegmentCaps.png](test_results/TestMultiSegmentCaps.png) + +```go func TestMultiSegmentCaps() { i, gc := initGc(w, h) gc.MoveTo(50.0, 75.0) @@ -287,9 +284,10 @@ func TestMultiSegmentCaps() { } ``` -## Test Round Rectangle ## -![http://draw2d.googlecode.com/hg/resource/result/TestRoundRectangle.png](http://draw2d.googlecode.com/hg/resource/result/TestRoundRectangle.png) -``` +## Test Round Rectangle +![test_results/TestRoundRectangle.png](test_results/TestRoundRectangle.png) + +```go func TestRoundRectangle() { i, gc := initGc(w, h) /* a custom shape that could be wrapped in a function */ @@ -316,9 +314,10 @@ func TestRoundRectangle() { } ``` -## Test Line Cap ## -![http://draw2d.googlecode.com/hg/resource/result/TestLineCap.png](http://draw2d.googlecode.com/hg/resource/result/TestLineCap.png) -``` +## Test Line Cap +![test_results/TestLineCap.png](test_results/TestLineCap.png) + +```go func TestLineCap() { i, gc := initGc(w, h) gc.SetLineWidth(30.0) @@ -349,9 +348,10 @@ func TestLineCap() { } ``` -## Test Line Join ## -![http://draw2d.googlecode.com/hg/resource/result/TestLineJoin.png](http://draw2d.googlecode.com/hg/resource/result/TestLineJoin.png) -``` +## Test Line Join +![test_results/TestLineJoin.png](test_results/TestLineJoin.png) + +```go func TestLineJoin() { i, gc := initGc(w, h) gc.SetLineWidth(40.96) @@ -376,9 +376,10 @@ func TestLineJoin() { } ``` -## Test Bubble ## -![http://draw2d.googlecode.com/hg/resource/result/TestBubble.png](http://draw2d.googlecode.com/hg/resource/result/TestBubble.png) -``` +## Test Bubble +![test_results/TestBubble.png](test_results/TestBubble.png) + +```go func TestBubble() { i, gc := initGc(w, h) gc.BeginPath(); @@ -394,9 +395,10 @@ func TestBubble() { } ``` -## Test Star ## -![http://draw2d.googlecode.com/hg/resource/result/TestStar.png](http://draw2d.googlecode.com/hg/resource/result/TestStar.png) -``` +## Test Star +![test_results/TestStar.png](test_results/TestStar.png) + +```go func TestStar() { i, gc := initGc(w, h) for i := 0.0 ; i < 360; i = i + 10 {// Go from 0 to 360 degrees in 10 degree steps @@ -413,10 +415,10 @@ func TestStar() { } ``` -## Test Transform ## -![http://draw2d.googlecode.com/hg/resource/result/TestTransform.png](http://draw2d.googlecode.com/hg/resource/result/TestTransform.png) -``` +## Test Transform +![test_results/TestTransform.png](test_results/TestTransform.png) +```go func TestTransform() { i, gc := initGc(800, 600) @@ -472,10 +474,10 @@ func TestTransform() { } ``` -## Test Path Transform ## -![http://draw2d.googlecode.com/hg/resource/result/TestPathTransform.png](http://draw2d.googlecode.com/hg/resource/result/TestPathTransform.png) -``` +## Test Path Transform +![test_results/TestPathTransform.png](test_results/TestPathTransform.png) +```go func TestPathTransform() { i, gc := initGc(800, 600) gc.SetLineWidth(20) @@ -486,10 +488,10 @@ func TestPathTransform() { } ``` -## Test Android ## -![http://draw2d.googlecode.com/hg/resource/result/TestAndroid.png](http://draw2d.googlecode.com/hg/resource/result/TestAndroid.png) -``` +## Test Android +![test_results/TestAndroid.png](test_results/TestAndroid.png) +```go func android(gc *draw2d.GraphicContext, x, y float) { gc.SetLineCap(draw2d.RoundCap) gc.SetLineWidth(5) @@ -518,10 +520,11 @@ func android(gc *draw2d.GraphicContext, x, y float) { gc.FillStroke() } ``` -## Test Gopher ## -![http://draw2d.googlecode.com/hg/resource/result/TestGopher.png](http://draw2d.googlecode.com/hg/resource/result/TestGopher.png) -``` +## Test Gopher +![test_results/TestGopher.png](test_results/TestGopher.png) + +```go func gordon(gc *draw2d.GraphicContext, x, y, w, h float) { h23 := (h * 2) / 3 @@ -587,9 +590,11 @@ func gordon(gc *draw2d.GraphicContext, x, y, w, h float) { } ``` -## Test Fill String ## -![http://draw2d.googlecode.com/hg/resource/result/TestFillString.png](http://draw2d.googlecode.com/hg/resource/result/TestFillString.png) -``` + +## Test Fill String +![test_results/TestFillString.png](test_results/TestFillString.png) + +```go func TestFillString() { i, gc := initGc(100, 100) draw2d.RoundRect(gc, 5, 5, 95, 95, 10, 10) diff --git a/test_results/TestAndroid.png b/test_results/TestAndroid.png new file mode 100644 index 0000000..ffa068b Binary files /dev/null and b/test_results/TestAndroid.png differ diff --git a/test_results/TestBigPicture.png b/test_results/TestBigPicture.png new file mode 100644 index 0000000..791a9df Binary files /dev/null and b/test_results/TestBigPicture.png differ diff --git a/test_results/TestBubble.png b/test_results/TestBubble.png new file mode 100644 index 0000000..29fff3f Binary files /dev/null and b/test_results/TestBubble.png differ diff --git a/test_results/TestCurveRectangle.png b/test_results/TestCurveRectangle.png new file mode 100644 index 0000000..2220ee7 Binary files /dev/null and b/test_results/TestCurveRectangle.png differ diff --git a/test_results/TestDash.png b/test_results/TestDash.png new file mode 100644 index 0000000..324fa3d Binary files /dev/null and b/test_results/TestDash.png differ diff --git a/test_results/TestDrawArc.png b/test_results/TestDrawArc.png new file mode 100644 index 0000000..85b04af Binary files /dev/null and b/test_results/TestDrawArc.png differ diff --git a/test_results/TestDrawArcNegative.png b/test_results/TestDrawArcNegative.png new file mode 100644 index 0000000..6fb9fa8 Binary files /dev/null and b/test_results/TestDrawArcNegative.png differ diff --git a/test_results/TestDrawCubicCurve.png b/test_results/TestDrawCubicCurve.png new file mode 100644 index 0000000..7cff371 Binary files /dev/null and b/test_results/TestDrawCubicCurve.png differ diff --git a/test_results/TestDrawImage.png b/test_results/TestDrawImage.png new file mode 100644 index 0000000..c1b377d Binary files /dev/null and b/test_results/TestDrawImage.png differ diff --git a/test_results/TestFillString.png b/test_results/TestFillString.png new file mode 100644 index 0000000..547f4a7 Binary files /dev/null and b/test_results/TestFillString.png differ diff --git a/test_results/TestFillStroke.png b/test_results/TestFillStroke.png new file mode 100644 index 0000000..3582b64 Binary files /dev/null and b/test_results/TestFillStroke.png differ diff --git a/test_results/TestFillStyle.png b/test_results/TestFillStyle.png new file mode 100644 index 0000000..ad23dda Binary files /dev/null and b/test_results/TestFillStyle.png differ diff --git a/test_results/TestGettingStarted.png b/test_results/TestGettingStarted.png new file mode 100644 index 0000000..c1c532a Binary files /dev/null and b/test_results/TestGettingStarted.png differ diff --git a/test_results/TestGopher.png b/test_results/TestGopher.png new file mode 100644 index 0000000..aac6491 Binary files /dev/null and b/test_results/TestGopher.png differ diff --git a/test_results/TestLineCap.png b/test_results/TestLineCap.png new file mode 100644 index 0000000..0474d91 Binary files /dev/null and b/test_results/TestLineCap.png differ diff --git a/test_results/TestLineJoin.png b/test_results/TestLineJoin.png new file mode 100644 index 0000000..f6605e5 Binary files /dev/null and b/test_results/TestLineJoin.png differ diff --git a/test_results/TestMultiSegmentCaps.png b/test_results/TestMultiSegmentCaps.png new file mode 100644 index 0000000..1ac6698 Binary files /dev/null and b/test_results/TestMultiSegmentCaps.png differ diff --git a/test_results/TestPathTransform.png b/test_results/TestPathTransform.png new file mode 100644 index 0000000..45bf578 Binary files /dev/null and b/test_results/TestPathTransform.png differ diff --git a/test_results/TestRectangle.png b/test_results/TestRectangle.png new file mode 100644 index 0000000..d961ad2 Binary files /dev/null and b/test_results/TestRectangle.png differ diff --git a/test_results/TestRoundRectangle.png b/test_results/TestRoundRectangle.png new file mode 100644 index 0000000..9b5ef12 Binary files /dev/null and b/test_results/TestRoundRectangle.png differ diff --git a/test_results/TestStar.png b/test_results/TestStar.png new file mode 100644 index 0000000..65c7ec7 Binary files /dev/null and b/test_results/TestStar.png differ diff --git a/test_results/TestTransform.png b/test_results/TestTransform.png new file mode 100644 index 0000000..7cd821b Binary files /dev/null and b/test_results/TestTransform.png differ