如何使用 Go 在 X11 中绘图

发布于 2024-10-16 00:53:07 字数 117 浏览 4 评论 0原文

我一直在研究 Go 附带的 drawdraw.x11 包。我没有找到在 X11 窗口上画线的简单方法。

在哪里可以找到一些简单的 2D 绘图示例?

I've been looking into draw and draw.x11 packages that come with Go. I didn't find out a simple way to draw a line on a X11 window.

Where I can find some simple 2D drawing examples?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

怪我入戏太深 2024-10-23 00:53:07

我自己找到了答案,这是一个简单的例子:

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)
}

I found myself the answer, here it goes a simple example:

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)
}
尐偏执 2024-10-23 00:53:07

虽然您的解决方案有效,但我认为您真正需要的是 X Go Binding

While your solution works, I think what you're really looking for is X Go Binding

微凉 2024-10-23 00:53:07
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
}                                                     
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
}                                                     
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文