format && add images
|
@ -1,7 +1,7 @@
|
||||||
## Getting Started
|
## 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
|
```go
|
||||||
package main
|
package main
|
||||||
|
@ -17,6 +17,27 @@ import (
|
||||||
"image/png"
|
"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 {
|
func saveToPngFile(filePath string, m image.Image) error {
|
||||||
// Create the file
|
// Create the file
|
||||||
f, err := os.Create(filePath)
|
f, err := os.Create(filePath)
|
||||||
|
@ -38,19 +59,8 @@ func saveToPngFile(filePath string, m image.Image) error {
|
||||||
return nil
|
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 #
|
See [Samples](Samples) to go further.
|
||||||
Now you are ready to start using the draw2d package. Go to [Samples](Samples.md) or [GettingStartedGUI](GettingStartedGUI.md).
|
|
||||||
|
|
143
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:
|
Those samples are largely inspired by this page:
|
||||||
> http://cairographics.org/samples/
|
> 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)
|
||||||
|
|
||||||
|
```go
|
||||||
|
func TestRectangle() {
|
||||||
## Test Path ##
|
|
||||||
![http://draw2d.googlecode.com/hg/resource/result/TestPath.png](http://draw2d.googlecode.com/hg/resource/result/TestPath.png)
|
|
||||||
```
|
|
||||||
func TestPath() {
|
|
||||||
i, gc := initGc(w, h)
|
i, gc := initGc(w, h)
|
||||||
gc.MoveTo(10.0, 10.0)
|
gc.MoveTo(10.0, 10.0)
|
||||||
gc.LineTo(100.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, 100.0)
|
||||||
gc.LineTo(10.0, 10.0)
|
gc.LineTo(10.0, 10.0)
|
||||||
gc.FillStroke()
|
gc.FillStroke()
|
||||||
saveToPngFile("TestPath", i)
|
saveToPngFile("TestRectangle", i)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Test Draw Arc
|
||||||
|
![test_results/TestDrawArc.png](test_results/TestDrawArc.png)
|
||||||
|
|
||||||
## Test Draw Arc ##
|
```go
|
||||||
![http://draw2d.googlecode.com/hg/resource/result/TestDrawArc.png](http://draw2d.googlecode.com/hg/resource/result/TestDrawArc.png)
|
|
||||||
```
|
|
||||||
func TestDrawArc() {
|
func TestDrawArc() {
|
||||||
i, gc := initGc(w, h)
|
i, gc := initGc(w, h)
|
||||||
// draw an arc
|
// draw an arc
|
||||||
|
@ -63,9 +54,11 @@ func TestDrawArc() {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Test Draw Arc Negative ##
|
## Test Draw Arc Negative
|
||||||
![http://draw2d.googlecode.com/hg/resource/result/TestDrawArcNegative.png](http://draw2d.googlecode.com/hg/resource/result/TestDrawArcNegative.png)
|
![test_results/TestDrawArcNegative.png](test_results/TestDrawArcNegative.png)
|
||||||
```
|
|
||||||
|
|
||||||
|
```go
|
||||||
func TestDrawArcNegative() {
|
func TestDrawArcNegative() {
|
||||||
i, gc := initGc(w, h)
|
i, gc := initGc(w, h)
|
||||||
// draw an arc
|
// draw an arc
|
||||||
|
@ -95,9 +88,10 @@ func TestDrawArcNegative() {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Test Curve Rectangle ##
|
## Test Curve Rectangle
|
||||||
![http://draw2d.googlecode.com/hg/resource/result/TestCurveRectangle.png](http://draw2d.googlecode.com/hg/resource/result/TestCurveRectangle.png)
|
![test_results/TestCurveRectangle.png](test_results/TestCurveRectangle.png)
|
||||||
```
|
|
||||||
|
```go
|
||||||
func TestCurveRectangle() {
|
func TestCurveRectangle() {
|
||||||
i, gc := initGc(w, h)
|
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 ##
|
```go
|
||||||
![http://draw2d.googlecode.com/hg/resource/result/TestDrawCubicCurve.png](http://draw2d.googlecode.com/hg/resource/result/TestDrawCubicCurve.png)
|
|
||||||
```
|
|
||||||
func TestDrawCubicCurve() {
|
func TestDrawCubicCurve() {
|
||||||
i, gc := initGc(w, h)
|
i, gc := initGc(w, h)
|
||||||
// draw a cubic curve
|
// draw a cubic curve
|
||||||
|
@ -186,10 +180,10 @@ func TestDrawCubicCurve() {
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## Test Dash ##
|
## 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() {
|
func TestDash() {
|
||||||
i, gc := initGc(w, h)
|
i, gc := initGc(w, h)
|
||||||
gc.SetLineDash([]float{50, 10, 10, 10}, -50.0)
|
gc.SetLineDash([]float{50, 10, 10, 10}, -50.0)
|
||||||
|
@ -209,8 +203,9 @@ func TestDash() {
|
||||||
```
|
```
|
||||||
|
|
||||||
## Test Fill Stroke ##
|
## 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() {
|
func TestFillStroke() {
|
||||||
i, gc := initGc(w, h)
|
i, gc := initGc(w, h)
|
||||||
gc.MoveTo(128.0, 25.6)
|
gc.MoveTo(128.0, 25.6)
|
||||||
|
@ -233,9 +228,10 @@ func TestFillStroke() {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Test Fill Style ##
|
## Test Fill Style
|
||||||
![http://draw2d.googlecode.com/hg/resource/result/TestFillStyle.png](http://draw2d.googlecode.com/hg/resource/result/TestFillStyle.png)
|
![test_results/TestFillStyle.png](test_results/TestFillStyle.png)
|
||||||
```
|
|
||||||
|
```go
|
||||||
func TestFillStyle() {
|
func TestFillStyle() {
|
||||||
i, gc := initGc(w, h)
|
i, gc := initGc(w, h)
|
||||||
gc.SetLineWidth(6)
|
gc.SetLineWidth(6)
|
||||||
|
@ -266,9 +262,10 @@ func TestFillStyle() {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Test Multi Segment Caps ##
|
## Test Multi Segment Caps
|
||||||
![http://draw2d.googlecode.com/hg/resource/result/TestMultiSegmentCaps.png](http://draw2d.googlecode.com/hg/resource/result/TestMultiSegmentCaps.png)
|
![test_results/TestMultiSegmentCaps.png](test_results/TestMultiSegmentCaps.png)
|
||||||
```
|
|
||||||
|
```go
|
||||||
func TestMultiSegmentCaps() {
|
func TestMultiSegmentCaps() {
|
||||||
i, gc := initGc(w, h)
|
i, gc := initGc(w, h)
|
||||||
gc.MoveTo(50.0, 75.0)
|
gc.MoveTo(50.0, 75.0)
|
||||||
|
@ -287,9 +284,10 @@ func TestMultiSegmentCaps() {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Test Round Rectangle ##
|
## Test Round Rectangle
|
||||||
![http://draw2d.googlecode.com/hg/resource/result/TestRoundRectangle.png](http://draw2d.googlecode.com/hg/resource/result/TestRoundRectangle.png)
|
![test_results/TestRoundRectangle.png](test_results/TestRoundRectangle.png)
|
||||||
```
|
|
||||||
|
```go
|
||||||
func TestRoundRectangle() {
|
func TestRoundRectangle() {
|
||||||
i, gc := initGc(w, h)
|
i, gc := initGc(w, h)
|
||||||
/* a custom shape that could be wrapped in a function */
|
/* a custom shape that could be wrapped in a function */
|
||||||
|
@ -316,9 +314,10 @@ func TestRoundRectangle() {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Test Line Cap ##
|
## Test Line Cap
|
||||||
![http://draw2d.googlecode.com/hg/resource/result/TestLineCap.png](http://draw2d.googlecode.com/hg/resource/result/TestLineCap.png)
|
![test_results/TestLineCap.png](test_results/TestLineCap.png)
|
||||||
```
|
|
||||||
|
```go
|
||||||
func TestLineCap() {
|
func TestLineCap() {
|
||||||
i, gc := initGc(w, h)
|
i, gc := initGc(w, h)
|
||||||
gc.SetLineWidth(30.0)
|
gc.SetLineWidth(30.0)
|
||||||
|
@ -349,9 +348,10 @@ func TestLineCap() {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Test Line Join ##
|
## Test Line Join
|
||||||
![http://draw2d.googlecode.com/hg/resource/result/TestLineJoin.png](http://draw2d.googlecode.com/hg/resource/result/TestLineJoin.png)
|
![test_results/TestLineJoin.png](test_results/TestLineJoin.png)
|
||||||
```
|
|
||||||
|
```go
|
||||||
func TestLineJoin() {
|
func TestLineJoin() {
|
||||||
i, gc := initGc(w, h)
|
i, gc := initGc(w, h)
|
||||||
gc.SetLineWidth(40.96)
|
gc.SetLineWidth(40.96)
|
||||||
|
@ -376,9 +376,10 @@ func TestLineJoin() {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Test Bubble ##
|
## Test Bubble
|
||||||
![http://draw2d.googlecode.com/hg/resource/result/TestBubble.png](http://draw2d.googlecode.com/hg/resource/result/TestBubble.png)
|
![test_results/TestBubble.png](test_results/TestBubble.png)
|
||||||
```
|
|
||||||
|
```go
|
||||||
func TestBubble() {
|
func TestBubble() {
|
||||||
i, gc := initGc(w, h)
|
i, gc := initGc(w, h)
|
||||||
gc.BeginPath();
|
gc.BeginPath();
|
||||||
|
@ -394,9 +395,10 @@ func TestBubble() {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Test Star ##
|
## Test Star
|
||||||
![http://draw2d.googlecode.com/hg/resource/result/TestStar.png](http://draw2d.googlecode.com/hg/resource/result/TestStar.png)
|
![test_results/TestStar.png](test_results/TestStar.png)
|
||||||
```
|
|
||||||
|
```go
|
||||||
func TestStar() {
|
func TestStar() {
|
||||||
i, gc := initGc(w, h)
|
i, gc := initGc(w, h)
|
||||||
for i := 0.0 ; i < 360; i = i + 10 {// Go from 0 to 360 degrees in 10 degree steps
|
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 ##
|
## Test Transform
|
||||||
![http://draw2d.googlecode.com/hg/resource/result/TestTransform.png](http://draw2d.googlecode.com/hg/resource/result/TestTransform.png)
|
![test_results/TestTransform.png](test_results/TestTransform.png)
|
||||||
```
|
|
||||||
|
|
||||||
|
```go
|
||||||
func TestTransform() {
|
func TestTransform() {
|
||||||
i, gc := initGc(800, 600)
|
i, gc := initGc(800, 600)
|
||||||
|
|
||||||
|
@ -472,10 +474,10 @@ func TestTransform() {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Test Path Transform ##
|
## Test Path Transform
|
||||||
![http://draw2d.googlecode.com/hg/resource/result/TestPathTransform.png](http://draw2d.googlecode.com/hg/resource/result/TestPathTransform.png)
|
![test_results/TestPathTransform.png](test_results/TestPathTransform.png)
|
||||||
```
|
|
||||||
|
|
||||||
|
```go
|
||||||
func TestPathTransform() {
|
func TestPathTransform() {
|
||||||
i, gc := initGc(800, 600)
|
i, gc := initGc(800, 600)
|
||||||
gc.SetLineWidth(20)
|
gc.SetLineWidth(20)
|
||||||
|
@ -486,10 +488,10 @@ func TestPathTransform() {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Test Android ##
|
## Test Android
|
||||||
![http://draw2d.googlecode.com/hg/resource/result/TestAndroid.png](http://draw2d.googlecode.com/hg/resource/result/TestAndroid.png)
|
![test_results/TestAndroid.png](test_results/TestAndroid.png)
|
||||||
```
|
|
||||||
|
|
||||||
|
```go
|
||||||
func android(gc *draw2d.GraphicContext, x, y float) {
|
func android(gc *draw2d.GraphicContext, x, y float) {
|
||||||
gc.SetLineCap(draw2d.RoundCap)
|
gc.SetLineCap(draw2d.RoundCap)
|
||||||
gc.SetLineWidth(5)
|
gc.SetLineWidth(5)
|
||||||
|
@ -518,10 +520,11 @@ func android(gc *draw2d.GraphicContext, x, y float) {
|
||||||
gc.FillStroke()
|
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) {
|
func gordon(gc *draw2d.GraphicContext, x, y, w, h float) {
|
||||||
h23 := (h * 2) / 3
|
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() {
|
func TestFillString() {
|
||||||
i, gc := initGc(100, 100)
|
i, gc := initGc(100, 100)
|
||||||
draw2d.RoundRect(gc, 5, 5, 95, 95, 10, 10)
|
draw2d.RoundRect(gc, 5, 5, 95, 95, 10, 10)
|
||||||
|
|
BIN
test_results/TestAndroid.png
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
test_results/TestBigPicture.png
Normal file
After Width: | Height: | Size: 1.8 KiB |
BIN
test_results/TestBubble.png
Normal file
After Width: | Height: | Size: 4.2 KiB |
BIN
test_results/TestCurveRectangle.png
Normal file
After Width: | Height: | Size: 9.4 KiB |
BIN
test_results/TestDash.png
Normal file
After Width: | Height: | Size: 4.7 KiB |
BIN
test_results/TestDrawArc.png
Normal file
After Width: | Height: | Size: 5.2 KiB |
BIN
test_results/TestDrawArcNegative.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
test_results/TestDrawCubicCurve.png
Normal file
After Width: | Height: | Size: 8.1 KiB |
BIN
test_results/TestDrawImage.png
Normal file
After Width: | Height: | Size: 23 KiB |
BIN
test_results/TestFillString.png
Normal file
After Width: | Height: | Size: 3.2 KiB |
BIN
test_results/TestFillStroke.png
Normal file
After Width: | Height: | Size: 5.7 KiB |
BIN
test_results/TestFillStyle.png
Normal file
After Width: | Height: | Size: 9.8 KiB |
BIN
test_results/TestGettingStarted.png
Normal file
After Width: | Height: | Size: 603 B |
BIN
test_results/TestGopher.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
test_results/TestLineCap.png
Normal file
After Width: | Height: | Size: 2.2 KiB |
BIN
test_results/TestLineJoin.png
Normal file
After Width: | Height: | Size: 3.6 KiB |
BIN
test_results/TestMultiSegmentCaps.png
Normal file
After Width: | Height: | Size: 2.2 KiB |
BIN
test_results/TestPathTransform.png
Normal file
After Width: | Height: | Size: 10 KiB |
BIN
test_results/TestRectangle.png
Normal file
After Width: | Height: | Size: 2.2 KiB |
BIN
test_results/TestRoundRectangle.png
Normal file
After Width: | Height: | Size: 5 KiB |
BIN
test_results/TestStar.png
Normal file
After Width: | Height: | Size: 13 KiB |
BIN
test_results/TestTransform.png
Normal file
After Width: | Height: | Size: 6.1 KiB |