-
Notifications
You must be signed in to change notification settings - Fork 0
/
history.go
67 lines (52 loc) · 1.05 KB
/
history.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
package main
import (
"log"
"github.com/johnny-morrice/godelbrot/config"
)
type history struct {
frames []*rendercmd
}
var __history *history
func gethistory() *history {
if __history == nil {
__history = &history{}
__history.frames = []*rendercmd{getfractal().defaultrendercmd()}
}
return __history
}
func (h *history) back() {
count := len(h.frames)
if count > 1 {
h.frames = h.frames[:count - 1]
h.render()
}
}
func (h *history) last() *rendercmd {
return h.frames[len(h.frames) - 1]
}
func (h *history) restart() {
h.frames = h.frames[:1]
h.render()
}
func (h *history) render() {
go func() {
pic, err := h.last().render()
if err != nil {
log.Printf("Render error: %v", err)
return
}
getfractal().replace(pic)
}()
}
func (h *history) zoom(bounds []uint) {
zb := config.ZoomBounds{}
zb.Xmin = bounds[0]
zb.Xmax = bounds[1]
zb.Ymin = bounds[2]
zb.Ymax = bounds[3]
x, y := getfractal().dims()
parent := h.last().addr
next := zoomcmd(x, y, parent, zb)
h.frames = append(h.frames, next)
h.render()
}