initial commit
This commit is contained in:
commit
d45c2a1f38
|
@ -0,0 +1,2 @@
|
|||
.stack-work/
|
||||
*~
|
|
@ -0,0 +1,4 @@
|
|||
# Changelog for life
|
||||
|
||||
## 12/01/2021
|
||||
First commit
|
|
@ -0,0 +1,30 @@
|
|||
Copyright Author name here (c) 2021
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following
|
||||
disclaimer in the documentation and/or other materials provided
|
||||
with the distribution.
|
||||
|
||||
* Neither the name of Author name here nor the names of other
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@ -0,0 +1,31 @@
|
|||
# What doth life?
|
||||
### Install
|
||||
|
||||
`git clone` this repository and run `stack install`
|
||||
You probably need libfreeglut installed
|
||||
|
||||
### Keybindings:
|
||||
|
||||
```
|
||||
Click a cell to toggle it
|
||||
SPACEBAR: Stop - Start simulation
|
||||
|
||||
f: forward 1 generation
|
||||
|
||||
x: speed up
|
||||
z: slow down
|
||||
|
||||
s: zoom out
|
||||
a: zoom in
|
||||
|
||||
arrows: move around
|
||||
|
||||
r: clear all cells
|
||||
q: quit program
|
||||
```
|
||||
|
||||
TODO:
|
||||
|
||||
- Hashlife
|
||||
- HUD
|
||||
- load and save files
|
|
@ -0,0 +1,30 @@
|
|||
module Main where
|
||||
|
||||
import Graphics.UI.GLUT
|
||||
import Data.IORef
|
||||
import Bindings
|
||||
import Engine
|
||||
|
||||
timeStep :: Int
|
||||
timeStep = 1000
|
||||
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
(_progName, _args) <- getArgsAndInitialize
|
||||
initialDisplayMode $= [DoubleBuffered]
|
||||
_window <- createWindow "Conway's game of life"
|
||||
|
||||
|
||||
pos <- newIORef (0, 0)
|
||||
time <- newIORef timeStep
|
||||
stop <- newIORef True
|
||||
cells <- newIORef startingmem
|
||||
zoom <- newIORef 1
|
||||
|
||||
reshapeCallback $= Just reshape
|
||||
keyboardMouseCallback $= Just (keyboardMouse cells zoom pos time stop)
|
||||
idleCallback $= Nothing
|
||||
displayCallback $= display zoom cells pos
|
||||
addTimerCallback timeStep (looper cells time stop )
|
||||
mainLoop
|
|
@ -0,0 +1,50 @@
|
|||
{-# LANGUAGE CPP #-}
|
||||
{-# LANGUAGE NoRebindableSyntax #-}
|
||||
{-# OPTIONS_GHC -fno-warn-missing-import-lists #-}
|
||||
module Paths_life (
|
||||
version,
|
||||
getBinDir, getLibDir, getDynLibDir, getDataDir, getLibexecDir,
|
||||
getDataFileName, getSysconfDir
|
||||
) where
|
||||
|
||||
import qualified Control.Exception as Exception
|
||||
import Data.Version (Version(..))
|
||||
import System.Environment (getEnv)
|
||||
import Prelude
|
||||
|
||||
#if defined(VERSION_base)
|
||||
|
||||
#if MIN_VERSION_base(4,0,0)
|
||||
catchIO :: IO a -> (Exception.IOException -> IO a) -> IO a
|
||||
#else
|
||||
catchIO :: IO a -> (Exception.Exception -> IO a) -> IO a
|
||||
#endif
|
||||
|
||||
#else
|
||||
catchIO :: IO a -> (Exception.IOException -> IO a) -> IO a
|
||||
#endif
|
||||
catchIO = Exception.catch
|
||||
|
||||
version :: Version
|
||||
version = Version [0,1,0,0] []
|
||||
bindir, libdir, dynlibdir, datadir, libexecdir, sysconfdir :: FilePath
|
||||
|
||||
bindir = "/home/raphy/.cabal/bin"
|
||||
libdir = "/home/raphy/.cabal/lib/x86_64-linux-ghc-8.8.4/life-0.1.0.0-inplace"
|
||||
dynlibdir = "/home/raphy/.cabal/lib/x86_64-linux-ghc-8.8.4"
|
||||
datadir = "/home/raphy/.cabal/share/x86_64-linux-ghc-8.8.4/life-0.1.0.0"
|
||||
libexecdir = "/home/raphy/.cabal/libexec/x86_64-linux-ghc-8.8.4/life-0.1.0.0"
|
||||
sysconfdir = "/home/raphy/.cabal/etc"
|
||||
|
||||
getBinDir, getLibDir, getDynLibDir, getDataDir, getLibexecDir, getSysconfDir :: IO FilePath
|
||||
getBinDir = catchIO (getEnv "life_bindir") (\_ -> return bindir)
|
||||
getLibDir = catchIO (getEnv "life_libdir") (\_ -> return libdir)
|
||||
getDynLibDir = catchIO (getEnv "life_dynlibdir") (\_ -> return dynlibdir)
|
||||
getDataDir = catchIO (getEnv "life_datadir") (\_ -> return datadir)
|
||||
getLibexecDir = catchIO (getEnv "life_libexecdir") (\_ -> return libexecdir)
|
||||
getSysconfDir = catchIO (getEnv "life_sysconfdir") (\_ -> return sysconfdir)
|
||||
|
||||
getDataFileName :: FilePath -> IO FilePath
|
||||
getDataFileName name = do
|
||||
dir <- getDataDir
|
||||
return (dir ++ "/" ++ name)
|
|
@ -0,0 +1,154 @@
|
|||
/* DO NOT EDIT: This file is automatically generated by Cabal */
|
||||
|
||||
/* package life-0.1.0.0 */
|
||||
#ifndef VERSION_life
|
||||
#define VERSION_life "0.1.0.0"
|
||||
#endif /* VERSION_life */
|
||||
#ifndef MIN_VERSION_life
|
||||
#define MIN_VERSION_life(major1,major2,minor) (\
|
||||
(major1) < 0 || \
|
||||
(major1) == 0 && (major2) < 1 || \
|
||||
(major1) == 0 && (major2) == 1 && (minor) <= 0)
|
||||
#endif /* MIN_VERSION_life */
|
||||
|
||||
/* package GLUT-2.7.0.15 */
|
||||
#ifndef VERSION_GLUT
|
||||
#define VERSION_GLUT "2.7.0.15"
|
||||
#endif /* VERSION_GLUT */
|
||||
#ifndef MIN_VERSION_GLUT
|
||||
#define MIN_VERSION_GLUT(major1,major2,minor) (\
|
||||
(major1) < 2 || \
|
||||
(major1) == 2 && (major2) < 7 || \
|
||||
(major1) == 2 && (major2) == 7 && (minor) <= 0)
|
||||
#endif /* MIN_VERSION_GLUT */
|
||||
|
||||
/* package OpenGL-3.0.3.0 */
|
||||
#ifndef VERSION_OpenGL
|
||||
#define VERSION_OpenGL "3.0.3.0"
|
||||
#endif /* VERSION_OpenGL */
|
||||
#ifndef MIN_VERSION_OpenGL
|
||||
#define MIN_VERSION_OpenGL(major1,major2,minor) (\
|
||||
(major1) < 3 || \
|
||||
(major1) == 3 && (major2) < 0 || \
|
||||
(major1) == 3 && (major2) == 0 && (minor) <= 3)
|
||||
#endif /* MIN_VERSION_OpenGL */
|
||||
|
||||
/* package base-4.13.0.0 */
|
||||
#ifndef VERSION_base
|
||||
#define VERSION_base "4.13.0.0"
|
||||
#endif /* VERSION_base */
|
||||
#ifndef MIN_VERSION_base
|
||||
#define MIN_VERSION_base(major1,major2,minor) (\
|
||||
(major1) < 4 || \
|
||||
(major1) == 4 && (major2) < 13 || \
|
||||
(major1) == 4 && (major2) == 13 && (minor) <= 0)
|
||||
#endif /* MIN_VERSION_base */
|
||||
|
||||
/* tool gcc-9.3.0 */
|
||||
#ifndef TOOL_VERSION_gcc
|
||||
#define TOOL_VERSION_gcc "9.3.0"
|
||||
#endif /* TOOL_VERSION_gcc */
|
||||
#ifndef MIN_TOOL_VERSION_gcc
|
||||
#define MIN_TOOL_VERSION_gcc(major1,major2,minor) (\
|
||||
(major1) < 9 || \
|
||||
(major1) == 9 && (major2) < 3 || \
|
||||
(major1) == 9 && (major2) == 3 && (minor) <= 0)
|
||||
#endif /* MIN_TOOL_VERSION_gcc */
|
||||
|
||||
/* tool ghc-8.8.4 */
|
||||
#ifndef TOOL_VERSION_ghc
|
||||
#define TOOL_VERSION_ghc "8.8.4"
|
||||
#endif /* TOOL_VERSION_ghc */
|
||||
#ifndef MIN_TOOL_VERSION_ghc
|
||||
#define MIN_TOOL_VERSION_ghc(major1,major2,minor) (\
|
||||
(major1) < 8 || \
|
||||
(major1) == 8 && (major2) < 8 || \
|
||||
(major1) == 8 && (major2) == 8 && (minor) <= 4)
|
||||
#endif /* MIN_TOOL_VERSION_ghc */
|
||||
|
||||
/* tool ghc-pkg-8.8.4 */
|
||||
#ifndef TOOL_VERSION_ghc_pkg
|
||||
#define TOOL_VERSION_ghc_pkg "8.8.4"
|
||||
#endif /* TOOL_VERSION_ghc_pkg */
|
||||
#ifndef MIN_TOOL_VERSION_ghc_pkg
|
||||
#define MIN_TOOL_VERSION_ghc_pkg(major1,major2,minor) (\
|
||||
(major1) < 8 || \
|
||||
(major1) == 8 && (major2) < 8 || \
|
||||
(major1) == 8 && (major2) == 8 && (minor) <= 4)
|
||||
#endif /* MIN_TOOL_VERSION_ghc_pkg */
|
||||
|
||||
/* tool haddock-2.23.0 */
|
||||
#ifndef TOOL_VERSION_haddock
|
||||
#define TOOL_VERSION_haddock "2.23.0"
|
||||
#endif /* TOOL_VERSION_haddock */
|
||||
#ifndef MIN_TOOL_VERSION_haddock
|
||||
#define MIN_TOOL_VERSION_haddock(major1,major2,minor) (\
|
||||
(major1) < 2 || \
|
||||
(major1) == 2 && (major2) < 23 || \
|
||||
(major1) == 2 && (major2) == 23 && (minor) <= 0)
|
||||
#endif /* MIN_TOOL_VERSION_haddock */
|
||||
|
||||
/* tool hpc-0.67 */
|
||||
#ifndef TOOL_VERSION_hpc
|
||||
#define TOOL_VERSION_hpc "0.67"
|
||||
#endif /* TOOL_VERSION_hpc */
|
||||
#ifndef MIN_TOOL_VERSION_hpc
|
||||
#define MIN_TOOL_VERSION_hpc(major1,major2,minor) (\
|
||||
(major1) < 0 || \
|
||||
(major1) == 0 && (major2) < 67 || \
|
||||
(major1) == 0 && (major2) == 67 && (minor) <= 0)
|
||||
#endif /* MIN_TOOL_VERSION_hpc */
|
||||
|
||||
/* tool hsc2hs-0.68.7 */
|
||||
#ifndef TOOL_VERSION_hsc2hs
|
||||
#define TOOL_VERSION_hsc2hs "0.68.7"
|
||||
#endif /* TOOL_VERSION_hsc2hs */
|
||||
#ifndef MIN_TOOL_VERSION_hsc2hs
|
||||
#define MIN_TOOL_VERSION_hsc2hs(major1,major2,minor) (\
|
||||
(major1) < 0 || \
|
||||
(major1) == 0 && (major2) < 68 || \
|
||||
(major1) == 0 && (major2) == 68 && (minor) <= 7)
|
||||
#endif /* MIN_TOOL_VERSION_hsc2hs */
|
||||
|
||||
/* tool pkg-config-0.29.2 */
|
||||
#ifndef TOOL_VERSION_pkg_config
|
||||
#define TOOL_VERSION_pkg_config "0.29.2"
|
||||
#endif /* TOOL_VERSION_pkg_config */
|
||||
#ifndef MIN_TOOL_VERSION_pkg_config
|
||||
#define MIN_TOOL_VERSION_pkg_config(major1,major2,minor) (\
|
||||
(major1) < 0 || \
|
||||
(major1) == 0 && (major2) < 29 || \
|
||||
(major1) == 0 && (major2) == 29 && (minor) <= 2)
|
||||
#endif /* MIN_TOOL_VERSION_pkg_config */
|
||||
|
||||
/* tool runghc-8.8.4 */
|
||||
#ifndef TOOL_VERSION_runghc
|
||||
#define TOOL_VERSION_runghc "8.8.4"
|
||||
#endif /* TOOL_VERSION_runghc */
|
||||
#ifndef MIN_TOOL_VERSION_runghc
|
||||
#define MIN_TOOL_VERSION_runghc(major1,major2,minor) (\
|
||||
(major1) < 8 || \
|
||||
(major1) == 8 && (major2) < 8 || \
|
||||
(major1) == 8 && (major2) == 8 && (minor) <= 4)
|
||||
#endif /* MIN_TOOL_VERSION_runghc */
|
||||
|
||||
/* tool strip-2.35 */
|
||||
#ifndef TOOL_VERSION_strip
|
||||
#define TOOL_VERSION_strip "2.35"
|
||||
#endif /* TOOL_VERSION_strip */
|
||||
#ifndef MIN_TOOL_VERSION_strip
|
||||
#define MIN_TOOL_VERSION_strip(major1,major2,minor) (\
|
||||
(major1) < 2 || \
|
||||
(major1) == 2 && (major2) < 35 || \
|
||||
(major1) == 2 && (major2) == 35 && (minor) <= 0)
|
||||
#endif /* MIN_TOOL_VERSION_strip */
|
||||
|
||||
#ifndef CURRENT_PACKAGE_KEY
|
||||
#define CURRENT_PACKAGE_KEY "life-0.1.0.0-inplace"
|
||||
#endif /* CURRENT_PACKAGE_KEY */
|
||||
#ifndef CURRENT_COMPONENT_ID
|
||||
#define CURRENT_COMPONENT_ID "life-0.1.0.0-inplace"
|
||||
#endif /* CURRENT_COMPONENT_ID */
|
||||
#ifndef CURRENT_PACKAGE_VERSION
|
||||
#define CURRENT_PACKAGE_VERSION "0.1.0.0"
|
||||
#endif /* CURRENT_PACKAGE_VERSION */
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,73 @@
|
|||
cabal-version: 1.12
|
||||
|
||||
-- This file has been generated from package.yaml by hpack version 0.34.2.
|
||||
--
|
||||
-- see: https://github.com/sol/hpack
|
||||
|
||||
name: life
|
||||
version: 0.1.0.0
|
||||
description: Please see the README on GitHub at <https://github.com/githubuser/life#readme>
|
||||
homepage: https://github.com/githubuser/life#readme
|
||||
bug-reports: https://github.com/githubuser/life/issues
|
||||
author: Author name here
|
||||
maintainer: example@example.com
|
||||
copyright: 2021 Author name here
|
||||
license: BSD3
|
||||
license-file: LICENSE
|
||||
build-type: Simple
|
||||
extra-source-files:
|
||||
README.md
|
||||
ChangeLog.md
|
||||
|
||||
source-repository head
|
||||
type: git
|
||||
location: https://github.com/githubuser/life
|
||||
|
||||
library
|
||||
exposed-modules:
|
||||
Bindings
|
||||
Cells
|
||||
Cube
|
||||
Display
|
||||
Engine
|
||||
other-modules:
|
||||
Paths_life
|
||||
hs-source-dirs:
|
||||
src
|
||||
build-depends:
|
||||
GLUT >=2.7.0.15
|
||||
, OpenGL >=3.0.3.0
|
||||
, base >=4.7 && <5
|
||||
, containers >=0.6.2.1
|
||||
default-language: Haskell2010
|
||||
|
||||
executable life-exe
|
||||
main-is: Main.hs
|
||||
other-modules:
|
||||
Paths_life
|
||||
hs-source-dirs:
|
||||
app
|
||||
ghc-options: -threaded -rtsopts -with-rtsopts=-N
|
||||
build-depends:
|
||||
GLUT >=2.7.0.15
|
||||
, OpenGL >=3.0.3.0
|
||||
, base >=4.7 && <5
|
||||
, containers >=0.6.2.1
|
||||
, life
|
||||
default-language: Haskell2010
|
||||
|
||||
test-suite life-test
|
||||
type: exitcode-stdio-1.0
|
||||
main-is: Spec.hs
|
||||
other-modules:
|
||||
Paths_life
|
||||
hs-source-dirs:
|
||||
test
|
||||
ghc-options: -threaded -rtsopts -with-rtsopts=-N
|
||||
build-depends:
|
||||
GLUT >=2.7.0.15
|
||||
, OpenGL >=3.0.3.0
|
||||
, base >=4.7 && <5
|
||||
, containers >=0.6.2.1
|
||||
, life
|
||||
default-language: Haskell2010
|
|
@ -0,0 +1,50 @@
|
|||
name: life
|
||||
version: 0.1.0.0
|
||||
license: BSD3
|
||||
author: "Raphael Jacobs"
|
||||
maintainer: "Raphy@airmail.cc"
|
||||
copyright: "2021 Raphyjake"
|
||||
|
||||
extra-source-files:
|
||||
- README.md
|
||||
- ChangeLog.md
|
||||
|
||||
# Metadata used when publishing your package
|
||||
# synopsis: Short description of your package
|
||||
# category: Web
|
||||
|
||||
# To avoid duplicated efforts in documentation and dealing with the
|
||||
# complications of embedding Haddock markup inside cabal files, it is
|
||||
# common to point users to the README.md file.
|
||||
description: Please see the README on GitHub at <https://github.com/githubuser/life#readme>
|
||||
|
||||
dependencies:
|
||||
- base >= 4.7 && < 5
|
||||
- OpenGL >= 3.0.3.0
|
||||
- GLUT >= 2.7.0.15
|
||||
- containers >= 0.6.2.1
|
||||
|
||||
library:
|
||||
source-dirs: src
|
||||
|
||||
executables:
|
||||
life-exe:
|
||||
main: Main.hs
|
||||
source-dirs: app
|
||||
ghc-options:
|
||||
- -threaded
|
||||
- -rtsopts
|
||||
- -with-rtsopts=-N
|
||||
dependencies:
|
||||
- life
|
||||
|
||||
tests:
|
||||
life-test:
|
||||
main: Spec.hs
|
||||
source-dirs: test
|
||||
ghc-options:
|
||||
- -threaded
|
||||
- -rtsopts
|
||||
- -with-rtsopts=-N
|
||||
dependencies:
|
||||
- life
|
|
@ -0,0 +1,79 @@
|
|||
module Bindings (display, reshape, keyboardMouse, looper) where
|
||||
|
||||
import Graphics.UI.GLUT
|
||||
import Data.IORef
|
||||
import Display
|
||||
import Engine
|
||||
import System.Exit
|
||||
|
||||
reshape :: ReshapeCallback
|
||||
reshape s = do
|
||||
clear [ColorBuffer]
|
||||
postRedisplay Nothing
|
||||
|
||||
|
||||
keyboardMouse ::
|
||||
IORef Cells ->
|
||||
IORef GLfloat ->
|
||||
IORef (GLfloat, GLfloat) ->
|
||||
IORef Int ->
|
||||
IORef Bool ->
|
||||
KeyboardMouseCallback
|
||||
keyboardMouse cells z p t s key Down _ position@(Position x y) = do
|
||||
case key of
|
||||
|
||||
(SpecialKey KeyF11) -> fullScreenToggle
|
||||
|
||||
(Char 'q') -> do exit; exitSuccess
|
||||
(Char 'r') -> cells $~! const emptymem
|
||||
|
||||
(Char 'z') -> t $~! \x -> x+50
|
||||
(Char 'x') -> t $~! \x -> if x > 50 then x-50 else 50
|
||||
|
||||
(Char 'a') -> do
|
||||
k <- get z
|
||||
if k > 1 then pure() else
|
||||
z $~! const (k * 1.5) >>
|
||||
p $~! \(x,y) -> (x*1.5, y*1.5)
|
||||
|
||||
(Char 's') -> (z $~! \x -> x/1.5) >>
|
||||
p $~! \(x,y) -> (x/1.5, y/1.5)
|
||||
|
||||
(SpecialKey KeyLeft ) -> p $~! \(x,y) -> (x+0.1,y)
|
||||
(SpecialKey KeyRight) -> p $~! \(x,y) -> (x-0.1,y)
|
||||
(SpecialKey KeyUp ) -> p $~! \(x,y) -> (x,y-0.1)
|
||||
(SpecialKey KeyDown ) -> p $~! \(x,y) -> (x,y+0.1)
|
||||
|
||||
|
||||
(MouseButton LeftButton) -> do
|
||||
|
||||
Size w' h' <- get windowSize
|
||||
zoom <- get z
|
||||
c <- get cells
|
||||
(posx, posy) <- get p
|
||||
let w = fromIntegral w'
|
||||
let h = fromIntegral h'
|
||||
let k = zoom*fromIntegral h' / 20
|
||||
|
||||
let (p, q) = (floor $ (fromIntegral (x - w `div` 2) + k/2) / k - posx*10/zoom,
|
||||
floor $ -(fromIntegral (y - h `div` 2) - k/2) / k - posy*10/zoom)
|
||||
|
||||
cells $~! const (toggle c (fromIntegral p, fromIntegral q))
|
||||
|
||||
(Char ' ') -> s $~! not
|
||||
_ -> return ()
|
||||
|
||||
postRedisplay Nothing
|
||||
keyboardMouse _ _ _ _ _ _ _ _ _ = return ()
|
||||
|
||||
negfloor x = if x > 0 then floor x else ceiling x
|
||||
|
||||
looper :: IORef Cells -> IORef Int -> IORef Bool -> TimerCallback
|
||||
looper cells n s = do
|
||||
time <- get n
|
||||
stop <- get s
|
||||
old <- get cells
|
||||
if stop then pure () else do
|
||||
cells $~! const (updatem old)
|
||||
postRedisplay Nothing
|
||||
addTimerCallback time (looper cells n s)
|
|
@ -0,0 +1,20 @@
|
|||
module Cells (Cells, updatem, rendercells) where
|
||||
|
||||
import Graphics.UI.GLUT
|
||||
import Engine
|
||||
import qualified Data.Set as S
|
||||
|
||||
vertex3f :: (GLfloat, GLfloat, GLfloat) -> IO ()
|
||||
vertex3f (x, y, z) = vertex $ Vertex3 x y z
|
||||
|
||||
--cell :: GLfloat -> IO ()
|
||||
cell w (x, y) = renderPrimitive Quads $ mapM_ vertex3f
|
||||
[ ( x' +w, y' +w, 0),
|
||||
( x' +w, y' -w, 0),
|
||||
( x' -w, y' -w, 0),
|
||||
( x' -w, y' +w, 0)]
|
||||
where x' = fromIntegral x/10
|
||||
y' = fromIntegral y/10
|
||||
|
||||
rendercells :: Cells -> IO ()
|
||||
rendercells cells = mapM_ (cell 0.05) (S.toList cells)
|
|
@ -0,0 +1,25 @@
|
|||
module Cube where
|
||||
|
||||
import Graphics.UI.GLUT
|
||||
|
||||
vertex3f :: (GLfloat, GLfloat, GLfloat) -> IO ()
|
||||
vertex3f (x, y, z) = vertex $ Vertex3 x y z
|
||||
|
||||
|
||||
cube :: GLfloat -> IO ()
|
||||
cube w = renderPrimitive Quads $ mapM_ vertex3f
|
||||
[( w, w, w), ( w,-w, w), (-w,-w, w), (-w, w, w),
|
||||
( w, w,-w), ( w,-w,-w), (-w,-w,-w), (-w, w,-w),
|
||||
( w, w, w), ( w,-w, w), ( w,-w,-w), ( w, w,-w),
|
||||
(-w, w, w), (-w,-w, w), (-w,-w,-w), (-w, w,-w),
|
||||
( w, w, w), (-w, w, w), (-w, w,-w), ( w, w,-w),
|
||||
( w,-w, w), (-w,-w, w), (-w,-w,-w), ( w,-w,-w)]
|
||||
|
||||
|
||||
cubeFrame w = renderPrimitive Lines $ mapM_ vertex3f
|
||||
[( w, w, w), ( w,-w, w), ( w,-w, w), (-w,-w, w),
|
||||
(-w,-w, w), (-w, w, w), (-w, w, w), ( w, w, w),
|
||||
( w, w,-w), ( w,-w,-w), ( w,-w,-w), (-w,-w,-w),
|
||||
(-w,-w,-w), (-w, w,-w), (-w, w,-w), ( w, w,-w),
|
||||
( w, w, w), ( w, w,-w), ( w,-w, w), ( w,-w,-w),
|
||||
(-w,-w, w), (-w,-w,-w), (-w, w, w), (-w, w,-w)]
|
|
@ -0,0 +1,44 @@
|
|||
{-# LANGUAGE BlockArguments #-}
|
||||
module Display where
|
||||
|
||||
import Graphics.UI.GLUT
|
||||
import Control.Monad
|
||||
import Data.IORef
|
||||
import Cube
|
||||
import Cells
|
||||
|
||||
|
||||
display ::
|
||||
IORef GLfloat ->
|
||||
IORef Cells ->
|
||||
IORef (GLfloat, GLfloat) ->
|
||||
DisplayCallback
|
||||
|
||||
display z cells pos = do
|
||||
clear [ColorBuffer]
|
||||
(x',y') <- get pos
|
||||
old <- get cells
|
||||
zoom <- get z
|
||||
size <- get windowSize
|
||||
|
||||
viewport $= (Position 0 0, size)
|
||||
let Size w' h' = size
|
||||
let w = fromIntegral w'
|
||||
let h = fromIntegral h'
|
||||
|
||||
|
||||
matrixMode $= Projection
|
||||
loadIdentity
|
||||
let ar = w/h
|
||||
ortho2D (-1*ar) (1*ar) (-1) 1
|
||||
matrixMode $= Modelview 0
|
||||
loadIdentity
|
||||
clear [ColorBuffer]
|
||||
|
||||
translate $ Vector3 x' y' 0
|
||||
scale zoom zoom zoom
|
||||
|
||||
color $ Color3 1 1 (1 :: Float)
|
||||
rendercells old
|
||||
swapBuffers
|
||||
print "render"
|
|
@ -0,0 +1,32 @@
|
|||
module Engine (startingmem, Cells, updatem, toggle, emptymem) where
|
||||
|
||||
-- Naive Method
|
||||
import qualified Data.Set as S
|
||||
|
||||
type Cells = S.Set (Int, Int)
|
||||
|
||||
emptymem :: S.Set (Int, Int)
|
||||
emptymem = S.empty
|
||||
|
||||
startingmem :: S.Set (Int, Int)
|
||||
startingmem = S.fromList []
|
||||
|
||||
neighbors :: (Num a, Num b, Enum a, Enum b, Eq a, Eq b) => (a, b) -> [(a, b)]
|
||||
neighbors (x, y) = [(x+k1, y+k2) |
|
||||
k1 <- [-1..1],
|
||||
k2 <-[-1..1],
|
||||
not $ k1 == 0 && k2 == 0]
|
||||
|
||||
check :: (Ord a, Ord b, Num a, Num b, Enum a, Enum b) => S.Set (a, b) -> (a, b) -> Int
|
||||
check mem (x, y) = length . filter id . fmap (`S.member` mem) $ neighbors (x, y)
|
||||
|
||||
toggle :: (Ord a, Ord b) => S.Set (a, b) -> (a, b) -> S.Set (a, b)
|
||||
toggle mem (x, y) = if S.member (x, y) mem then S.delete (x, y) mem else S.insert (x, y) mem
|
||||
|
||||
updatem :: (Ord a, Ord b, Num a, Num b, Enum a, Enum b) => S.Set (a, b) -> S.Set (a, b)
|
||||
updatem active = S.union toKeep toAdd where
|
||||
frontier = S.unions . S.map (\x -> S.difference (S.fromList (neighbors x)) active) $ active
|
||||
toKeep = S.filter live active
|
||||
toAdd = S.filter born frontier
|
||||
live x = 2 == check active x || 3 == check active x
|
||||
born x = 3 == check active x
|
|
@ -0,0 +1,67 @@
|
|||
# This file was automatically generated by 'stack init'
|
||||
#
|
||||
# Some commonly used options have been documented as comments in this file.
|
||||
# For advanced use and comprehensive documentation of the format, please see:
|
||||
# https://docs.haskellstack.org/en/stable/yaml_configuration/
|
||||
|
||||
# Resolver to choose a 'specific' stackage snapshot or a compiler version.
|
||||
# A snapshot resolver dictates the compiler version and the set of packages
|
||||
# to be used for project dependencies. For example:
|
||||
#
|
||||
# resolver: lts-3.5
|
||||
# resolver: nightly-2015-09-21
|
||||
# resolver: ghc-7.10.2
|
||||
#
|
||||
# The location of a snapshot can be provided as a file or url. Stack assumes
|
||||
# a snapshot provided as a file might change, whereas a url resource does not.
|
||||
#
|
||||
# resolver: ./custom-snapshot.yaml
|
||||
# resolver: https://example.com/snapshots/2018-01-01.yaml
|
||||
resolver:
|
||||
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/16/28.yaml
|
||||
|
||||
# User packages to be built.
|
||||
# Various formats can be used as shown in the example below.
|
||||
#
|
||||
# packages:
|
||||
# - some-directory
|
||||
# - https://example.com/foo/bar/baz-0.0.2.tar.gz
|
||||
# subdirs:
|
||||
# - auto-update
|
||||
# - wai
|
||||
packages:
|
||||
- .
|
||||
# Dependency packages to be pulled from upstream that are not in the resolver.
|
||||
# These entries can reference officially published versions as well as
|
||||
# forks / in-progress versions pinned to a git hash. For example:
|
||||
#
|
||||
# extra-deps:
|
||||
# - acme-missiles-0.3
|
||||
# - git: https://github.com/commercialhaskell/stack.git
|
||||
# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
|
||||
#
|
||||
# extra-deps: []
|
||||
|
||||
# Override default flag values for local packages and extra-deps
|
||||
# flags: {}
|
||||
|
||||
# Extra package databases containing global packages
|
||||
# extra-package-dbs: []
|
||||
|
||||
# Control whether we use the GHC we find on the path
|
||||
# system-ghc: true
|
||||
#
|
||||
# Require a specific version of stack, using version ranges
|
||||
# require-stack-version: -any # Default
|
||||
# require-stack-version: ">=2.5"
|
||||
#
|
||||
# Override the architecture used by stack, especially useful on Windows
|
||||
# arch: i386
|
||||
# arch: x86_64
|
||||
#
|
||||
# Extra directories used by stack for building
|
||||
# extra-include-dirs: [/path/to/dir]
|
||||
# extra-lib-dirs: [/path/to/dir]
|
||||
#
|
||||
# Allow a newer minor version of GHC than the snapshot specifies
|
||||
# compiler-check: newer-minor
|
|
@ -0,0 +1,13 @@
|
|||
# This file was autogenerated by Stack.
|
||||
# You should not edit this file by hand.
|
||||
# For more information, please see the documentation at:
|
||||
# https://docs.haskellstack.org/en/stable/lock_files
|
||||
|
||||
packages: []
|
||||
snapshots:
|
||||
- completed:
|
||||
size: 533053
|
||||
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/16/28.yaml
|
||||
sha256: a9c01d860ac8dfb3a1b6f7ec4a36dd9504a95392b89c99b0877da63fa36a8e97
|
||||
original:
|
||||
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/16/28.yaml
|
|
@ -0,0 +1,2 @@
|
|||
main :: IO ()
|
||||
main = putStrLn "Test suite not yet implemented"
|
Loading…
Reference in New Issue