3D 等距投影的着色

2022-11-23 19:59:48
1. 将其转为 Web 服务器并将 SVG 呈现为网页

2. 为 SVG 着色，使峰为红色，谷为蓝色

package main

import (

"fmt"

"math"

"net/http"

"strconv"

)

const (

cells   = 100         // number of grid cells

xyrange = 30.0        // axis ranges (-xyrange..+xyrange)

angle   = math.Pi / 6 // angle of x, y axes (=30°)

)

var height, width = 300, 600 // canvas size in pixels

var xyscale = width / 2 / xyrange  // pixels per x or y unit

var zscale = float64(height) * 0.4 // pixels per z unit

var sin30, cos30 = math.Sin(angle), math.Cos(angle) // sin(30°), cos(30°)

func main() {

//http server

http.HandleFunc("/", handle)

}

func handle(w http.ResponseWriter, r *http.Request) {

if err := r.ParseForm(); err != nil {

return

}

for k, v := range r.Form {

if k == "height" {

h, _ := strconv.Atoi(v[0])

if h > 0 {

height = h

}

}

if k == "width" {

w, _ := strconv.Atoi(v[0])

if w > 0 {

width = w

}

}

}

fmt.Fprintf(w, "</svg>")

}

1 回答

TA贡献1651条经验 获得超7个赞

```fmt.Fprintf(w, "<polygon points='%g,%g %g,%g %g,%g %g,%g' fill='#%x%x%x'/>\n",
ax, ay, bx, by, cx, cy, dx, dy, r, g, b)```

• 1 回答
• 0 关注
• 8 浏览

0/150