module Display (display,idle, Inst(..), CubeState(..), goalState, randomMoves) where import Graphics.UI.GLUT hiding (index, R) import Data.IORef import Control.Monad import RubikCube import GI import Sprites display state = do clear [ ColorBuffer ] loadIdentity -- clear the matrix lookAt (Vertex3 6 5 8) (Vertex3 0 0 0) (Vector3 0 1 0) c <- readIORef $ cube state cubeAction state swapBuffers flush idle = do postRedisplay Nothing cubeAction:: CubeState -> IO () cubeAction state = do rCube <- readIORef $ cube state let ins = inst state i <- readIORef ins print i when (head i == NO) $ do c <- readIORef $ cube state paintCube c when ( elem (head i) [TF,TF',TU,TU',TR,TR',R, R',MF,MF',L,L',F,F',MR,MR',B,B',U,U',MU,MU',D,D'] ) $ do let ro = rot state r <- readIORef ro if r < 90 then do animation (head i) state r writeIORef (rot state) (r+0.8) else do let lista = insts state l <- readIORef lista animation (head i) state 90 nextMove (head i) state if(null (tail i)) then writeIORef ins ([NO]) else writeIORef ins ((tail i)) writeIORef lista (inverseMove (head i):l) writeIORef ro 0.0 animation:: Inst -> CubeState -> GLfloat -> IO () animation F state r = do c <- readIORef $ cube state paintRow2 c paintRow1 c animate c paintRow0 (negate r) (Vector3 0 0 1) animation F' state r = do c <- readIORef $ cube state paintRow2 c paintRow1 c animate c paintRow0 r (Vector3 0 0 1) animation MR state r = do c <- readIORef $ cube state paintRow2 c paintRow1 c animate c paintRow0 (negate r) (Vector3 0 0 1) animation MR' state r = do c <- readIORef $ cube state paintRow2 c paintRow1 c animate c paintRow0 (negate r) (Vector3 0 0 1) animation B state r = do c <- readIORef $ cube state animate c paintRow2 r (Vector3 0 0 1) paintRow1 c paintRow0 c animation B' state r = do c <- readIORef $ cube state animate c paintRow2 (negate r) (Vector3 0 0 1) paintRow1 c paintRow0 c animation L' state r = do c <- readIORef $ cube state animate c paintColum2 (negate r) (Vector3 1 0 0) paintColum1 c paintColum0 c animation L state r = do c <- readIORef $ cube state animate c paintColum2 r (Vector3 1 0 0) paintColum1 c paintColum0 c animation MF' state r = do c <- readIORef $ cube state paintColum2 c animate c paintColum1 (negate r) (Vector3 0 0 1) paintColum0 c animation MF state r = do c <- readIORef $ cube state paintColum2 c animate c paintColum1 (negate r) (Vector3 0 0 1) paintColum0 c animation R' state r = do c <- readIORef $ cube state paintColum2 c paintColum1 c animate c paintColum0 r (Vector3 1 0 0) animation R state r = do c <- readIORef $ cube state paintColum2 c paintColum1 c animate c paintColum0 (negate r) (Vector3 1 0 0) animation U state r = do c <- readIORef $ cube state paintLayer2 c paintLayer1 c animate c paintLayer0 (negate r) (Vector3 0 1 0) animation U' state r = do c <- readIORef $ cube state paintLayer2 c paintLayer1 c animate c paintLayer0 r (Vector3 0 1 0) animation MU state r = do c <- readIORef $ cube state paintLayer2 c animate c paintLayer1 r (Vector3 0 1 0) paintLayer0 c animation MU' state r = do c <- readIORef $ cube state paintLayer2 c animate c paintLayer1 r (Vector3 0 1 0) paintLayer0 c animation D state r = do c <- readIORef $ cube state animate c paintLayer2 r (Vector3 0 1 0) paintLayer1 c paintLayer0 c animation D' state r = do c <- readIORef $ cube state animate c paintLayer2 (negate r) (Vector3 0 1 0) paintLayer1 c paintLayer0 c animation TF state r = do c <- readIORef $ cube state animate c paintCube (negate r) (Vector3 0 0 1) animation TF' state r = do c <- readIORef $ cube state animate c paintCube r (Vector3 0 0 1) animation TU state r = do c <- readIORef $ cube state animate c paintCube (negate r) (Vector3 0 1 0) animation TU' state r = do c <- readIORef $ cube state animate c paintCube r (Vector3 0 1 0) animation TR state r = do c <- readIORef $ cube state animate c paintCube (negate r) (Vector3 1 0 0) animation TR' state r = do c <- readIORef $ cube state animate c paintCube r (Vector3 1 0 0) animation _ _ _ = return () animate c f r' vec = preservingMatrix $ do rotate r' vec f c