Home > Back-end >  Coloring for 3D Isometric projection
Coloring for 3D Isometric projection

Time:03-26

The ask is, base on the following program enter image description here

NB, although the question seems to be for Go, but it is actually the getColor() algorithm that I'm asking about. You can understand/answer even if you don't write in Go.

CodePudding user response:

Your code uses the format verb %x to print the hex values to the SVG's fill attribute:

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)

This causes some numbers like 0 and 1 to be formatted with one hex digit. For example RGB (254, 0, 1) would be formatted as fe01. The browser then render colors incorrectly.

Change the format verbs to x to ensure the RGB is always printed with two hex digits.

Now RGB (254, 0, 1) is printed as fe0001, which is the correct hex color.

Output:

enter image description here

  • Related