Studio/OpenGL/ColorCube
Jump to navigation
Jump to search
The vertices are colored according to their position (-1,1 corresponds to RGB 0,255), and the faces filled in. Note that exactly the same technique can be used to color any solid, though typically extreme positions such as 1 0 0 (i.e. RGB 255 0 0) will not be found.
The J code to produce the graphic follows. vtx is a list of the solid's faces. colorit steps through each face, applying the glVertex and glcolor verbs, to define it as a vertex and as a color.
NB. colored solid NB. NB. the vertices are colored according to NB. their position, and the faces filled in. SOLID=: gscube'' NB. try gsdodecahedron'' GS_ROTXYZ=: 45 60 0 GS_CLEARCOLOR=: 0.1 0 0.2 1 paint=: 3 : 0 gsinit'' face=. 2 pick SOLID vtx=. 1.5*_3 [\"1 face clr=. gsfit01 vtx vtx make_colored"2 clr gsfini'' ) colorit=: (glVertex@[ gscolor)"1 make_colored=: 4 : 0 glBegin GL_POLYGON x colorit y glEnd '' )
The same code with cube replaced by icosahedron gives: