【发布时间】:2011-02-05 13:42:15
【问题描述】:
我一直在研究 Go 附带的 draw 和 draw.x11 软件包。我没有找到在 X11 窗口上画线的简单方法。
在哪里可以找到一些简单的 2D 绘图示例?
【问题讨论】:
我一直在研究 Go 附带的 draw 和 draw.x11 软件包。我没有找到在 X11 窗口上画线的简单方法。
在哪里可以找到一些简单的 2D 绘图示例?
【问题讨论】:
我自己找到了答案,这里举个简单的例子:
package main
import (
"os"
"time"
"image"
"exp/draw/x11"
)
func main() {
win, _ := x11.NewWindow()
color := image.RGBAColor{255, 255, 255, 255}
img := win.Screen()
for i, j := 0, 0; i < 100 && j < 100; i, j = i + 1, j + 1 {
img.Set(i, j, color)
}
win.FlushImage()
time.Sleep(10 * 1000 * 1000 * 1000)
win.Close()
os.Exit(0)
}
【讨论】:
exp/draw/x11 和 gui/x11 已从主要 go repo 中删除,工作已移至 code.google.com/p/x-go-binding/xgb: code.google.com/p/x-go-binding
虽然您的解决方案有效,但我认为您真正需要的是 X Go Binding
【讨论】:
package main
import (
"fmt"
"code.google.ui/x11" // i'm not sure this is the actual package
"time" // name u better refer the packages
"os"
)
func main() {
win,err := x11.NewWindowArea(600,600) // it creates a window with 600 width&600
if err != nil { // height
fmt.Println(err)
os.Exit(0) // if any err occurs it exits
}
img :=win.Screen // in this newly created screen u cn draw
for i:=0;i<100;i++ { // any thing pixel by pixel
for j:=0;j<100;j++ {
img.Set(0+i,0+j,image.Black) // now this draws a square in the black
} // color oo the created screen
}
win.FlushImage() // its for flushing the image then only new
time.Sleep(time.Second*15) // image cn be draw
}
【讨论】: