Shrink 2x and shift down so we can see the whole set

Fix 0x zoom - dividing by 0 is not fun
This commit is contained in:
Steven Polley 2018-08-02 23:34:39 -06:00
parent cd0cb9195a
commit ba0ef17b06
2 changed files with 11 additions and 9 deletions

View File

@ -18,7 +18,7 @@ import (
)
const (
Size = 256
Size = 128
Iterations = (1<<16 - 1) / 128
)
@ -54,8 +54,8 @@ func computeThread() {
for p := range queue {
val := mandelbrot(
complex(
(float64(p.x)/Size+float64(p.tileX))/float64(uint(1<<p.tileZoom)),
(float64(p.y)/Size+float64(p.tileY))/float64(uint(1<<p.tileZoom)),
(float64(p.x)/Size+float64(p.tileX))/float64(uint(1<<(p.tileZoom-1))),
(float64(p.y)/Size+float64(p.tileY))/float64(uint(1<<(p.tileZoom-1))),
),
)
p.out.SetRGBA(p.x, p.y, colors[val])
@ -110,7 +110,8 @@ func renderTile(w http.ResponseWriter, r *http.Request) {
for x := 0; x < Size; x++ {
for y := 0; y < Size; y++ {
queue <- pixel{img, x, y, tileX, tileY, uint16(tileZoom), &wg}
queue <- pixel{img, x, y, tileX - int64(1<<tileZoom-1) - 1, tileY, uint16(tileZoom), &wg}
}
}
@ -119,7 +120,7 @@ func renderTile(w http.ResponseWriter, r *http.Request) {
/*
ip := GetOutboundIP()
addLabel(img, 20, 30, fmt.Sprintf("rendered by \n%s", ip.String()))
//addLabel(img, 20, 30, fmt.Sprintf("%s/%s/%s.png", components[1], components[2], components[3]))
addLabel(img, 20, 30, fmt.Sprintf("%s/%s/%s.png", components[1], components[2], components[3]))
*/
w.Header().Set("Content-Type", "image/png")
png.Encode(w, img)
@ -213,6 +214,7 @@ func addLabel(img *image.RGBA, x, y int, label string) {
d.DrawString(label)
}
func GetOutboundIP() net.IP {
conn, err := net.Dial("udp", "8.8.8.8:80")
if err != nil {

8
web.go
View File

@ -23,10 +23,10 @@ var mandelbrotTypeOptions = {
getTileUrl: function(coord, zoom) {
return '/mandelbrot/' + zoom + '/' + coord.x + '/' + coord.y + '.png';
},
tileSize: new google.maps.Size(256, 256),
maxZoom: (1<<16) - 1,
minZoom: 0,
name: 'Mandelbrot'
tileSize: new google.maps.Size(128, 128),
maxZoom: (1<<16),
minZoom: 1,
name: '0xdeadbeef Mandel Mapper'
};
var mandelbrotMapType = new google.maps.ImageMapType(mandelbrotTypeOptions);