How to draw in X11 with Go

I looked at the packages drawand draw.x11that come with Go. I did not find an easy way to draw a line in the X11 window.

Where can I find simple examples of 2D drawings?

+3
source share
3 answers

I found the answer, here it looks simple:

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)
}
+4
source

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

+3
source
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
}                                                     
+1
source

Source: https://habr.com/ru/post/1790179/


All Articles