/
glot15.go
70 lines (57 loc) · 1.39 KB
/
glot15.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
// Seriál "Programovací jazyk Go"
// https://www.root.cz/serialy/programovaci-jazyk-go/
//
// Padesátá část
// Tvorba grafů v jazyce Go
// https://www.root.cz/clanky/tvorba-grafu-v-jazyce-go/
//
// Repositář:
// https://github.com/tisnik/go-root/
//
// Seznam demonstračních příkladů z padesáté části:
// https://github.com/tisnik/go-root/blob/master/article_50/README.md
//
// Dokumentace ve stylu "literate programming":
// https://tisnik.github.io/go-root/article_50/glot15.html
package main
import (
"github.com/Arafatk/glot"
"math"
)
type Plot struct {
*glot.Plot
}
func (plot *Plot) Save(filename string) {
plot.Cmd("set terminal pngcairo")
plot.Cmd("set output '" + filename + "'")
plot.Cmd("replot")
}
func NewPlot(dimensions int) *Plot {
plot, err := glot.NewPlot(dimensions, false, false)
if err != nil {
panic(err)
}
return &Plot{plot}
}
const points = 400
func main() {
plot := NewPlot(3)
defer plot.Close()
var pointsX [points]float64
var pointsY [points]float64
for i := 0; i < points; i++ {
t := float64(i) * 8.0 * math.Pi / points
pointsX[i] = math.Sin(t)
pointsY[i] = math.Cos(t)
}
z := 0.0
function1 := func(u, v float64) float64 {
z = z + 1.0
return z
}
plot.AddFunc3d("spiral", "points", pointsX[:], pointsY[:], function1)
plot.SetTitle("Plot #15")
plot.SetXLabel("t")
plot.SetYLabel("y")
plot.Save("glot15.png")
}