diff --git a/web/render.go b/web/render.go
index 54eddba..b38992e 100644
--- a/web/render.go
+++ b/web/render.go
@@ -1,16 +1,20 @@
package main
import (
+ "fmt"
"image"
"image/color"
"image/png"
"log"
+ "math"
"math/cmplx"
"net/http"
"runtime"
"strconv"
"strings"
"sync"
+
+ "deadbeef.codes/steven/mandelbrot/palette"
)
const (
@@ -19,6 +23,10 @@ const (
Brighten = 1024
)
+var (
+ colors []color.RGBA
+)
+
func mandelbrot(c complex128) uint16 {
var z complex128
@@ -33,7 +41,7 @@ func mandelbrot(c complex128) uint16 {
}
type pixel struct {
- out *image.Gray16
+ out *image.RGBA
x, y int
tileX, tileY int64
tileZoom uint8
@@ -50,8 +58,8 @@ func computeThread() {
(float64(p.y)/Size+float64(p.tileY))/float64(uint(1<
= steps[j] && i < steps[j+1] {
+ min = steps[j]
+ max = steps[j+1]
+ minColor = float64(cols[j])
+ maxColor = float64(cols[j+1])
+ uintColor := cosineInterpolation(maxColor, minColor, (i-min)/(max-min))
+ interpolated = append(interpolated, uint32(uintColor))
+ }
+ }
+ }
+ }
+
+ for _, pixelValue := range interpolated {
+ r := pixelValue >> 24 & 0xff
+ g := pixelValue >> 16 & 0xff
+ b := pixelValue >> 8 & 0xff
+ a := 0xff
+
+ interpolatedColors = append(interpolatedColors, color.RGBA{uint8(r), uint8(g), uint8(b), uint8(a)})
+ }
+ }
+ }
+ }
+
+ return interpolatedColors
+}
+
+func cosineInterpolation(c1, c2, mu float64) float64 {
+ mu2 := (1 - math.Cos(mu*math.Pi)) / 2.0
+ return c1*(1-mu2) + c2*mu2
+}
+
+func linearInterpolation(c1, c2, mu uint32) uint32 {
+ return c1*(1-mu) + c2*mu
+}
diff --git a/web/web.go b/web/web.go
index 3335121..9e03974 100644
--- a/web/web.go
+++ b/web/web.go
@@ -16,7 +16,7 @@ func init() {
fmt.Fprintf(w, `
-Mandelbrot Map
+MandelMapper