Skip to content

Commit 9cf2a8f

Browse files
committed
Squashed commit of the following:
commit 7b94a3a Author: TheTeaCat <[email protected]> Date: Mon Jan 18 02:48:25 2021 +0000 Add tricorn set to readme commit f18ec12 Author: TheTeaCat <[email protected]> Date: Mon Jan 18 02:41:44 2021 +0000 Lint+comment commit 5a70784 Author: TheTeaCat <[email protected]> Date: Mon Jan 18 02:22:43 2021 +0000 Implement birdofprey and multiburningship fractals commit 0bbb652 Author: TheTeaCat <[email protected]> Date: Mon Jan 18 02:22:30 2021 +0000 Make color funcs take kwargs to allow better smooth coloring support commit a652e71 Author: TheTeaCat <[email protected]> Date: Sun Jan 17 23:19:06 2021 +0000 Add burning ship lady to readme commit a417de1 Author: TheTeaCat <[email protected]> Date: Sun Jan 17 19:56:29 2021 +0000 Add supersampling to multibrot and multijulia examples commit 58c12a9 Author: Joshua O'Sullivan <[email protected]> Date: Sun Jan 17 19:53:36 2021 +0000 Update readme commit dc3f4e0 Author: Joshua O'Sullivan <[email protected]> Date: Sun Jan 17 19:51:50 2021 +0000 Update readme commit b8bf9a9 Author: TheTeaCat <[email protected]> Date: Sun Jan 17 19:44:15 2021 +0000 Add multicorn example animation commit a6bd9ad Author: TheTeaCat <[email protected]> Date: Sun Jan 17 19:43:58 2021 +0000 Add multibrot and multijulia sample images commit 687d962 Author: TheTeaCat <[email protected]> Date: Sun Jan 17 18:34:31 2021 +0000 Update descriptions commit 7660762 Author: TheTeaCat <[email protected]> Date: Sun Jan 17 18:31:07 2021 +0000 Implement multibrot, multijulia and multicorn fractals (closes #8) commit 8f7d5f5 Author: TheTeaCat <[email protected]> Date: Sun Jan 17 18:29:23 2021 +0000 Minor refactor of genRoutine
1 parent e2770ac commit 9cf2a8f

File tree

4 files changed

+261
-82
lines changed

4 files changed

+261
-82
lines changed

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Supported Fractals:
88
- [Julia sets](#a-julia-set)
99
- [The Burning Ship fractal](#the-burning-ship-fractal)
1010
- [The Collatz fractal](#the-collatz-fractal)
11+
- The Tricorn set
1112
- [Multicorn sets](#a-multicorn-animation)
1213
- [Multibrot sets](#a-multibrot-set)
1314
- [Multijulia sets](#a-multijulia-set)
@@ -194,3 +195,11 @@ done
194195
<p align="center">
195196
<img src="./samples/julia3.png" width="70%">
196197
</p>
198+
199+
### The Burning Ship Lady
200+
```
201+
-ff=burningship -z=100 -y=1.015 -cf=wackygrayscale -ss=8 -w=2000 -h=2000
202+
```
203+
<p align="center">
204+
<img src="./samples/burningshiplady.png" width="70%">
205+
</p>

lib/colors.go

+40-30
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,33 @@ import (
55
"math"
66
)
77

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)
1812

1913
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) {
2115
col := float64(255*iterations) / float64(iterationCap)
2216
return col, col, col, 255
2317
},
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)
2520
col := 255.0 * (math.Mod(z.abs(), 2.0) / 2.0)
2621
return col, col, col, 255
2722
},
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++
3323

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)
3530

31+
z = iterator(iterator(z))
32+
iterations += 2
33+
34+
i := float64(iterations)
3635
if iterations < iterationCap {
3736
i = i - (math.Log(math.Log(z.abs())) / math.Log(2))
3837
}
@@ -45,14 +44,14 @@ var colorSchemes = map[string]colorFunc{
4544
return col, col, col, 255
4645

4746
},
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)
5350

54-
i := float64(iterations)
51+
z = iterator(iterator(z))
52+
iterations += 2
5553

54+
i := float64(iterations)
5655
if iterations < iterationCap {
5756
i = i - (math.Log(math.Log(z.abs())) / math.Log(2))
5857
}
@@ -69,14 +68,14 @@ var colorSchemes = map[string]colorFunc{
6968
}
7069
return 0, 0, 0, 255
7170
},
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)
7774

78-
i := float64(iterations)
75+
z = iterator(iterator(z))
76+
iterations += 2
7977

78+
i := float64(iterations)
8079
if iterations < iterationCap {
8180
i = i - (math.Log(math.Log(z.abs())) / math.Log(2))
8281
}
@@ -93,6 +92,8 @@ var colorSchemes = map[string]colorFunc{
9392
}
9493
return 0, 0, 0, 255
9594
},
95+
96+
// 'wacky' coloring functions simply iterate over a set of colors.
9697
"wackyrainbow": wacky([]color.RGBA{
9798
color.RGBA{84, 110, 98, 255}, // grey-green
9899
color.RGBA{79, 127, 135, 255}, // turq
@@ -108,3 +109,12 @@ var colorSchemes = map[string]colorFunc{
108109
color.RGBA{255, 255, 255, 255},
109110
}),
110111
}
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

Comments
 (0)