Last active
August 14, 2020 04:00
-
-
Save dhotson/4df31d48c184678fec36fb959f4ba413 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"image" | |
"math" | |
"os" | |
"sync" | |
"github.com/disintegration/gift" | |
"golang.org/x/image/tiff" | |
) | |
var w = float64(1200) | |
var h = float64(1200) | |
func main() { | |
var wg sync.WaitGroup | |
wg.Add(1) | |
go draw(0.0, &wg) | |
// go draw("image2.tiff", 0.1, &wg) | |
// go draw("image3.tiff", 0.2, &wg) | |
// go draw("image4.tiff", 0.3, &wg) | |
wg.Wait() | |
} | |
func plot(x float64, y float64) (int, int) { | |
return int(x*(w/4-2) + w/2), int(y*(w/4-2) + w/2) | |
} | |
func draw(seed float64, wg *sync.WaitGroup) { | |
defer wg.Done() | |
r := image.Rectangle{image.Point{0, 0}, image.Point{int(w), int(h)}} | |
a := float64(1.141914030) | |
b := float64(-2.28415230) | |
c := float64(2.42754030) | |
d := float64(-2.1771960) | |
// a = 3.1857827494137165 | |
// b = -0.3198765697284589 | |
// c = 2.360541685422172 | |
// d = 3.7715199253585237 | |
// Trying out some different numbers... | |
a, b, c, d = -3.691189689088887, -1.6092399803788613, -3.237184177967544, 1.0777434951897948 | |
a, b, c, d = 0.9007053969634278, -2.637442325264809, 1.7301797869949507, -3.9470323418777316 | |
a, b, c, d = 2.503099257297462, -3.368168279026971, 1.0470005061998595, 100.21597068244601 | |
a, b, c, d = -3.1786357692725513, -2.5369374008830796, -1.3966670936288477, -1.1863296941409676 | |
a, b, c, d = -3.500319454310196, -2.274038540095157, 2.197560305067105, -3.341233355959094 | |
a, b, c, d = -3.3961435716410797, -3.6251089470068134, -3.928629774986387, -1.8938605382165878 | |
a, b, c, d = -1.2172606689053183, 3.238552831567606, 0.4987222602920749, 3.4832339552396494 | |
name := fmt.Sprintf("image-%f,%f,%f,%f.tiff", a, b, c, d) | |
img := image.NewGray16(r) | |
f, err := os.Create(name) | |
if err != nil { | |
panic(err) | |
} | |
defer f.Close() | |
x := float64(seed) | |
y := float64(seed) | |
xn := float64(0) | |
yn := float64(0) | |
max := uint16(0) | |
n := 0 | |
for true { | |
xn = math.Sin(a*y) - math.Cos(b*x) | |
yn = math.Sin(c*x) - math.Cos(d*y) | |
// fmt.Printf("%-2.2f, %-2.2f\n", xn, yn) | |
sx, sy := plot(xn, yn) | |
color := img.Gray16At(sx, sy) | |
if color.Y >= uint16(65535) { | |
break | |
} | |
// Factors of 65535 .. 1, 3, 5, 15, 17, 51, 85, 255, 257, 771, 1285, 3855, 4369, 13107, 21845. | |
color.Y += 15 | |
img.SetGray16(sx, sy, color) | |
if color.Y >= max { | |
max = color.Y | |
} | |
if n%10000000 == 0 { | |
fmt.Printf("seed %1.1f max: %d n:%d\n", seed, max, n) | |
} | |
n = n + 1 | |
x = xn | |
y = yn | |
} | |
g := gift.New( | |
gift.ColorspaceLinearToSRGB(), | |
gift.Gamma(2.5), | |
gift.Invert(), | |
) | |
img2 := image.NewGray16(r) | |
g.Draw(img2, img) | |
tiff.Encode(f, img2, nil) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment