-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.go
More file actions
50 lines (42 loc) · 685 Bytes
/
util.go
File metadata and controls
50 lines (42 loc) · 685 Bytes
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
package main
import (
"image"
"image/png"
"log"
"math"
"math/rand"
"os"
"time"
)
func init() {
rand.Seed(time.Now().UTC().UnixNano())
}
func randomF(min, max float64) float64 {
return min + rand.Float64()*(max-min)
}
func random() float64 {
return randomF(0.0, 1.0)
}
func clamp(x, min, max float64) float64 {
if x < min {
return min
}
if x > max {
return max
}
return x
}
func degreesToRadians(degrees float64) float64 {
return degrees * math.Pi / 180.0
}
func writePNG(img *image.RGBA, filename string) {
f, err := os.Create(filename)
if err != nil {
log.Fatal(err)
}
defer f.Close()
err = png.Encode(f, img)
if err != nil {
log.Fatal(err)
}
}