-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
90 lines (76 loc) · 1.56 KB
/
main.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
89
90
package main
import (
"fmt"
"github.com/andrepxx/sydney/color"
"github.com/andrepxx/sydney/coordinates"
"github.com/andrepxx/sydney/scene"
"image"
imagecolor "image/color"
"image/draw"
"image/png"
"math/rand"
"os"
)
/*
* Sample program demonstrating sydney graphics library.
*/
func main() {
scn := scene.Create(800, 800, -5.0, 5.0, -5.0, 5.0)
data := make([]coordinates.Cartesian, 1000)
/*
* Create a total of a hundred thousand data points.
*/
for j := 0; j < 100; j++ {
/*
* Generate some data.
*/
for i := range data {
x := rand.NormFloat64()
y := rand.NormFloat64()
data[i] = coordinates.CreateCartesian(x, y)
}
scn.Aggregate(data)
}
scn.Spread(1)
mapping := color.DefaultMapping()
img, err := scn.Render(mapping)
/*
* Check if an error occured during rendering.
*/
if err != nil {
msg := err.Error()
fmt.Printf("Something went wrong: %s\n", msg)
} else {
dim := image.Rect(0, 0, 800, 800)
target := image.NewNRGBA(dim)
/*
* The background color.
*/
c := imagecolor.NRGBA{
R: 0,
G: 0,
B: 0,
A: 255,
}
uniform := image.NewUniform(c)
draw.Draw(target, dim, uniform, image.ZP, draw.Over)
draw.Draw(target, dim, img, image.ZP, draw.Over)
/*
* The PNG encoder.
*/
enc := png.Encoder{
CompressionLevel: png.BestCompression,
}
fd, err := os.Create("output.png")
/*
* Check if there was an error creating the file.
*/
if err != nil {
msg := err.Error()
fmt.Printf("Error creating output file: %s", msg)
} else {
enc.Encode(fd, target)
fd.Close()
}
}
}