-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
37 lines (30 loc) · 787 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package main
import (
"code/lsystem-v6/ls"
"code/lsystem-v6/turtlego"
"fmt"
"log"
"net/http"
"strconv"
)
func main() {
l := ls.NewLsystem("F", "F", "FF+[+F-F-F]-[-F+F+F]", []string{})
http.Handle("/", l)
http.Handle("/create", create())
http.Handle("/public/", http.StripPrefix("/public", http.FileServer(http.Dir("public"))))
log.Fatal(http.ListenAndServe(":8080", nil))
}
func create() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
l := ls.NewLsystem("F", "F", "FF+[+F-F-F]-[-F+F+F]", []string{})
err := req.ParseForm()
if err != nil {
panic(err)
}
n := req.Form.Get("n")
i, err := strconv.Atoi(n)
l.Generate(i)
turtlego.ToPNG(l, fmt.Sprintf("./public/pic/l-system%d.png", i))
l.ServeHTTP(w, req)
})
}