-
Notifications
You must be signed in to change notification settings - Fork 3
/
model.go
63 lines (55 loc) · 1.34 KB
/
model.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
package main
import tea "github.com/charmbracelet/bubbletea"
type State int
const (
MandelbrotSet State = iota
JuliaSet
BurningShipSet
NumStates // represents the total number of states
)
type model struct {
height int
width int
zoom float64
yStart int
xStart int
maxIterations int
color int
state State
fractalFunction func(cr float64, ci float64, maxIterations int, bailout float64) int
palette []string
bailout float64
usecache bool
cache map[uint64]int
}
func initialModel() *model {
return &model{
zoom: 1.0,
yStart: 0,
xStart: 0,
maxIterations: 20,
color: DEF,
state: MandelbrotSet,
fractalFunction: mandelbrot,
palette: []string{"#421E0F", "#19071A", "#09012F", "#040449", "#000764", "#0C2C8A", "#1852B1", "#397DD1", "#86B5E5", "#D3ECF8", "#F1E9BF", "#F8C95F", "#FFAA00", "#CC8000", "#995700", "#6A3403"},
bailout: 4.0,
}
}
func (m *model) Init() tea.Cmd {
m.resetCache()
return nil
}
func (m *model) nextState() {
m.state = (m.state + 1) % NumStates
switch m.state {
case MandelbrotSet:
m.fractalFunction = mandelbrot
case JuliaSet:
m.fractalFunction = julia
case BurningShipSet:
m.fractalFunction = burningShip
}
}
func (m *model) resetCache() {
m.cache = make(map[uint64]int)
}