changes in changelog

This commit is contained in:
Raphy 2021-11-30 05:08:32 +01:00
parent de13fff167
commit 910967b289
7 changed files with 84 additions and 105 deletions

View File

@ -1,5 +1,10 @@
# Changelog for life
## 30/11/2021 v0.1.2.1
Removed useless file
Added vim-like keybindings
Updated ghc version
## 12/01/2021 v0.1.2.0
Updated main naive algorithm
Added functionality to read .cells file

View File

@ -2,7 +2,7 @@
### Install
`git clone` this repository and run `stack install`
You probably need libfreeglut installed.
You probably need libfreeglut-dev or devel to build this, and libfreeglut installed to run it.
Then, run `life`
You can load .cells files using `life my_file.cells`
@ -22,14 +22,19 @@ s: zoom out
a: zoom in
arrows: move around
h,j,k,l: move around
r: clear all cells
q: quit program
```
TODO:
### Links:
<https://www.youtube.com/watch?v=Sq2egQOygV8>
### TODO:
- Hashlife
- HUD
- save files
- support for .rle
- support for .rle

View File

@ -1,5 +1,5 @@
name: life
version: 0.1.2.0
version: 0.1.2.1
license: BSD3
author: "Raphael Jacobs"
maintainer: "Raphy@airmail.cc"

View File

@ -1,10 +1,9 @@
module Bindings (display, reshape, keyboardMouse, looper) where
import Graphics.UI.GLUT
import Data.IORef
import Display
import Engine
import Graphics.UI.GLUT
import System.Exit
-- Just re-render
@ -13,69 +12,68 @@ 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 'f') -> get s >>= \x -> if x then cells $~! updatem else pure ()
(Char ' ') -> s $~! not -- Forward one step
(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)
(Char 'h') -> p $~! \(x, y) -> (x + 0.1, y)
(Char 'l') -> p $~! \(x, y) -> (x -0.1, y)
(Char 'j') -> p $~! \(x, y) -> (x, y -0.1)
(Char 'k') -> 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
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
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
)
(SpecialKey KeyF11) -> fullScreenToggle
cells $~! const (toggle c (fromIntegral p, fromIntegral q))
_ -> return ()
(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 'f') -> get s >>= \x -> if x then cells $~! updatem else pure ()
(Char ' ') -> s $~! not -- Forward one step
(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))
_ -> return ()
postRedisplay Nothing
postRedisplay Nothing
keyboardMouse _ _ _ _ _ _ _ _ _ = return ()
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)
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)

View File

@ -1,25 +0,0 @@
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)]

View File

@ -1,22 +1,20 @@
{-# LANGUAGE BlockArguments #-}
module Display where
import Graphics.UI.GLUT
import Cells
import Control.Monad
import Data.IORef
import Cube
import Cells
import Graphics.UI.GLUT
display ::
display ::
IORef GLfloat ->
IORef Cells ->
IORef (GLfloat, GLfloat) ->
IORef Cells ->
IORef (GLfloat, GLfloat) ->
DisplayCallback
display z cells pos = do
clear [ColorBuffer]
(x',y') <- get pos
(x', y') <- get pos
old <- get cells
zoom <- get z
size <- get windowSize
@ -26,11 +24,10 @@ display z cells pos = do
let w = fromIntegral w'
let h = fromIntegral h'
matrixMode $= Projection
loadIdentity
let ar = w/h
ortho2D (-1*ar) (1*ar) (-1) 1
let ar = w / h
ortho2D (-1 * ar) (1 * ar) (-1) 1
matrixMode $= Modelview 0
loadIdentity
clear [ColorBuffer]
@ -40,4 +37,4 @@ display z cells pos = do
color $ Color3 1 1 (1 :: Float)
rendercells old
swapBuffers
swapBuffers

View File

@ -17,8 +17,7 @@
#
# 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
resolver: lts-18.18
# User packages to be built.
# Various formats can be used as shown in the example below.