format && add images

Laurent Le Goff 2015-04-19 23:00:53 +02:00
parent c0710570ac
commit 4243a36c24
24 changed files with 116 additions and 101 deletions

@ -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,6 +17,27 @@ import (
"image/png"
)
func main() {
// 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)
@ -38,19 +59,8 @@ func saveToPngFile(filePath string, m image.Image) error {
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)
}
```
# 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.

@ -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)

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

BIN
test_results/TestBubble.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

BIN
test_results/TestDash.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 603 B

BIN
test_results/TestGopher.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5 KiB

BIN
test_results/TestStar.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB