diff --git a/draw2d/src/cmd/gettingStarted.go b/draw2d/src/cmd/gettingStarted.go index 3e98f2a..f373f16 100644 --- a/draw2d/src/cmd/gettingStarted.go +++ b/draw2d/src/cmd/gettingStarted.go @@ -11,8 +11,8 @@ import ( "image" "image/png" - //"draw2d" - "draw2d.googlecode.com/svn/trunk/draw2d/src/pkg/draw2d" + "draw2d" + //"draw2d.googlecode.com/svn/trunk/draw2d/src/pkg/draw2d" ) @@ -44,4 +44,4 @@ func main() { gc.LineTo(100.0, 10.0) gc.Stroke() saveToPngFile("TestPath.png", i) -} \ No newline at end of file +} diff --git a/draw2d/src/cmd/testX11draw.go b/draw2d/src/cmd/testX11draw.go index 7f1229b..9a0b666 100644 --- a/draw2d/src/cmd/testX11draw.go +++ b/draw2d/src/cmd/testX11draw.go @@ -6,13 +6,13 @@ import ( "exp/draw/x11" "image" "math" - //"draw2d" - "draw2d.googlecode.com/svn/trunk/draw2d/src/pkg/draw2d" + "draw2d" + //"draw2d.googlecode.com/svn/trunk/draw2d/src/pkg/draw2d" ) func main() { window, err := x11.NewWindow() - if(err != nil) { + if err != nil { fmt.Printf("Cannot open an x11 window\n") return } @@ -22,34 +22,34 @@ func main() { gc.SetStrokeColor(image.Black) gc.SetFillColor(image.White) gc.Clear() - for i := 0.0 ; i < 360; i = i + 10 {// Go from 0 to 360 degrees in 10 degree steps - gc.BeginPath() // Start a new path - gc.Save() // Keep rotations temporary - gc.MoveTo(144, 144) - gc.Rotate(i * (math.Pi / 180.0)) // Rotate by degrees on stack from 'for' - gc.RLineTo(72, 0) - gc.Stroke() - gc.Restore() // Get back the unrotated state + for i := 0.0; i < 360; i = i + 10 { // Go from 0 to 360 degrees in 10 degree steps + gc.BeginPath() // Start a new path + gc.Save() // Keep rotations temporary + gc.MoveTo(144, 144) + gc.Rotate(i * (math.Pi / 180.0)) // Rotate by degrees on stack from 'for' + gc.RLineTo(72, 0) + gc.Stroke() + gc.Restore() // Get back the unrotated state } fmt.Printf("This is an rgba image\n") - + window.FlushImage() - + gc.SetLineWidth(3) nbclick := 0 for { - + switch evt := (<-window.EventChan()).(type) { case draw.KeyEvent: - if(evt.Key == 'q') { + if evt.Key == 'q' { window.Close() } case draw.MouseEvent: - if(evt.Buttons & 1 != 0) { - if(nbclick % 2 == 0) { - gc.MoveTo(float(evt.Loc.X),float(evt.Loc.Y)) + if evt.Buttons&1 != 0 { + if nbclick%2 == 0 { + gc.MoveTo(float(evt.Loc.X), float(evt.Loc.Y)) } else { - gc.LineTo(float(evt.Loc.X),float(evt.Loc.Y)) + gc.LineTo(float(evt.Loc.X), float(evt.Loc.Y)) gc.Stroke() window.FlushImage() } @@ -60,4 +60,4 @@ func main() { } else { fmt.Printf("Not an RGBA image!\n") } -} \ No newline at end of file +} diff --git a/draw2d/src/cmd/testandroid.go b/draw2d/src/cmd/testandroid.go index b1fc0a1..6d04957 100644 --- a/draw2d/src/cmd/testandroid.go +++ b/draw2d/src/cmd/testandroid.go @@ -7,12 +7,12 @@ import ( "os" "bufio" "time" - + "math" "image" "image/png" - //"draw2d" - "draw2d.googlecode.com/svn/trunk/draw2d/src/pkg/draw2d" + "draw2d" + //"draw2d.googlecode.com/svn/trunk/draw2d/src/pkg/draw2d" ) const ( @@ -64,22 +64,22 @@ func saveToPngFile(TestName string, m image.Image) { func android(gc *draw2d.GraphicContext, x, y float) { gc.SetLineCap(draw2d.RoundCap) gc.SetLineWidth(5) - gc.ArcTo(x+80, y+70, 50, 50, 180 * (math.Pi/180), 360 * (math.Pi/180)) // head + gc.ArcTo(x+80, y+70, 50, 50, 180*(math.Pi/180), 360*(math.Pi/180)) // head gc.FillStroke() gc.MoveTo(x+60, y+25) gc.LineTo(x+50, y+10) gc.MoveTo(x+100, y+25) - gc.LineTo( x+110, y+10) + gc.LineTo(x+110, y+10) gc.Stroke() - draw2d.Circle(gc, x+60, y+45, 5) // left eye + draw2d.Circle(gc, x+60, y+45, 5) // left eye gc.FillStroke() - draw2d.Circle(gc, x+100, y+45, 5) // right eye + draw2d.Circle(gc, x+100, y+45, 5) // right eye gc.FillStroke() - draw2d.RoundRect(gc, x+30, y+75, x+30+100, y+75+90, 10, 10) // body + draw2d.RoundRect(gc, x+30, y+75, x+30+100, y+75+90, 10, 10) // body gc.FillStroke() draw2d.Rect(gc, x+30, y+75, x+30+100, y+75+80) gc.FillStroke() - draw2d.RoundRect(gc, x+5, y+80, x+5+20, y+80+70, 10, 10) // left arm + draw2d.RoundRect(gc, x+5, y+80, x+5+20, y+80+70, 10, 10) // left arm gc.FillStroke() draw2d.RoundRect(gc, x+135, y+80, x+135+20, y+80+70, 10, 10) // right arm gc.FillStroke() @@ -90,7 +90,6 @@ func android(gc *draw2d.GraphicContext, x, y float) { } - func main() { i, gc := initGc(width, height) gc.SetFillColor(image.RGBAColor{0xff, 0x44, 0x44, 0xff}) diff --git a/draw2d/src/cmd/testdraw2d.go b/draw2d/src/cmd/testdraw2d.go index 982fe68..d228ca3 100644 --- a/draw2d/src/cmd/testdraw2d.go +++ b/draw2d/src/cmd/testdraw2d.go @@ -13,8 +13,8 @@ import ( "math" "image" "image/png" - //"draw2d" - "draw2d.googlecode.com/svn/trunk/draw2d/src/pkg/draw2d" + "draw2d" + //"draw2d.googlecode.com/svn/trunk/draw2d/src/pkg/draw2d" ) const ( @@ -68,7 +68,7 @@ func saveToPngFile(TestName string, m image.Image) { */ func TestPath() { i, gc := initGc(w, h) - gc.Translate(10,10) + gc.Translate(10, 10) gc.MoveTo(0.0, 0.0) gc.LineTo(100.0, 00.0) gc.LineTo(100.0, 100.0) @@ -128,15 +128,14 @@ func TestDrawArcNegative() { gc.SetLineWidth(10) gc.SetLineCap(draw2d.ButtCap) gc.SetStrokeColor(image.Black) - + gc.ArcTo(xc, yc, radiusX, radiusY, startAngle, angle) gc.Stroke() // fill a circle gc.SetStrokeColor(image.RGBAColor{255, 0x33, 0x33, 0x80}) gc.SetFillColor(image.RGBAColor{255, 0x33, 0x33, 0x80}) gc.SetLineWidth(6) - - + gc.MoveTo(xc, yc) gc.LineTo(xc+cos(startAngle)*radiusX, yc+sin(startAngle)*radiusY) gc.MoveTo(xc, yc) @@ -404,104 +403,104 @@ func TestLineJoin() { func TestBubble() { i, gc := initGc(w, h) - gc.BeginPath() - gc.MoveTo(75,25) - gc.QuadCurveTo(25,25,25,62.5) - gc.QuadCurveTo(25,100,50,100) - gc.QuadCurveTo(50,120,30,125) - gc.QuadCurveTo(60,120,65,100) - gc.QuadCurveTo(125,100,125,62.5) - gc.QuadCurveTo(125,25,75,25) - gc.Stroke() - saveToPngFile("TestBubble", i) + gc.BeginPath() + gc.MoveTo(75, 25) + gc.QuadCurveTo(25, 25, 25, 62.5) + gc.QuadCurveTo(25, 100, 50, 100) + gc.QuadCurveTo(50, 120, 30, 125) + gc.QuadCurveTo(60, 120, 65, 100) + gc.QuadCurveTo(125, 100, 125, 62.5) + gc.QuadCurveTo(125, 25, 75, 25) + gc.Stroke() + saveToPngFile("TestBubble", i) } 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 - gc.Save() - gc.SetLineWidth(5) // Keep rotations temporary - gc.Translate(144, 144) - gc.Rotate(i * (math.Pi / 180.0)) // Rotate by degrees on stack from 'for' - gc.MoveTo(0, 0) - gc.LineTo(72, 0) - gc.Stroke() - gc.Restore() + for i := 0.0; i < 360; i = i + 10 { // Go from 0 to 360 degrees in 10 degree steps + gc.Save() + gc.SetLineWidth(5) // Keep rotations temporary + gc.Translate(144, 144) + gc.Rotate(i * (math.Pi / 180.0)) // Rotate by degrees on stack from 'for' + gc.MoveTo(0, 0) + gc.LineTo(72, 0) + gc.Stroke() + gc.Restore() } - saveToPngFile("TestStar", i) + saveToPngFile("TestStar", i) } func TestTransform() { - i, gc := initGc(800, 600) + i, gc := initGc(800, 600) gc.Save() - gc.Translate(40, 40) // Set origin to (40, 40) + gc.Translate(40, 40) // Set origin to (40, 40) gc.BeginPath() - gc.MoveTo(0,0) - gc.RLineTo(72,0) + gc.MoveTo(0, 0) + gc.RLineTo(72, 0) gc.RLineTo(0, 72) - gc.RLineTo(-72,0) + gc.RLineTo(-72, 0) gc.Close() gc.Stroke() gc.Restore() - + gc.Save() - gc.Translate(100, 150) // Translate origin to (100, 150) - gc.Rotate(30* (math.Pi / 180.0)) // Rotate counter-clockwise by 30 degrees + gc.Translate(100, 150) // Translate origin to (100, 150) + gc.Rotate(30 * (math.Pi / 180.0)) // Rotate counter-clockwise by 30 degrees gc.BeginPath() - gc.MoveTo(0,0) - gc.RLineTo(72,0) + gc.MoveTo(0, 0) + gc.RLineTo(72, 0) gc.RLineTo(0, 72) - gc.RLineTo(-72,0) - gc.Close() // Draw box... - gc.Stroke() - gc.Restore() - - gc.Save() - gc.Translate(40, 300) // Translate to (40, 300) - gc.Scale(0.5, 1) // Reduce x coord by 1/2, y coord left alone - gc.BeginPath() - gc.MoveTo(0,0) - gc.RLineTo(72,0) - gc.RLineTo(0, 72) - gc.RLineTo(-72,0) - gc.Close() // Draw box... + gc.RLineTo(-72, 0) + gc.Close() // Draw box... gc.Stroke() gc.Restore() gc.Save() - gc.Translate(300, 300) // Set origin to (300, 300) - gc.Rotate(45* (math.Pi / 180.0)) // Rotate coordinates by 45 degrees - gc.Scale(0.5, 1) // Scale coordinates + gc.Translate(40, 300) // Translate to (40, 300) + gc.Scale(0.5, 1) // Reduce x coord by 1/2, y coord left alone gc.BeginPath() - gc.MoveTo(0,0) - gc.RLineTo(72,0) + gc.MoveTo(0, 0) + gc.RLineTo(72, 0) gc.RLineTo(0, 72) - gc.RLineTo(-72,0) - gc.Close() // Draw box + gc.RLineTo(-72, 0) + gc.Close() // Draw box... gc.Stroke() gc.Restore() - + + gc.Save() + gc.Translate(300, 300) // Set origin to (300, 300) + gc.Rotate(45 * (math.Pi / 180.0)) // Rotate coordinates by 45 degrees + gc.Scale(0.5, 1) // Scale coordinates + gc.BeginPath() + gc.MoveTo(0, 0) + gc.RLineTo(72, 0) + gc.RLineTo(0, 72) + gc.RLineTo(-72, 0) + gc.Close() // Draw box + gc.Stroke() + gc.Restore() + saveToPngFile("TestTransform", i) } func TestPathTransform() { - i, gc := initGc(800, 600) + i, gc := initGc(800, 600) gc.SetLineWidth(20) - gc.Scale(1,5) - gc.ArcTo(200, 50, 50, 50, 0, math.Pi * 2) + gc.Scale(1, 5) + gc.ArcTo(200, 50, 50, 50, 0, math.Pi*2) gc.Stroke() saveToPngFile("TestPathTransform", i) } func TestFillString() { draw2d.SetFontFolder("../../fonts/") - i, gc := initGc(100, 100) + i, gc := initGc(100, 100) draw2d.RoundRect(gc, 5, 5, 95, 95, 10, 10) gc.FillStroke() gc.SetFontSize(18) gc.MoveTo(10, 52) - gc.SetFontData(draw2d.FontData{"luxi", draw2d.FontFamilyMono, draw2d.FontStyleBold|draw2d.FontStyleItalic}) + gc.SetFontData(draw2d.FontData{"luxi", draw2d.FontFamilyMono, draw2d.FontStyleBold | draw2d.FontStyleItalic}) width := gc.FillString("cou") fmt.Printf("width: %f\n", width) gc.RMoveTo(width+1, 0) diff --git a/draw2d/src/cmd/testgopher.go b/draw2d/src/cmd/testgopher.go index aa3674f..7c36b80 100644 --- a/draw2d/src/cmd/testgopher.go +++ b/draw2d/src/cmd/testgopher.go @@ -11,8 +11,8 @@ import ( "image" "image/png" - //"draw2d" - "draw2d.googlecode.com/svn/trunk/draw2d/src/pkg/draw2d" + "draw2d" + //"draw2d.googlecode.com/svn/trunk/draw2d/src/pkg/draw2d" ) const ( @@ -64,26 +64,26 @@ func saveToPngFile(TestName string, m image.Image) { func gordon(gc *draw2d.GraphicContext, x, y, w, h float) { h23 := (h * 2) / 3 - blf := image.RGBAColor{0, 0, 0, 0xff} + blf := image.RGBAColor{0, 0, 0, 0xff} wf := image.RGBAColor{0xff, 0xff, 0xff, 0xff} nf := image.RGBAColor{0x8B, 0x45, 0x13, 0xff} brf := image.RGBAColor{0x8B, 0x45, 0x13, 0x99} brb := image.RGBAColor{0x8B, 0x45, 0x13, 0xBB} - + gc.MoveTo(x, y+h) gc.CubicCurveTo(x, y+h, x+w/2, y-h, x+w, y+h) gc.Close() gc.SetFillColor(brb) gc.Fill() - draw2d.RoundRect(gc, x, y+h, x+ w, y+h+h, 10, 10) + draw2d.RoundRect(gc, x, y+h, x+w, y+h+h, 10, 10) gc.Fill() - draw2d.Circle(gc,x, y+h, w/12) // left ear + draw2d.Circle(gc, x, y+h, w/12) // left ear gc.SetFillColor(brf) gc.Fill() draw2d.Circle(gc, x, y+h, w/12-10) gc.SetFillColor(nf) gc.Fill() - + draw2d.Circle(gc, x+w, y+h, w/12) // right ear gc.SetFillColor(brf) gc.Fill() @@ -94,7 +94,7 @@ func gordon(gc *draw2d.GraphicContext, x, y, w, h float) { draw2d.Circle(gc, x+w/3, y+h23, w/9) // left eye gc.SetFillColor(wf) gc.Fill() - draw2d.Circle(gc, x+w/3+10, y+h23, w / 10 - 10) + draw2d.Circle(gc, x+w/3+10, y+h23, w/10-10) gc.SetFillColor(blf) gc.Fill() draw2d.Circle(gc, x+w/3+15, y+h23, 5) @@ -103,7 +103,7 @@ func gordon(gc *draw2d.GraphicContext, x, y, w, h float) { draw2d.Circle(gc, x+w-w/3, y+h23, w/9) // right eye gc.Fill() - draw2d.Circle(gc, x+w-w/3+10, y+h23, w / 10 - 10) + draw2d.Circle(gc, x+w-w/3+10, y+h23, w/10-10) gc.SetFillColor(blf) gc.Fill() draw2d.Circle(gc, x+w-(w/3)+15, y+h23, 5) @@ -111,19 +111,18 @@ func gordon(gc *draw2d.GraphicContext, x, y, w, h float) { gc.Fill() gc.SetFillColor(wf) - draw2d.RoundRect(gc, x+w/2-w/8, y+h+30, x+w/2-w/8 + w/8, y+h+30 + w/6, 5, 5) // left tooth + draw2d.RoundRect(gc, x+w/2-w/8, y+h+30, x+w/2-w/8+w/8, y+h+30+w/6, 5, 5) // left tooth gc.Fill() - draw2d.RoundRect(gc, x+w/2, y+h+30, x+w/2+w/8, y+h+30+w/6, 5, 5) // right tooth + draw2d.RoundRect(gc, x+w/2, y+h+30, x+w/2+w/8, y+h+30+w/6, 5, 5) // right tooth gc.Fill() - - draw2d.Ellipse(gc, x+(w/2), y+h+30, w/6, w/12) // snout + draw2d.Ellipse(gc, x+(w/2), y+h+30, w/6, w/12) // snout gc.SetFillColor(nf) gc.Fill() draw2d.Ellipse(gc, x+(w/2), y+h+10, w/10, w/12) // nose gc.SetFillColor(blf) gc.Fill() - + } func main() { @@ -133,4 +132,4 @@ func main() { gc.Rotate(-30 * (math.Pi / 180.0)) gordon(gc, 48, 48, 240, 72) saveToPngFile("TestGopher", i) -} \ No newline at end of file +}