-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathplasma.go
88 lines (63 loc) · 1.33 KB
/
plasma.go
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
76
77
78
79
80
81
82
83
84
85
86
87
88
package main
import (
"image/color"
"time"
"github.com/faiface/pixel"
"github.com/faiface/pixel/pixelgl"
"github.com/peterhellberg/plasma"
"github.com/peterhellberg/plasma/palette"
)
const (
width = 768
height = 768
size = 256
)
func run() {
scale := float64(height) / float64(size)
cfg := pixelgl.WindowConfig{
Bounds: pixel.R(0, 0, 1024, 512),
VSync: true,
Resizable: false,
Undecorated: true,
}
win, err := pixelgl.NewWindow(cfg)
if err != nil {
panic(err)
}
win.SetSmooth(false)
var s *pixel.Sprite
size := 12.0
p := plasmaPicture(256, 128, size, 0)
s = pixel.NewSprite(p, p.Bounds())
go func() {
c := time.Tick(32 * time.Millisecond)
var i int
for range c {
i++
p := plasmaPicture(256, 128, size, i)
s.Set(p, p.Bounds())
}
}()
win.Clear(color.Black)
c := win.Bounds().Center()
for !win.Closed() {
win.Update()
s.Draw(win, pixel.IM.Moved(c).Scaled(c, scale))
if win.Pressed(pixelgl.KeyUp) {
size += 0.2
}
if win.Pressed(pixelgl.KeyDown) {
size -= 0.2
}
if win.JustPressed(pixelgl.KeyEscape) || win.JustPressed(pixelgl.KeyQ) {
return
}
}
}
func plasmaPicture(w, h int, s float64, i int) *pixel.PictureData {
return pixel.PictureDataFromImage(plasma.New(w, h, s).
Image(w, h, i, palette.DefaultGradient))
}
func main() {
pixelgl.Run(run)
}