問(wèn)題是,基于以下程序 https://github.com/adonovan/gopl.io/blob/master/ch3/surface/main.go將其轉(zhuǎn)為 Web 服務(wù)器并將 SVG 呈現(xiàn)為網(wǎng)頁(yè)為 SVG 著色,使峰為紅色,谷為藍(lán)色我肯定第一部分是對(duì)的,我想我第二部分是對(duì)的,但顯然不是,但我不知道我哪里錯(cuò)了。請(qǐng)幫忙。package mainimport ( "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 pixelsvar xyscale = width / 2 / xyrange // pixels per x or y unitvar zscale = float64(height) * 0.4 // pixels per z unitvar sin30, cos30 = math.Sin(angle), math.Cos(angle) // sin(30°), cos(30°)func main() { addr := ":8000" fmt.Printf("Visit\n http://localhost%s/\n http://localhost%[1]s/?height=600&width=1200\n", addr) //http server http.HandleFunc("/", handle) http.ListenAndServe(addr, nil)}func handle(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "image/svg+xml") 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>")}這是我得到的結(jié)果:注意,雖然這個(gè)問(wèn)題似乎是針對(duì) Go 的,但它實(shí)際上是 getColor()我要問(wèn)的算法。即使您不使用 Go 編寫,您也可以理解/回答。
3D 等距投影的著色
BIG陽(yáng)
2022-11-23 19:59:48