Skip to content

mark-gerarts/nature-of-code-haskell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nature of Code - Haskell edition

Nature of Code examples and exercises implemented in Haskell using gloss.

Recursive tree

Running examples manually

Run each sketch individually using the following command:

$ stack runghc src/<chapter>/<name>/Sketch.hs

E.g. to run the first example:

$ stack runghc src/Introduction/TraditionalRandomWalk/Sketch.hs

The README of each sketch provides its full command as well, ready to be copy-pasted.

Gloss provides a few default keybinds to interact with the sketch:

  • Quit using ESC
  • Move around with the arrows key or by dragging the screen
  • Zoom with the mousewheel, page up/down, CTRL+drag, right click + drag
  • Rotate with HOME/END of ALT + left click drag
  • Reset the viewport with R

These keybinds are not available in sketches that require interaction, or if changing the viewport does not make sense for a specific sketch (e.g. collision detection where the window edges act as walls).

Overview

3D

3D examples (e.g. this one) are implemented using not-gloss. It's a library for 3D graphics that is not affiliated with, but heavily inspired by gloss. Its familiar feel make it integrate well with the rest of the sketches

Recordings

Recordings of the sketches are made using SimpleScreenRecorder, as it allows to directly record an OpenGL application.

The recording is saved as an mp4, and then converted to gif using ffmpeg. A quick & dirty script to handle this is included:

$ ./gengif.sh sketch.mp4 sketch.gif

Generating documentation

Documentation is not committed, this serves more as a reminder for me, as I sometimes generate docs to check if my docblock syntax is okay.

$ find src/ -type f -name "*.hs" -exec stack exec -- haddock --html --pretty-html --hyperlinked-source --odir=dist/docs {} +

Related

This is something I like to do to gain a better understanding of a language. See also:

About

Nature of Code examples and exercises implemented in Haskell

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published