gofmt on package

This commit is contained in:
legoff.laurent 2010-12-06 17:18:39 +00:00
parent 873e6bfa2b
commit b0cb20d244
5 changed files with 108 additions and 111 deletions

View file

@ -11,8 +11,8 @@ import (
"image" "image"
"image/png" "image/png"
//"draw2d" "draw2d"
"draw2d.googlecode.com/svn/trunk/draw2d/src/pkg/draw2d" //"draw2d.googlecode.com/svn/trunk/draw2d/src/pkg/draw2d"
) )
@ -44,4 +44,4 @@ func main() {
gc.LineTo(100.0, 10.0) gc.LineTo(100.0, 10.0)
gc.Stroke() gc.Stroke()
saveToPngFile("TestPath.png", i) saveToPngFile("TestPath.png", i)
} }

View file

@ -6,13 +6,13 @@ import (
"exp/draw/x11" "exp/draw/x11"
"image" "image"
"math" "math"
//"draw2d" "draw2d"
"draw2d.googlecode.com/svn/trunk/draw2d/src/pkg/draw2d" //"draw2d.googlecode.com/svn/trunk/draw2d/src/pkg/draw2d"
) )
func main() { func main() {
window, err := x11.NewWindow() window, err := x11.NewWindow()
if(err != nil) { if err != nil {
fmt.Printf("Cannot open an x11 window\n") fmt.Printf("Cannot open an x11 window\n")
return return
} }
@ -22,34 +22,34 @@ func main() {
gc.SetStrokeColor(image.Black) gc.SetStrokeColor(image.Black)
gc.SetFillColor(image.White) gc.SetFillColor(image.White)
gc.Clear() gc.Clear()
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
gc.BeginPath() // Start a new path gc.BeginPath() // Start a new path
gc.Save() // Keep rotations temporary gc.Save() // Keep rotations temporary
gc.MoveTo(144, 144) gc.MoveTo(144, 144)
gc.Rotate(i * (math.Pi / 180.0)) // Rotate by degrees on stack from 'for' gc.Rotate(i * (math.Pi / 180.0)) // Rotate by degrees on stack from 'for'
gc.RLineTo(72, 0) gc.RLineTo(72, 0)
gc.Stroke() gc.Stroke()
gc.Restore() // Get back the unrotated state gc.Restore() // Get back the unrotated state
} }
fmt.Printf("This is an rgba image\n") fmt.Printf("This is an rgba image\n")
window.FlushImage() window.FlushImage()
gc.SetLineWidth(3) gc.SetLineWidth(3)
nbclick := 0 nbclick := 0
for { for {
switch evt := (<-window.EventChan()).(type) { switch evt := (<-window.EventChan()).(type) {
case draw.KeyEvent: case draw.KeyEvent:
if(evt.Key == 'q') { if evt.Key == 'q' {
window.Close() window.Close()
} }
case draw.MouseEvent: case draw.MouseEvent:
if(evt.Buttons & 1 != 0) { if evt.Buttons&1 != 0 {
if(nbclick % 2 == 0) { if nbclick%2 == 0 {
gc.MoveTo(float(evt.Loc.X),float(evt.Loc.Y)) gc.MoveTo(float(evt.Loc.X), float(evt.Loc.Y))
} else { } else {
gc.LineTo(float(evt.Loc.X),float(evt.Loc.Y)) gc.LineTo(float(evt.Loc.X), float(evt.Loc.Y))
gc.Stroke() gc.Stroke()
window.FlushImage() window.FlushImage()
} }
@ -60,4 +60,4 @@ func main() {
} else { } else {
fmt.Printf("Not an RGBA image!\n") fmt.Printf("Not an RGBA image!\n")
} }
} }

View file

@ -7,12 +7,12 @@ import (
"os" "os"
"bufio" "bufio"
"time" "time"
"math" "math"
"image" "image"
"image/png" "image/png"
//"draw2d" "draw2d"
"draw2d.googlecode.com/svn/trunk/draw2d/src/pkg/draw2d" //"draw2d.googlecode.com/svn/trunk/draw2d/src/pkg/draw2d"
) )
const ( const (
@ -64,22 +64,22 @@ func saveToPngFile(TestName string, m image.Image) {
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)
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.FillStroke()
gc.MoveTo(x+60, y+25) gc.MoveTo(x+60, y+25)
gc.LineTo(x+50, y+10) gc.LineTo(x+50, y+10)
gc.MoveTo(x+100, y+25) gc.MoveTo(x+100, y+25)
gc.LineTo( x+110, y+10) gc.LineTo(x+110, y+10)
gc.Stroke() gc.Stroke()
draw2d.Circle(gc, x+60, y+45, 5) // left eye draw2d.Circle(gc, x+60, y+45, 5) // left eye
gc.FillStroke() gc.FillStroke()
draw2d.Circle(gc, x+100, y+45, 5) // right eye draw2d.Circle(gc, x+100, y+45, 5) // right eye
gc.FillStroke() 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() gc.FillStroke()
draw2d.Rect(gc, x+30, y+75, x+30+100, y+75+80) draw2d.Rect(gc, x+30, y+75, x+30+100, y+75+80)
gc.FillStroke() 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() gc.FillStroke()
draw2d.RoundRect(gc, x+135, y+80, x+135+20, y+80+70, 10, 10) // right arm draw2d.RoundRect(gc, x+135, y+80, x+135+20, y+80+70, 10, 10) // right arm
gc.FillStroke() gc.FillStroke()
@ -90,7 +90,6 @@ func android(gc *draw2d.GraphicContext, x, y float) {
} }
func main() { func main() {
i, gc := initGc(width, height) i, gc := initGc(width, height)
gc.SetFillColor(image.RGBAColor{0xff, 0x44, 0x44, 0xff}) gc.SetFillColor(image.RGBAColor{0xff, 0x44, 0x44, 0xff})

View file

@ -13,8 +13,8 @@ import (
"math" "math"
"image" "image"
"image/png" "image/png"
//"draw2d" "draw2d"
"draw2d.googlecode.com/svn/trunk/draw2d/src/pkg/draw2d" //"draw2d.googlecode.com/svn/trunk/draw2d/src/pkg/draw2d"
) )
const ( const (
@ -68,7 +68,7 @@ func saveToPngFile(TestName string, m image.Image) {
*/ */
func TestPath() { func TestPath() {
i, gc := initGc(w, h) i, gc := initGc(w, h)
gc.Translate(10,10) gc.Translate(10, 10)
gc.MoveTo(0.0, 0.0) gc.MoveTo(0.0, 0.0)
gc.LineTo(100.0, 00.0) gc.LineTo(100.0, 00.0)
gc.LineTo(100.0, 100.0) gc.LineTo(100.0, 100.0)
@ -128,15 +128,14 @@ func TestDrawArcNegative() {
gc.SetLineWidth(10) gc.SetLineWidth(10)
gc.SetLineCap(draw2d.ButtCap) gc.SetLineCap(draw2d.ButtCap)
gc.SetStrokeColor(image.Black) gc.SetStrokeColor(image.Black)
gc.ArcTo(xc, yc, radiusX, radiusY, startAngle, angle) gc.ArcTo(xc, yc, radiusX, radiusY, startAngle, angle)
gc.Stroke() gc.Stroke()
// fill a circle // fill a circle
gc.SetStrokeColor(image.RGBAColor{255, 0x33, 0x33, 0x80}) gc.SetStrokeColor(image.RGBAColor{255, 0x33, 0x33, 0x80})
gc.SetFillColor(image.RGBAColor{255, 0x33, 0x33, 0x80}) gc.SetFillColor(image.RGBAColor{255, 0x33, 0x33, 0x80})
gc.SetLineWidth(6) gc.SetLineWidth(6)
gc.MoveTo(xc, yc) gc.MoveTo(xc, yc)
gc.LineTo(xc+cos(startAngle)*radiusX, yc+sin(startAngle)*radiusY) gc.LineTo(xc+cos(startAngle)*radiusX, yc+sin(startAngle)*radiusY)
gc.MoveTo(xc, yc) gc.MoveTo(xc, yc)
@ -404,104 +403,104 @@ func TestLineJoin() {
func TestBubble() { func TestBubble() {
i, gc := initGc(w, h) i, gc := initGc(w, h)
gc.BeginPath() gc.BeginPath()
gc.MoveTo(75,25) gc.MoveTo(75, 25)
gc.QuadCurveTo(25,25,25,62.5) gc.QuadCurveTo(25, 25, 25, 62.5)
gc.QuadCurveTo(25,100,50,100) gc.QuadCurveTo(25, 100, 50, 100)
gc.QuadCurveTo(50,120,30,125) gc.QuadCurveTo(50, 120, 30, 125)
gc.QuadCurveTo(60,120,65,100) gc.QuadCurveTo(60, 120, 65, 100)
gc.QuadCurveTo(125,100,125,62.5) gc.QuadCurveTo(125, 100, 125, 62.5)
gc.QuadCurveTo(125,25,75,25) gc.QuadCurveTo(125, 25, 75, 25)
gc.Stroke() gc.Stroke()
saveToPngFile("TestBubble", i) saveToPngFile("TestBubble", i)
} }
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
gc.Save() gc.Save()
gc.SetLineWidth(5) // Keep rotations temporary gc.SetLineWidth(5) // Keep rotations temporary
gc.Translate(144, 144) gc.Translate(144, 144)
gc.Rotate(i * (math.Pi / 180.0)) // Rotate by degrees on stack from 'for' gc.Rotate(i * (math.Pi / 180.0)) // Rotate by degrees on stack from 'for'
gc.MoveTo(0, 0) gc.MoveTo(0, 0)
gc.LineTo(72, 0) gc.LineTo(72, 0)
gc.Stroke() gc.Stroke()
gc.Restore() gc.Restore()
} }
saveToPngFile("TestStar", i) saveToPngFile("TestStar", i)
} }
func TestTransform() { func TestTransform() {
i, gc := initGc(800, 600) i, gc := initGc(800, 600)
gc.Save() gc.Save()
gc.Translate(40, 40) // Set origin to (40, 40) gc.Translate(40, 40) // Set origin to (40, 40)
gc.BeginPath() gc.BeginPath()
gc.MoveTo(0,0) gc.MoveTo(0, 0)
gc.RLineTo(72,0) gc.RLineTo(72, 0)
gc.RLineTo(0, 72) gc.RLineTo(0, 72)
gc.RLineTo(-72,0) gc.RLineTo(-72, 0)
gc.Close() gc.Close()
gc.Stroke() gc.Stroke()
gc.Restore() gc.Restore()
gc.Save() gc.Save()
gc.Translate(100, 150) // Translate origin to (100, 150) gc.Translate(100, 150) // Translate origin to (100, 150)
gc.Rotate(30* (math.Pi / 180.0)) // Rotate counter-clockwise by 30 degrees gc.Rotate(30 * (math.Pi / 180.0)) // Rotate counter-clockwise by 30 degrees
gc.BeginPath() gc.BeginPath()
gc.MoveTo(0,0) gc.MoveTo(0, 0)
gc.RLineTo(72,0) gc.RLineTo(72, 0)
gc.RLineTo(0, 72) gc.RLineTo(0, 72)
gc.RLineTo(-72,0) gc.RLineTo(-72, 0)
gc.Close() // Draw box... 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.Stroke() gc.Stroke()
gc.Restore() gc.Restore()
gc.Save() gc.Save()
gc.Translate(300, 300) // Set origin to (300, 300) gc.Translate(40, 300) // Translate to (40, 300)
gc.Rotate(45* (math.Pi / 180.0)) // Rotate coordinates by 45 degrees gc.Scale(0.5, 1) // Reduce x coord by 1/2, y coord left alone
gc.Scale(0.5, 1) // Scale coordinates
gc.BeginPath() gc.BeginPath()
gc.MoveTo(0,0) gc.MoveTo(0, 0)
gc.RLineTo(72,0) gc.RLineTo(72, 0)
gc.RLineTo(0, 72) gc.RLineTo(0, 72)
gc.RLineTo(-72,0) gc.RLineTo(-72, 0)
gc.Close() // Draw box gc.Close() // Draw box...
gc.Stroke() gc.Stroke()
gc.Restore() 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) saveToPngFile("TestTransform", i)
} }
func TestPathTransform() { func TestPathTransform() {
i, gc := initGc(800, 600) i, gc := initGc(800, 600)
gc.SetLineWidth(20) gc.SetLineWidth(20)
gc.Scale(1,5) gc.Scale(1, 5)
gc.ArcTo(200, 50, 50, 50, 0, math.Pi * 2) gc.ArcTo(200, 50, 50, 50, 0, math.Pi*2)
gc.Stroke() gc.Stroke()
saveToPngFile("TestPathTransform", i) saveToPngFile("TestPathTransform", i)
} }
func TestFillString() { func TestFillString() {
draw2d.SetFontFolder("../../fonts/") draw2d.SetFontFolder("../../fonts/")
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)
gc.FillStroke() gc.FillStroke()
gc.SetFontSize(18) gc.SetFontSize(18)
gc.MoveTo(10, 52) 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") width := gc.FillString("cou")
fmt.Printf("width: %f\n", width) fmt.Printf("width: %f\n", width)
gc.RMoveTo(width+1, 0) gc.RMoveTo(width+1, 0)

View file

@ -11,8 +11,8 @@ import (
"image" "image"
"image/png" "image/png"
//"draw2d" "draw2d"
"draw2d.googlecode.com/svn/trunk/draw2d/src/pkg/draw2d" //"draw2d.googlecode.com/svn/trunk/draw2d/src/pkg/draw2d"
) )
const ( const (
@ -64,26 +64,26 @@ func saveToPngFile(TestName string, m image.Image) {
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
blf := image.RGBAColor{0, 0, 0, 0xff} blf := image.RGBAColor{0, 0, 0, 0xff}
wf := image.RGBAColor{0xff, 0xff, 0xff, 0xff} wf := image.RGBAColor{0xff, 0xff, 0xff, 0xff}
nf := image.RGBAColor{0x8B, 0x45, 0x13, 0xff} nf := image.RGBAColor{0x8B, 0x45, 0x13, 0xff}
brf := image.RGBAColor{0x8B, 0x45, 0x13, 0x99} brf := image.RGBAColor{0x8B, 0x45, 0x13, 0x99}
brb := image.RGBAColor{0x8B, 0x45, 0x13, 0xBB} brb := image.RGBAColor{0x8B, 0x45, 0x13, 0xBB}
gc.MoveTo(x, y+h) gc.MoveTo(x, y+h)
gc.CubicCurveTo(x, y+h, x+w/2, y-h, x+w, y+h) gc.CubicCurveTo(x, y+h, x+w/2, y-h, x+w, y+h)
gc.Close() gc.Close()
gc.SetFillColor(brb) gc.SetFillColor(brb)
gc.Fill() 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() 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.SetFillColor(brf)
gc.Fill() gc.Fill()
draw2d.Circle(gc, x, y+h, w/12-10) draw2d.Circle(gc, x, y+h, w/12-10)
gc.SetFillColor(nf) gc.SetFillColor(nf)
gc.Fill() gc.Fill()
draw2d.Circle(gc, x+w, y+h, w/12) // right ear draw2d.Circle(gc, x+w, y+h, w/12) // right ear
gc.SetFillColor(brf) gc.SetFillColor(brf)
gc.Fill() 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 draw2d.Circle(gc, x+w/3, y+h23, w/9) // left eye
gc.SetFillColor(wf) gc.SetFillColor(wf)
gc.Fill() 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.SetFillColor(blf)
gc.Fill() gc.Fill()
draw2d.Circle(gc, x+w/3+15, y+h23, 5) 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 draw2d.Circle(gc, x+w-w/3, y+h23, w/9) // right eye
gc.Fill() 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.SetFillColor(blf)
gc.Fill() gc.Fill()
draw2d.Circle(gc, x+w-(w/3)+15, y+h23, 5) 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.Fill()
gc.SetFillColor(wf) 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() 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() 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.SetFillColor(nf)
gc.Fill() gc.Fill()
draw2d.Ellipse(gc, x+(w/2), y+h+10, w/10, w/12) // nose draw2d.Ellipse(gc, x+(w/2), y+h+10, w/10, w/12) // nose
gc.SetFillColor(blf) gc.SetFillColor(blf)
gc.Fill() gc.Fill()
} }
func main() { func main() {
@ -133,4 +132,4 @@ func main() {
gc.Rotate(-30 * (math.Pi / 180.0)) gc.Rotate(-30 * (math.Pi / 180.0))
gordon(gc, 48, 48, 240, 72) gordon(gc, 48, 48, 240, 72)
saveToPngFile("TestGopher", i) saveToPngFile("TestGopher", i)
} }