2010-11-28 22:29:34 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"exp/draw"
|
|
|
|
"exp/draw/x11"
|
|
|
|
"image"
|
|
|
|
"math"
|
2011-03-17 22:32:06 +00:00
|
|
|
"draw2d.googlecode.com/hg/draw2d"
|
2010-11-28 22:29:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
window, err := x11.NewWindow()
|
2010-12-06 17:18:39 +00:00
|
|
|
if err != nil {
|
2010-11-28 22:29:34 +00:00
|
|
|
fmt.Printf("Cannot open an x11 window\n")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
screen := window.Screen()
|
|
|
|
if rgba, ok := screen.(*image.RGBA); ok {
|
|
|
|
gc := draw2d.NewGraphicContext(rgba)
|
|
|
|
gc.SetStrokeColor(image.Black)
|
|
|
|
gc.SetFillColor(image.White)
|
|
|
|
gc.Clear()
|
2010-12-06 17:18:39 +00:00
|
|
|
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
|
2010-11-28 22:29:34 +00:00
|
|
|
}
|
|
|
|
fmt.Printf("This is an rgba image\n")
|
2010-12-06 17:18:39 +00:00
|
|
|
|
2010-11-28 22:29:34 +00:00
|
|
|
window.FlushImage()
|
2010-12-06 17:18:39 +00:00
|
|
|
|
2010-11-28 22:29:34 +00:00
|
|
|
gc.SetLineWidth(3)
|
|
|
|
nbclick := 0
|
|
|
|
for {
|
2010-12-06 17:18:39 +00:00
|
|
|
|
2010-11-28 22:29:34 +00:00
|
|
|
switch evt := (<-window.EventChan()).(type) {
|
|
|
|
case draw.KeyEvent:
|
2010-12-06 17:18:39 +00:00
|
|
|
if evt.Key == 'q' {
|
2010-11-28 22:29:34 +00:00
|
|
|
window.Close()
|
|
|
|
}
|
|
|
|
case draw.MouseEvent:
|
2010-12-06 17:18:39 +00:00
|
|
|
if evt.Buttons&1 != 0 {
|
|
|
|
if nbclick%2 == 0 {
|
2011-02-02 21:38:17 +00:00
|
|
|
gc.MoveTo(float64(evt.Loc.X), float64(evt.Loc.Y))
|
2010-11-28 22:29:34 +00:00
|
|
|
} else {
|
2011-02-02 21:38:17 +00:00
|
|
|
gc.LineTo(float64(evt.Loc.X), float64(evt.Loc.Y))
|
2010-11-28 22:29:34 +00:00
|
|
|
gc.Stroke()
|
|
|
|
window.FlushImage()
|
|
|
|
}
|
|
|
|
nbclick = nbclick + 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fmt.Printf("Not an RGBA image!\n")
|
|
|
|
}
|
2010-12-06 17:18:39 +00:00
|
|
|
}
|