-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
75 lines (54 loc) · 1.53 KB
/
main.go
File metadata and controls
75 lines (54 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"image"
"image/color"
"sync"
"time"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/canvas"
)
// func checkError(err error) {
// if err != nil {
// log.Fatal(err)
// }
// }
func colorIt(rstart int, rend int, cstart int, cend int, img *image.RGBA, clr *color.RGBA, wg *sync.WaitGroup, fi *canvas.Image) {
defer wg.Done()
for i := rstart; i <= rend; i++ {
for j := cstart; j <= cend; j++ {
img.Set(i, j, clr)
fi.Refresh()
time.Sleep(time.Nanosecond)
}
}
}
func main() {
width := 600
height := 600
img := image.NewRGBA(image.Rect(1, 1, width, height))
// Create a new image of type RGBA which takes a parameter of rect which creates a rect with specified minimum and maximum coordinates
clr := &color.RGBA{255, 255, 255, 255}
for i := 1; i <= 600; i++ {
for j := 1; j <= 600; j++ {
img.Set(i, j, clr)
}
}
myGui := app.New() // Initialising the fyne class
window := myGui.NewWindow("Thread Visualizer")
fyneImage := canvas.NewImageFromImage(img)
window.SetContent(fyneImage)
window.Resize(fyne.NewSize(600, 600))
red := &color.RGBA{255, 0, 0, 255}
blue := &color.RGBA{0, 0, 255, 255}
green := &color.RGBA{0, 255, 0, 255}
randColor := &color.RGBA{128, 124, 234, 255}
wg := &sync.WaitGroup{}
wg.Add(4)
go colorIt(1, 300, 1, 300, img, red, wg, fyneImage)
go colorIt(301, 600, 1, 300, img, blue, wg, fyneImage)
go colorIt(1, 300, 301, 600, img, green, wg, fyneImage)
go colorIt(301, 600, 301, 600, img, randColor, wg, fyneImage)
window.ShowAndRun()
wg.Wait()
}