@@ -5,34 +5,33 @@ import (
5
5
"math"
6
6
)
7
7
8
- type colorFunc func (iterations , iterationCap int , z , c complex ) (R , G , B , A float64 )
9
-
10
- // returns a color func that cycles through the set of colors passed in
11
- func wacky (colors []color.RGBA ) colorFunc {
12
- return func (iterations , iterationCap int , z , c complex ) (R , G , B , A float64 ) {
13
- key := iterations % len (colors )
14
- color := colors [key ]
15
- return float64 (color .R ), float64 (color .G ), float64 (color .B ), float64 (color .A )
16
- }
17
- }
8
+ /* The relationship between fractals and colorFuncs is many to many, so the use
9
+ of a map[string]interface{} kwargs here is justifiable.
10
+ */
11
+ type colorFunc func (iterations , iterationCap int , kwargs map [string ]interface {}) (R , G , B , A float64 )
18
12
19
13
var colorSchemes = map [string ]colorFunc {
20
- "simplegrayscale" : func (iterations , iterationCap int , z , c complex ) (R , G , B , A float64 ) {
14
+ "simplegrayscale" : func (iterations , iterationCap int , kwargs map [ string ] interface {} ) (R , G , B , A float64 ) {
21
15
col := float64 (255 * iterations ) / float64 (iterationCap )
22
16
return col , col , col , 255
23
17
},
24
- "zgrayscale" : func (iterations , iterationCap int , z , c complex ) (R , G , B , A float64 ) {
18
+ "zgrayscale" : func (iterations , iterationCap int , kwargs map [string ]interface {}) (R , G , B , A float64 ) {
19
+ z := kwargs ["z" ].(complex )
25
20
col := 255.0 * (math .Mod (z .abs (), 2.0 ) / 2.0 )
26
21
return col , col , col , 255
27
22
},
28
- "smoothgrayscale" : func (iterations , iterationCap int , z , c complex ) (R , G , B , A float64 ) {
29
- z = z .mul (z ).add (c )
30
- iterations ++
31
- z = z .mul (z ).add (c )
32
- iterations ++
33
23
34
- i := float64 (iterations )
24
+ // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
25
+ // !!! Smooth coloring functions only work for some fractals where z is raised to a power of 2 !!!
26
+ // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
27
+ "smoothgrayscale" : func (iterations , iterationCap int , kwargs map [string ]interface {}) (R , G , B , A float64 ) {
28
+ z := kwargs ["z" ].(complex )
29
+ iterator := kwargs ["iterator" ].(func (complex ) complex )
35
30
31
+ z = iterator (iterator (z ))
32
+ iterations += 2
33
+
34
+ i := float64 (iterations )
36
35
if iterations < iterationCap {
37
36
i = i - (math .Log (math .Log (z .abs ())) / math .Log (2 ))
38
37
}
@@ -45,14 +44,14 @@ var colorSchemes = map[string]colorFunc{
45
44
return col , col , col , 255
46
45
47
46
},
48
- "smoothcolor" : func (iterations , iterationCap int , z , c complex ) (R , G , B , A float64 ) {
49
- z = z .mul (z ).add (c )
50
- iterations ++
51
- z = z .mul (z ).add (c )
52
- iterations ++
47
+ "smoothcolor" : func (iterations , iterationCap int , kwargs map [string ]interface {}) (R , G , B , A float64 ) {
48
+ z := kwargs ["z" ].(complex )
49
+ iterator := kwargs ["iterator" ].(func (complex ) complex )
53
50
54
- i := float64 (iterations )
51
+ z = iterator (iterator (z ))
52
+ iterations += 2
55
53
54
+ i := float64 (iterations )
56
55
if iterations < iterationCap {
57
56
i = i - (math .Log (math .Log (z .abs ())) / math .Log (2 ))
58
57
}
@@ -69,14 +68,14 @@ var colorSchemes = map[string]colorFunc{
69
68
}
70
69
return 0 , 0 , 0 , 255
71
70
},
72
- "smoothcolor2" : func (iterations , iterationCap int , z , c complex ) (R , G , B , A float64 ) {
73
- z = z .mul (z ).add (c )
74
- iterations ++
75
- z = z .mul (z ).add (c )
76
- iterations ++
71
+ "smoothcolor2" : func (iterations , iterationCap int , kwargs map [string ]interface {}) (R , G , B , A float64 ) {
72
+ z := kwargs ["z" ].(complex )
73
+ iterator := kwargs ["iterator" ].(func (complex ) complex )
77
74
78
- i := float64 (iterations )
75
+ z = iterator (iterator (z ))
76
+ iterations += 2
79
77
78
+ i := float64 (iterations )
80
79
if iterations < iterationCap {
81
80
i = i - (math .Log (math .Log (z .abs ())) / math .Log (2 ))
82
81
}
@@ -93,6 +92,8 @@ var colorSchemes = map[string]colorFunc{
93
92
}
94
93
return 0 , 0 , 0 , 255
95
94
},
95
+
96
+ // 'wacky' coloring functions simply iterate over a set of colors.
96
97
"wackyrainbow" : wacky ([]color.RGBA {
97
98
color.RGBA {84 , 110 , 98 , 255 }, // grey-green
98
99
color.RGBA {79 , 127 , 135 , 255 }, // turq
@@ -108,3 +109,12 @@ var colorSchemes = map[string]colorFunc{
108
109
color.RGBA {255 , 255 , 255 , 255 },
109
110
}),
110
111
}
112
+
113
+ // returns a color func that cycles through the set of colors passed in
114
+ func wacky (colors []color.RGBA ) colorFunc {
115
+ return func (iterations , iterationCap int , kwargs map [string ]interface {}) (R , G , B , A float64 ) {
116
+ key := iterations % len (colors )
117
+ color := colors [key ]
118
+ return float64 (color .R ), float64 (color .G ), float64 (color .B ), float64 (color .A )
119
+ }
120
+ }
0 commit comments