-
Notifications
You must be signed in to change notification settings - Fork 0
/
mandel.go
69 lines (54 loc) · 1.33 KB
/
mandel.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
package main
import ("image";
"image/png";
"image/color";
"bufio";
"fmt";
"os";
"math";
"time"; )
func PointIteration(cx,cy,maxValue float64,maxIter uint8) uint8{
quadValue := float64(0.0);
iter := uint8(0);
x := float64(0.0);
y := float64(0.0);
for quadValue <= maxValue && iter < maxIter {
xt:= ( x * x ) - ( y * y) + cx;
yt:= ( float64(2.0) * x * y ) + cy;
x = xt;
y = yt;
iter++;
quadValue = ( x * x ) + ( y * y );
}
return iter;
}
func main(){
start := time.Now();
const pictureSize = 5000;
img := image.NewRGBA(image.Rect(0,0,pictureSize,pictureSize));
f, err := os.OpenFile("mandel.png", os.O_WRONLY|os.O_CREATE, 0666);
if err != nil {
fmt.Printf("Can't create picture file\n");
}
deltaX := math.Abs(float64(-2.0 - 1.0)) / float64(pictureSize);
deltaY := math.Abs(float64(-1.0 - 1.0)) / float64(pictureSize);
cx := float64(-2.0);
for x:=0;x<pictureSize;x++ {
cx+=deltaX;
cy := float64(-1.0);
for y:=0;y<pictureSize;y++ {
cy+=deltaY;
iter := PointIteration(cx,cy,255.0,255);
col := color.RGBA{255,iter,iter,iter};
col.A = 255;
col.R = iter;
col.G = iter;
col.B = iter;
img.Set(x,y,col);
}
}
w := bufio.NewWriter(f);
png.Encode(w,img);
w.Flush();
fmt.Printf("Seconds needed %d\n",time.Now().Sub(start));
}