ポリゴンを表示するプログラム
Posted feedbacks - Haskell
昔どこかのページを参考に作った奴です。
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 | module Main where
import System
import Graphics.UI.GLUT
import System.Random
display n = do
clear [ ColorBuffer ]
color $ Color3 (0.6::Double) 0.6 0.6
preservingMatrix $ do
renderPrimitive Polygon $ mapM_ vertex (nlist n)
flush
where
nlist n = nVertex n du
du = 2.0 * pi / fromIntegral n
nVertex n du
| n == 0 = [ point ]
| otherwise = point : nVertex (n-1) du
where
radius = 0.75
x = toRational (radius * cos (pi / 2.0 + fromIntegral n * du))
y = toRational (radius * sin (pi / 2.0 + fromIntegral n * du))
point = Vertex3 (fromRational x) (fromRational y) (0.0 :: GLfloat)
timer n = do
rotate (1::Double) (Vector3 0 1 0)
display n
finish
addTimerCallback 10 (timer n)
inputKey (Char 'q') _ _ _ = exitWith ExitSuccess
inputKey _ _ _ _ = return ()
main = do
(fileName, args) <- getArgsAndInitialize
let n = case args of
[] -> 3
_ -> max 3 $ read $ head args
createWindow "Haskell OpenGL"
displayCallback $= display n
addTimerCallback 1000 (timer n)
keyboardMouseCallback $= Just (inputKey)
mainLoop
|

ところてん
#5940()
Rating0/4=0.00
[ reply ]