Nature of Code examples and exercises implemented in Haskell using gloss.
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
ofALT
+ 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).
- Introduction
- Example I.1: Traditional random walk
- Example I.2: Random number distribution
- Example I.3: Walker that tends to move to the right
- Example I.4: Gaussian distribution
- Example I.5: Perlin noise walker
- Example I.6: 2D Perlin noise
- Exercise I.3: Dynamic random walker
- Exercise I.4: Paint splatter
- Exercise I.5: Gaussian random walk
- Exercise I.6: Custom distribution walker
- Exercise I.7: Perlin noise step size walker
- Exercise I.8: Interactive 2D Perlin noise
- Exercise I.9: Animated 2D Perlin noise
- Exercise I.10: 3D Perlin noise
- Extra: Interactive perlin noise graph
- Vectors
- Fractals
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 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
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 {} +
This is something I like to do to gain a better understanding of a language. See also: