-
Notifications
You must be signed in to change notification settings - Fork 5
/
drawSpiral.go
47 lines (39 loc) · 1.03 KB
/
drawSpiral.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
// Creates multiple spirals
// Reference: http://www.pheelicks.com/2013/11/intro-to-images-in-go-fractals/
package main
// Import packages
import ("image"; "image/color"; "image/png";
"os"
"log"
"math/rand"
"time"
"fmt")
func createImage(iterations uint32, degree float64, factor float64) {
// Declare image size
width, height := 2048, 1024
// Create a new image
img := image.Rect(0, 0, width, height)
c := NewCanvas(img)
c.DrawGradient()
rand.Seed(time.Now().UTC().UnixNano())
for i:=0; i<300; i++ {
x := float64(width) * rand.Float64()
y := float64(height) * rand.Float64()
color := color.RGBA{uint8(rand.Intn(255)),
uint8(rand.Intn(255)),
uint8(rand.Intn(255)),
255}
c.DrawSpiral(color, Coordinate{x, y}, iterations, degree, factor)
}
name := fmt.Sprintf("spiral_%d_%f_%f.png", iterations, degree, factor)
file, err := os.Create(name)
if err != nil {
log.Fatal(err)
}
defer file.Close()
png.Encode(file, c)
}
func main() {
createImage(9000, 0.04, 0.999)
createImage(10000, 0.04, 0.9999)
}