-
Notifications
You must be signed in to change notification settings - Fork 0
/
colorful_cube
62 lines (51 loc) · 1.82 KB
/
colorful_cube
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import Graphics.Rendering.OpenGL
import Graphics.UI.GLUT
import Data.IORef
display = do
let --color3f r g b = color $ Color4 r g (b :: GLfloat) 1.0
--vertex3f x y z = vertex $ Vertex3 x y (z :: GLfloat)
w = (0.08::GLfloat)
(x, y, z, w_w, r, d, c, (c_r,c_g,c_b)) = (0,0,0,0,0,0,0,(0.2,0.1,0.4))
--clear [ColorBuffer]
rotate 45 $ Vector3 0 (1::GLfloat) 0
renderPrimitive Quads $ do
color $ Color4 (0.5::GLfloat) 0.5 0.5 1.0
vertex $ Vertex3 w w (w/10)
vertex $ Vertex3 w w (-w/10)
vertex $ Vertex3 w (-w) (-w/10)
vertex $ Vertex3 w (-w) (w/10)
vertex $ Vertex3 w w (w/10)
vertex $ Vertex3 w w (-w/10)
vertex $ Vertex3 (-w) w (-w/10)
vertex $ Vertex3 (-w) w (w/10)
color $ Color4 ((1-(x+1)/4)::GLfloat) (1-(y+1)/4) (1-(z+1)/4) 1.0
vertex $ Vertex3 w w (w/10)
vertex $ Vertex3 w (-w) (w/10)
vertex $ Vertex3 (-w) (-w) (w/10)
vertex $ Vertex3 (-w) w (w/10)
color $ Color4 (0.5::GLfloat) 0.5 0.5 1
vertex $ Vertex3 (-w) w (w/10)
vertex $ Vertex3 (-w) w (-w/10)
vertex $ Vertex3 (-w) (-w) (-w/10)
vertex $ Vertex3 (-w) (-w) (w/10)
vertex $ Vertex3 w (-w) (w/10)
vertex $ Vertex3 w (-w) (-w/10)
vertex $ Vertex3 (-w) (-w) (-w/10)
vertex $ Vertex3 (-w) (-w) (w/10)
color $ Color4 (c_r::GLfloat) c_g c_b 1
vertex $ Vertex3 w w (-w/10)
vertex $ Vertex3 w (-w) (-w/10)
vertex $ Vertex3 (-w) (-w) (-w/10)
vertex $ Vertex3 (-w) w (-w/10)
flush
main :: IO ()
main = do
(_progName, _args) <- getArgsAndInitialize
_window <- createWindow "Hello World"
displayCallback $= display
reshapeCallback $= Just reshape
mainLoop
reshape :: ReshapeCallback
reshape size = do
viewport $= (Position 0 0, size)
postRedisplay Nothing