Skip to content

Commit 0e121d0

Browse files
committed
Merge branch 'master' of github.com:SimonWaldherr/bbmandelbrotGo
2 parents 371105d + f0ce476 commit 0e121d0

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

demo/webexample.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
package main
44

55
import (
6-
bbmandelbrot "simonwaldherr.de/go/bbmandelbrotGo"
76
"encoding/base64"
87
"fmt"
98
"image/png"
@@ -13,10 +12,15 @@ import (
1312
"net/url"
1413
"os"
1514
"runtime"
15+
bbmandelbrot "simonwaldherr.de/go/bbmandelbrotGo"
1616
"strconv"
1717
"strings"
1818
)
1919

20+
const (
21+
cachePath = "cache"
22+
)
23+
2024
func dataURI(fileName, contentType string) string {
2125
data, err := ioutil.ReadFile(fileName)
2226
if err != nil {
@@ -66,7 +70,7 @@ func handler(w http.ResponseWriter, r *http.Request) {
6670

6771
for y = 0; y < 4; y++ {
6872
for x = 0; x < 4; x++ {
69-
fname = fmt.Sprintf("cache/%vx%v_%v_%v_%v_%v_mandelbrot.png", width, height, cx1+160*x, cx1+160*(x+1), cy1+160*y, cy1+160*(y+1))
73+
fname = fmt.Sprintf("%s/%vx%v_%v_%v_%v_%v_mandelbrot.png", cachePath, width, height, cx1+160*x, cx1+160*(x+1), cy1+160*y, cy1+160*(y+1))
7074
if _, err := os.Stat(fname); err != nil {
7175
fmt.Println("generating ", fname)
7276
img, _ := bbmandelbrot.Mandelbrot(width, height, cx1+160*x, cx1+160*(x+1), cy1+160*y, cy1+160*(y+1), csr, csg, csb)
@@ -100,6 +104,10 @@ func handler(w http.ResponseWriter, r *http.Request) {
100104
}
101105

102106
func main() {
107+
if _, err := os.Stat(cachePath); os.IsNotExist(err) {
108+
os.Mkdir(cachePath, os.ModePerm)
109+
}
110+
103111
var port string = ":8080"
104112
runtime.GOMAXPROCS(runtime.NumCPU())
105113
http.HandleFunc("/", handler)

0 commit comments

Comments
 (0)