From 7295474407101c0b42ba498a236bf53cf79c1d0c Mon Sep 17 00:00:00 2001 From: Michael Dales Date: Fri, 22 Aug 2025 08:56:03 +0100 Subject: [PATCH 1/5] Tidying up the examples further. --- README.md | 38 ++++++++++++++++++++++++++- anni_albers/README.md | 1 + anni_albers/bin/dune | 4 +++ {day11 => anni_albers}/bin/main.ml | 5 ++-- day10/bin/dune | 4 --- day10/dune-project | 24 ----------------- day10/lib/dune | 2 -- day11/bin/dune | 4 --- day11/dune-project | 24 ----------------- day11/lib/dune | 2 -- day12/bin/dune | 4 --- day12/dune-project | 24 ----------------- day12/lib/dune | 2 -- day5/bin/dune | 4 --- day5/dune-project | 24 ----------------- day5/lib/dune | 2 -- day6/bin/dune | 4 --- day6/dune-project | 24 ----------------- day6/lib/dune | 2 -- day8/bin/dune | 4 --- day8/dune-project | 24 ----------------- day8/lib/dune | 2 -- filedrop/README.md | 3 +++ filedrop/bin/dune | 2 +- filedrop/dune-project | 24 ----------------- filedrop/lib/dune | 2 -- flocking/bin/dune | 4 --- flocking/dune-project | 24 ----------------- flocking/lib/dune | 2 -- julia_set/bin/dune | 2 +- julia_set/dune-project | 24 ----------------- julia_set/lib/dune | 2 -- keytest/README.md | 1 + keytest/bin/dune | 2 +- keytest/dune-project | 24 ----------------- keytest/lib/dune | 2 -- landscape/README.md | 1 + landscape/bin/dune | 2 +- landscape/dune-project | 24 ----------------- landscape/lib/dune | 2 -- lava_lamp/README.md | 1 + lava_lamp/bin/dune | 4 +++ {day12 => lava_lamp}/bin/main.ml | 11 ++++---- lorenz/README.md | 1 + lorenz/bin/dune | 4 +++ {day8 => lorenz}/bin/main.ml | 5 +--- murmuration/README.md | 1 + murmuration/bin/dune | 4 +++ {flocking => murmuration}/bin/main.ml | 5 +--- paint/README.md | 1 + paint/bin/dune | 2 +- paint/dune-project | 24 ----------------- paint/lib/dune | 2 -- plasma/README.md | 1 + {day2 => plasma}/bin/dune | 0 {day2 => plasma}/bin/main.ml | 2 +- polygons/README.md | 1 + polygons/bin/dune | 4 +++ {polygontest => polygons}/bin/main.ml | 6 ++--- polygontest/bin/dune | 4 --- polygontest/dune-project | 24 ----------------- polygontest/lib/dune | 2 -- red_hexagon/README.md | 1 + red_hexagon/bin/dune | 4 +++ {day10 => red_hexagon}/bin/main.ml | 2 +- screen_saver/README.md | 1 + screen_saver/bin/dune | 4 +++ {day6 => screen_saver}/bin/main.ml | 0 shapes/README.md | 1 + shapes/bin/dune | 2 +- shapes/dune-project | 24 ----------------- shapes/lib/dune | 2 -- vera_molnar/README.md | 1 + vera_molnar/bin/dune | 4 +++ {day5 => vera_molnar}/bin/main.ml | 24 ++++++++--------- 75 files changed, 116 insertions(+), 438 deletions(-) create mode 100644 anni_albers/README.md create mode 100644 anni_albers/bin/dune rename {day11 => anni_albers}/bin/main.ml (91%) delete mode 100644 day10/bin/dune delete mode 100644 day10/dune-project delete mode 100644 day10/lib/dune delete mode 100644 day11/bin/dune delete mode 100644 day11/dune-project delete mode 100644 day11/lib/dune delete mode 100644 day12/bin/dune delete mode 100644 day12/dune-project delete mode 100644 day12/lib/dune delete mode 100644 day5/bin/dune delete mode 100644 day5/dune-project delete mode 100644 day5/lib/dune delete mode 100644 day6/bin/dune delete mode 100644 day6/dune-project delete mode 100644 day6/lib/dune delete mode 100644 day8/bin/dune delete mode 100644 day8/dune-project delete mode 100644 day8/lib/dune create mode 100644 filedrop/README.md delete mode 100644 filedrop/dune-project delete mode 100644 filedrop/lib/dune delete mode 100644 flocking/bin/dune delete mode 100644 flocking/dune-project delete mode 100644 flocking/lib/dune delete mode 100644 julia_set/dune-project delete mode 100644 julia_set/lib/dune create mode 100644 keytest/README.md delete mode 100644 keytest/dune-project delete mode 100644 keytest/lib/dune create mode 100644 landscape/README.md delete mode 100644 landscape/dune-project delete mode 100644 landscape/lib/dune create mode 100644 lava_lamp/README.md create mode 100644 lava_lamp/bin/dune rename {day12 => lava_lamp}/bin/main.ml (81%) create mode 100644 lorenz/README.md create mode 100644 lorenz/bin/dune rename {day8 => lorenz}/bin/main.ml (91%) create mode 100644 murmuration/README.md create mode 100644 murmuration/bin/dune rename {flocking => murmuration}/bin/main.ml (94%) create mode 100644 paint/README.md delete mode 100644 paint/dune-project delete mode 100644 paint/lib/dune create mode 100644 plasma/README.md rename {day2 => plasma}/bin/dune (100%) rename {day2 => plasma}/bin/main.ml (92%) create mode 100644 polygons/README.md create mode 100644 polygons/bin/dune rename {polygontest => polygons}/bin/main.ml (86%) delete mode 100644 polygontest/bin/dune delete mode 100644 polygontest/dune-project delete mode 100644 polygontest/lib/dune create mode 100644 red_hexagon/README.md create mode 100644 red_hexagon/bin/dune rename {day10 => red_hexagon}/bin/main.ml (96%) create mode 100644 screen_saver/README.md create mode 100644 screen_saver/bin/dune rename {day6 => screen_saver}/bin/main.ml (100%) create mode 100644 shapes/README.md delete mode 100644 shapes/dune-project delete mode 100644 shapes/lib/dune create mode 100644 vera_molnar/README.md create mode 100644 vera_molnar/bin/dune rename {day5 => vera_molnar}/bin/main.ml (69%) diff --git a/README.md b/README.md index 0902e76..baf7ef7 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,39 @@ # Claudius Examples -A library of examples of using Claudius, mostly from [Tiny Code Christmas](https://tcc.lovebyte.party) and [Genuary](https://genuary.art). +A library of examples of using [Claudius](https://github.com/claudiusFX/claudius), a simple retro-style graphics library for OCaml. Many originally created for [Tiny Code Christmas](https://tcc.lovebyte.party) and [Genuary](https://genuary.art). + +# Examples Directory + +## Using primitives + +These examples just show a single feature of Claudius, and are a good place to start if you're trying to understand how Claudius works. + +* [Polygons](/polygons/) - rotating filled polygons. +* [Red Hexagon](/red_hexagon/) - a different style of rotating polyons. +* [Screen saver](/screen_saver/) - a recreation of a classic screen saver effect from the early Macintosh era. +* [Shapes](/shapes/) - using simple shape outlines to create some animation effects. + +## Algorithmic effects + +These examples start to use Claudius to build up interesting effects based on some simple algorithms + +* [Julia Set](/julia_set/) - an animated [Julia set fractal](https://en.wikipedia.org/wiki/Julia_set). +* [Lorenz](/lorenz/) - an animated [Lorenz Attractor](https://en.wikipedia.org/wiki/Lorenz_system). +* [Murmuration](/murmuration/) - another Lorenz Attractor, but this time used to mimic a flock of swarming birds. +* [Plasma](/plasma/) - an example of a classic [plasma effect](https://en.wikipedia.org/wiki/Plasma_effect). + +## Misc effects + +Other more complex effects created using Claudius + +* [Anni Albers](/anni_albers/) - a homage to leading textile artist [Anni Albers](https://en.wikipedia.org/wiki/Anni_Albers). +* [Particles](/particles/) - creating a pseudo-3D point cloud of a planet. +* [Landscape](/landscape/) - using the algorithm from the [Plasma example](/plasma/) to create a pseudo-3D landscape. +* [Lava lamp](/lava_lamp/) - yet another effect routed in the [Plasma example](/plasma/), this time with dithering added. +* [Vera Molnár](/vera_molnar/) - a homage to pioneering digital artist [Vera Molnár](https://en.wikipedia.org/wiki/Vera_Molnár). + +## Interactive programs + +* [Paint](/paint/) - a simple painting program in a few lines of OCaml using Claudius. +* [Filedrop](/filedrop/) - a simple GIF image viewer that accepts files dropped on it. +* [keytest](/keytest/) - an example that shows what key was pressed. \ No newline at end of file diff --git a/anni_albers/README.md b/anni_albers/README.md new file mode 100644 index 0000000..f3f7786 --- /dev/null +++ b/anni_albers/README.md @@ -0,0 +1 @@ +A homage to the textile artist [Anni Albers](https://en.wikipedia.org/wiki/Anni_Albers), showing that inspiration for digital art can come from different domains. \ No newline at end of file diff --git a/anni_albers/bin/dune b/anni_albers/bin/dune new file mode 100644 index 0000000..2d87b45 --- /dev/null +++ b/anni_albers/bin/dune @@ -0,0 +1,4 @@ +(executable + (public_name anni_albers) + (name main) + (libraries claudius)) diff --git a/day11/bin/main.ml b/anni_albers/bin/main.ml similarity index 91% rename from day11/bin/main.ml rename to anni_albers/bin/main.ml index 3bcf19b..8ae1caf 100644 --- a/day11/bin/main.ml +++ b/anni_albers/bin/main.ml @@ -10,11 +10,10 @@ let tick t s _p _i = let fx = Float.of_int x and fy = Float.of_int y and ft = Float.of_int t in let c = 1 + Int.of_float ((sin (sin (fx /. 8.))) *. (sin (sin (fy /. 8.))) *. (1. +. (5. *. sin (ft /. 500.)))) mod cols in if c < 0 then c + cols else c - ) + ) (* ----- *) let () = Screen.create 126 226 3 (Palette.load_tic80_palette havrekaka_palette) |> - Base.run "Genuary 11: Anni Albers" None tick - \ No newline at end of file + Base.run "Anni Albers" None tick diff --git a/day10/bin/dune b/day10/bin/dune deleted file mode 100644 index 862cae0..0000000 --- a/day10/bin/dune +++ /dev/null @@ -1,4 +0,0 @@ -(executable - (public_name day10) - (name main) - (libraries day10 claudius)) diff --git a/day10/dune-project b/day10/dune-project deleted file mode 100644 index a8ea470..0000000 --- a/day10/dune-project +++ /dev/null @@ -1,24 +0,0 @@ -(lang dune 3.12) - -(name day10) - -(source - (github ClaudiusFX/claudius)) - -(authors "Michael Dales ") - -(maintainers "Michael Dales " "Shreya Pawaskar ") - -(license ICS) - -(documentation https://github.com/claudiusFX/claudius-examples/tree/main/day10) - -(package - (name day10) - (synopsis "A short synopsis") - (description "A longer description") - (depends ocaml dune) - (tags - (graphics rendering paletted))) - -; See the complete stanza docs at https://dune.readthedocs.io/en/stable/dune-files.html#dune-project diff --git a/day10/lib/dune b/day10/lib/dune deleted file mode 100644 index 8d8bd55..0000000 --- a/day10/lib/dune +++ /dev/null @@ -1,2 +0,0 @@ -(library - (name day10)) diff --git a/day11/bin/dune b/day11/bin/dune deleted file mode 100644 index 54669a0..0000000 --- a/day11/bin/dune +++ /dev/null @@ -1,4 +0,0 @@ -(executable - (public_name day11) - (name main) - (libraries day11 claudius)) diff --git a/day11/dune-project b/day11/dune-project deleted file mode 100644 index f56b1c7..0000000 --- a/day11/dune-project +++ /dev/null @@ -1,24 +0,0 @@ -(lang dune 3.12) - -(name day11) - -(source - (github ClaudiusFX/claudius)) - -(authors "Michael Dales ") - -(maintainers "Michael Dales " "Shreya Pawaskar ") - -(license ICS) - -(documentation https://github.com/claudiusFX/claudius-examples/tree/main/day11) - -(package - (name day11) - (synopsis "A short synopsis") - (description "A longer description") - (depends ocaml dune) - (tags - (graphics rendering paletted))) - -; See the complete stanza docs at https://dune.readthedocs.io/en/stable/dune-files.html#dune-project diff --git a/day11/lib/dune b/day11/lib/dune deleted file mode 100644 index 4dddf90..0000000 --- a/day11/lib/dune +++ /dev/null @@ -1,2 +0,0 @@ -(library - (name day11)) diff --git a/day12/bin/dune b/day12/bin/dune deleted file mode 100644 index f582be3..0000000 --- a/day12/bin/dune +++ /dev/null @@ -1,4 +0,0 @@ -(executable - (public_name day12) - (name main) - (libraries day12 claudius)) diff --git a/day12/dune-project b/day12/dune-project deleted file mode 100644 index ee5ed66..0000000 --- a/day12/dune-project +++ /dev/null @@ -1,24 +0,0 @@ -(lang dune 3.12) - -(name day12) - -(source - (github ClaudiusFX/claudius)) - -(authors "Michael Dales ") - -(maintainers "Michael Dales " "Shreya Pawaskar ") - -(license ICS) - -(documentation https://github.com/claudiusFX/claudius-examples/tree/main/day12) - -(package - (name day12) - (synopsis "A short synopsis") - (description "A longer description") - (depends ocaml dune) - (tags - (graphics rendering paletted))) - -; See the complete stanza docs at https://dune.readthedocs.io/en/stable/dune-files.html#dune-project diff --git a/day12/lib/dune b/day12/lib/dune deleted file mode 100644 index 891c6c3..0000000 --- a/day12/lib/dune +++ /dev/null @@ -1,2 +0,0 @@ -(library - (name day12)) diff --git a/day5/bin/dune b/day5/bin/dune deleted file mode 100644 index 8c5b85e..0000000 --- a/day5/bin/dune +++ /dev/null @@ -1,4 +0,0 @@ -(executable - (public_name day5) - (name main) - (libraries day5 claudius)) diff --git a/day5/dune-project b/day5/dune-project deleted file mode 100644 index 0382bd8..0000000 --- a/day5/dune-project +++ /dev/null @@ -1,24 +0,0 @@ -(lang dune 3.12) - -(name day5) - -(source - (github ClaudiusFX/claudius)) - -(authors "Michael Dales ") - -(maintainers "Michael Dales " "Shreya Pawaskar ") - -(license ICS) - -(documentation https://github.com/claudiusFX/claudius-examples/tree/main/day5) - -(package - (name day5) - (synopsis "A short synopsis") - (description "A longer description") - (depends ocaml dune) - (tags - (graphics rendering paletted))) - -; See the complete stanza docs at https://dune.readthedocs.io/en/stable/dune-files.html#dune-project diff --git a/day5/lib/dune b/day5/lib/dune deleted file mode 100644 index 2de91f0..0000000 --- a/day5/lib/dune +++ /dev/null @@ -1,2 +0,0 @@ -(library - (name day5)) diff --git a/day6/bin/dune b/day6/bin/dune deleted file mode 100644 index 35b91db..0000000 --- a/day6/bin/dune +++ /dev/null @@ -1,4 +0,0 @@ -(executable - (public_name day6) - (name main) - (libraries day6 claudius)) diff --git a/day6/dune-project b/day6/dune-project deleted file mode 100644 index 040b40a..0000000 --- a/day6/dune-project +++ /dev/null @@ -1,24 +0,0 @@ -(lang dune 3.12) - -(name day6) - -(source - (github ClaudiusFX/claudius)) - -(authors "Michael Dales ") - -(maintainers "Michael Dales " "Shreya Pawaskar ") - -(license ICS) - -(documentation https://github.com/claudiusFX/claudius-examples/tree/main/day6) - -(package - (name day6) - (synopsis "A short synopsis") - (description "A longer description") - (depends ocaml dune) - (tags - (graphics rendering paletted))) - -; See the complete stanza docs at https://dune.readthedocs.io/en/stable/dune-files.html#dune-project diff --git a/day6/lib/dune b/day6/lib/dune deleted file mode 100644 index dadd304..0000000 --- a/day6/lib/dune +++ /dev/null @@ -1,2 +0,0 @@ -(library - (name day6)) diff --git a/day8/bin/dune b/day8/bin/dune deleted file mode 100644 index ae74623..0000000 --- a/day8/bin/dune +++ /dev/null @@ -1,4 +0,0 @@ -(executable - (public_name day8) - (name main) - (libraries day8 claudius)) diff --git a/day8/dune-project b/day8/dune-project deleted file mode 100644 index c0ef318..0000000 --- a/day8/dune-project +++ /dev/null @@ -1,24 +0,0 @@ -(lang dune 3.12) - -(name day8) - -(source - (github ClaudiusFX/claudius)) - -(authors "Michael Dales ") - -(maintainers "Michael Dales " "Shreya Pawaskar ") - -(license ICS) - -(documentation https://github.com/claudiusFX/claudius-examples/tree/main/day8) - -(package - (name day8) - (synopsis "A short synopsis") - (description "A longer description") - (depends ocaml dune) - (tags - (graphics rendering paletted))) - -; See the complete stanza docs at https://dune.readthedocs.io/en/stable/dune-files.html#dune-project diff --git a/day8/lib/dune b/day8/lib/dune deleted file mode 100644 index 6c981bf..0000000 --- a/day8/lib/dune +++ /dev/null @@ -1,2 +0,0 @@ -(library - (name day8)) diff --git a/filedrop/README.md b/filedrop/README.md new file mode 100644 index 0000000..e609bfa --- /dev/null +++ b/filedrop/README.md @@ -0,0 +1,3 @@ +An example of Claudius accepting files dropped on the window from the file system. + +Note that unfortunately this example does not currently work under the Windows WSL environment. \ No newline at end of file diff --git a/filedrop/bin/dune b/filedrop/bin/dune index 845a3b6..7a0d817 100644 --- a/filedrop/bin/dune +++ b/filedrop/bin/dune @@ -1,4 +1,4 @@ (executable (public_name filedrop) (name main) - (libraries filedrop claudius giflib)) + (libraries claudius giflib)) diff --git a/filedrop/dune-project b/filedrop/dune-project deleted file mode 100644 index 0f926f2..0000000 --- a/filedrop/dune-project +++ /dev/null @@ -1,24 +0,0 @@ -(lang dune 3.17) - -(name filedrop) - -(source - (github ClaudiusFX/claudius)) - -(authors "Michael Dales ") - -(maintainers "Michael Dales " "Shreya Pawaskar ") - -(license ICS) - -(documentation https://github.com/claudiusFX/claudius-examples/tree/main/filedrop) - -(package - (name filedrop) - (synopsis "A short synopsis") - (description "A longer description") - (depends ocaml) - (tags - (graphics rendering paletted))) - -; See the complete stanza docs at https://dune.readthedocs.io/en/stable/reference/dune-project/index.html diff --git a/filedrop/lib/dune b/filedrop/lib/dune deleted file mode 100644 index ca2552f..0000000 --- a/filedrop/lib/dune +++ /dev/null @@ -1,2 +0,0 @@ -(library - (name filedrop)) diff --git a/flocking/bin/dune b/flocking/bin/dune deleted file mode 100644 index 2fd99a9..0000000 --- a/flocking/bin/dune +++ /dev/null @@ -1,4 +0,0 @@ -(executable - (public_name flocking) - (name main) - (libraries flocking claudius)) diff --git a/flocking/dune-project b/flocking/dune-project deleted file mode 100644 index eb5539d..0000000 --- a/flocking/dune-project +++ /dev/null @@ -1,24 +0,0 @@ -(lang dune 3.12) - -(name flocking) - -(source - (github ClaudiusFX/claudius)) - -(authors "Michael Dales ") - -(maintainers "Michael Dales " "Shreya Pawaskar ") - -(license ICS) - -(documentation https://github.com/claudiusFX/claudius-examples/tree/main/flocking) - -(package - (name flocking) - (synopsis "A short synopsis") - (description "A longer description") - (depends ocaml dune) - (tags - (graphics rendering paletted))) - -; See the complete stanza docs at https://dune.readthedocs.io/en/stable/dune-files.html#dune-project diff --git a/flocking/lib/dune b/flocking/lib/dune deleted file mode 100644 index 5a4cc3e..0000000 --- a/flocking/lib/dune +++ /dev/null @@ -1,2 +0,0 @@ -(library - (name flocking)) diff --git a/julia_set/bin/dune b/julia_set/bin/dune index b5a185d..e3f9dc7 100644 --- a/julia_set/bin/dune +++ b/julia_set/bin/dune @@ -1,4 +1,4 @@ (executable (public_name julia_set) (name main) - (libraries julia_set claudius)) + (libraries claudius)) diff --git a/julia_set/dune-project b/julia_set/dune-project deleted file mode 100644 index 59c7e3a..0000000 --- a/julia_set/dune-project +++ /dev/null @@ -1,24 +0,0 @@ -(lang dune 3.12) - -(name julia_set) - -(source - (github ClaudiusFX/claudius)) - -(authors "Michael Dales " "Shreya Pawaskar ") - -(maintainers "Michael Dales " "Shreya Pawaskar ") - -(license ICS) - -(documentation https://github.com/claudiusFX/claudius-examples/tree/main/julia_set) - -(package - (name julia_set) - (synopsis "An example on Julia Set") - (description "Julia Sets are intricate fractal shapes that arise from iterating a simple mathematical formula in the complex plane.") - (depends ocaml dune) - (tags - (graphics rendering paletted))) - -; See the complete stanza docs at https://dune.readthedocs.io/en/stable/dune-files.html#dune-project diff --git a/julia_set/lib/dune b/julia_set/lib/dune deleted file mode 100644 index 2021ee1..0000000 --- a/julia_set/lib/dune +++ /dev/null @@ -1,2 +0,0 @@ -(library - (name julia_set)) diff --git a/keytest/README.md b/keytest/README.md new file mode 100644 index 0000000..7c1997c --- /dev/null +++ b/keytest/README.md @@ -0,0 +1 @@ +A simple example showing Claudius responding to keyboard input. \ No newline at end of file diff --git a/keytest/bin/dune b/keytest/bin/dune index cb70556..51ae2b7 100644 --- a/keytest/bin/dune +++ b/keytest/bin/dune @@ -1,4 +1,4 @@ (executable (public_name keytest) (name main) - (libraries keytest claudius)) + (libraries claudius)) diff --git a/keytest/dune-project b/keytest/dune-project deleted file mode 100644 index eeef732..0000000 --- a/keytest/dune-project +++ /dev/null @@ -1,24 +0,0 @@ -(lang dune 3.14) - -(name keytest) - -(source - (github ClaudiusFX/claudius)) - -(authors "Michael Dales ") - -(maintainers "Michael Dales " "Shreya Pawaskar ") - -(license ICS) - -(documentation https://github.com/claudiusFX/claudius-examples/tree/main/keytest) - -(package - (name keytest) - (synopsis "A short synopsis") - (description "A longer description") - (depends ocaml dune) - (tags - (graphics rendering paletted))) - -; See the complete stanza docs at https://dune.readthedocs.io/en/stable/dune-files.html#dune-project diff --git a/keytest/lib/dune b/keytest/lib/dune deleted file mode 100644 index 4c4109c..0000000 --- a/keytest/lib/dune +++ /dev/null @@ -1,2 +0,0 @@ -(library - (name keytest)) diff --git a/landscape/README.md b/landscape/README.md new file mode 100644 index 0000000..0aa1284 --- /dev/null +++ b/landscape/README.md @@ -0,0 +1 @@ +This example uses the same core algorithm from the [Plasma effect example](/plasma/), but instead of plotting the effect directly to pixels, it is used to create a pseudo-3D landscape of hills and valleys. \ No newline at end of file diff --git a/landscape/bin/dune b/landscape/bin/dune index 0f6c214..1e39031 100644 --- a/landscape/bin/dune +++ b/landscape/bin/dune @@ -1,4 +1,4 @@ (executable (public_name landscape) (name main) - (libraries landscape claudius)) + (libraries claudius)) diff --git a/landscape/dune-project b/landscape/dune-project deleted file mode 100644 index f758d12..0000000 --- a/landscape/dune-project +++ /dev/null @@ -1,24 +0,0 @@ -(lang dune 3.12) - -(name landscape) - -(source - (github ClaudiusFX/claudius)) - -(authors "Michael Dales ") - -(maintainers "Michael Dales " "Shreya Pawaskar ") - -(license ICS) - -(documentation https://github.com/claudiusFX/claudius-examples/tree/main/landscape) - -(package - (name landscape) - (synopsis "A short synopsis") - (description "A longer description") - (depends ocaml dune) - (tags - (graphics rendering paletted))) - -; See the complete stanza docs at https://dune.readthedocs.io/en/stable/dune-files.html#dune-project diff --git a/landscape/lib/dune b/landscape/lib/dune deleted file mode 100644 index 2ff4f6c..0000000 --- a/landscape/lib/dune +++ /dev/null @@ -1,2 +0,0 @@ -(library - (name landscape)) diff --git a/lava_lamp/README.md b/lava_lamp/README.md new file mode 100644 index 0000000..0bc0da3 --- /dev/null +++ b/lava_lamp/README.md @@ -0,0 +1 @@ +Another variation on the [Plasma effect](/plasma/), this time trying to evoke the idea of a lava lamp through a combination of a non-continuous palette and [dithering](https://en.wikipedia.org/wiki/Dither). The dithering effect itself is broken, only dithering between colours that step up in palette order, not that step down. This leads to times when there are smooth transitions and times when there are pronounced transitions, making the effect more interesting: perfect does not always mean good in generative art! \ No newline at end of file diff --git a/lava_lamp/bin/dune b/lava_lamp/bin/dune new file mode 100644 index 0000000..dcd2f47 --- /dev/null +++ b/lava_lamp/bin/dune @@ -0,0 +1,4 @@ +(executable + (public_name lava_lamp) + (name main) + (libraries claudius)) diff --git a/day12/bin/main.ml b/lava_lamp/bin/main.ml similarity index 81% rename from day12/bin/main.ml rename to lava_lamp/bin/main.ml index 3544f7f..386d150 100644 --- a/day12/bin/main.ml +++ b/lava_lamp/bin/main.ml @@ -7,15 +7,14 @@ let tick t s _p _i = let fx = Float.of_int x and fy = Float.of_int y in let c = ((sin ((sin (ft /. 23.)) +. fx /. 150.) *. 1.) +. (atan(((fy +. fx) /. 70.) -. ft)) *. 1.) and d = ((sin ((sin (ft /. 23.)) +. fy /. 250.) *. 1.) +. (sin((fx /. 150.) -. ft)) *. 1.) - and e = ((cos ((sin (fx /. 103.)) +. ft /. 250.) *. 1.) *. (sin((ft /. 10.) -. 0.)) *. 3.) in + and e = ((cos ((sin (fx /. 103.)) +. ft /. 250.) *. 1.) *. (sin((ft /. 10.) -. 0.)) *. 3.) in let col = c +. d +. e in let r = Float.rem (col) 1. in let m = if r > (Random.float 1.) then 1 else 0 in - (Int.of_float col) + m - ) + (Int.of_float col) + m + ) -let () = +let () = Palette.generate_plasma_palette 16 |> Screen.create 480 640 1 |> - Base.run "Genuary 12/13: Lava Lamp/Wobbly Functions" None tick - \ No newline at end of file + Base.run "Lava Lamp" None tick diff --git a/lorenz/README.md b/lorenz/README.md new file mode 100644 index 0000000..e14e837 --- /dev/null +++ b/lorenz/README.md @@ -0,0 +1 @@ +This example draws a classic [Lorenz Attractor](https://en.wikipedia.org/wiki/Lorenz_system) as a line that eventually fades out. \ No newline at end of file diff --git a/lorenz/bin/dune b/lorenz/bin/dune new file mode 100644 index 0000000..73f60c0 --- /dev/null +++ b/lorenz/bin/dune @@ -0,0 +1,4 @@ +(executable + (public_name lorenz) + (name main) + (libraries claudius)) diff --git a/day8/bin/main.ml b/lorenz/bin/main.ml similarity index 91% rename from day8/bin/main.ml rename to lorenz/bin/main.ml index c947acf..7db078b 100644 --- a/day8/bin/main.ml +++ b/lorenz/bin/main.ml @@ -27,9 +27,6 @@ let project (point: float * float * float) (s : Screen.t) : (int * int * int) = (* ----- *) -let boot s = - Framebuffer.init (Screen.dimensions s) (fun _x _y -> 0) - let tick _t s prev _i = (* Fade what came before *) let buffer = Framebuffer.map (fun pixel -> @@ -54,4 +51,4 @@ let tick _t s prev _i = let () = Palette.of_list (List.rev (Palette.to_list (Palette.generate_mono_palette 1024))) |> Screen.create 640 480 1 |> - Base.run "Genuary Day 8: Chaotic" (Some boot) tick + Base.run "Lorenz Attractor" None tick diff --git a/murmuration/README.md b/murmuration/README.md new file mode 100644 index 0000000..f841b70 --- /dev/null +++ b/murmuration/README.md @@ -0,0 +1 @@ +This example uses a [Lorenz Attractor](https://en.wikipedia.org/wiki/Lorenz_system) algorithm to attempt to create something that looks like a group of birds in a [murmuration](https://en.wikipedia.org/wiki/Swarm_behaviour). By taking a standard math effect and just changing how it is viewed we can use it to mimic other things! \ No newline at end of file diff --git a/murmuration/bin/dune b/murmuration/bin/dune new file mode 100644 index 0000000..322e5f5 --- /dev/null +++ b/murmuration/bin/dune @@ -0,0 +1,4 @@ +(executable + (public_name murmuration) + (name main) + (libraries claudius)) diff --git a/flocking/bin/main.ml b/murmuration/bin/main.ml similarity index 94% rename from flocking/bin/main.ml rename to murmuration/bin/main.ml index ae53e9a..318c60c 100644 --- a/flocking/bin/main.ml +++ b/murmuration/bin/main.ml @@ -1,8 +1,5 @@ open Claudius -(* let sigma = 12. -let rho = 28 -let beta = 2.667 *) let dt = 0.001 let cur = ref (List.init 10240 (fun i -> @@ -57,4 +54,4 @@ let tick t s fb _i = let () = Palette.of_list [ 0xaaccff ; 0x0 ; 0xff0000 ; 0x0 ; 0x00ff00 ; 0x0 ; 0x0000ff ; 0x0 ] |> Screen.create 640 480 1 |> - Base.run "Genuary Day 19: Flocking" None tick + Base.run "Murmuration" None tick diff --git a/paint/README.md b/paint/README.md new file mode 100644 index 0000000..f37206f --- /dev/null +++ b/paint/README.md @@ -0,0 +1 @@ +An example of using Claudius to build a small interactive application. \ No newline at end of file diff --git a/paint/bin/dune b/paint/bin/dune index 84af3d8..1944709 100644 --- a/paint/bin/dune +++ b/paint/bin/dune @@ -1,4 +1,4 @@ (executable (public_name paint) (name main) - (libraries paint claudius)) + (libraries claudius)) diff --git a/paint/dune-project b/paint/dune-project deleted file mode 100644 index 4404793..0000000 --- a/paint/dune-project +++ /dev/null @@ -1,24 +0,0 @@ -(lang dune 3.17) - -(name paint) - -(source - (github ClaudiusFX/claudius)) - -(authors "Michael Dales ") - -(maintainers "Michael Dales " "Shreya Pawaskar ") - -(license ICS) - -(documentation https://github.com/claudiusFX/claudius-examples/tree/main/paint) - -(package - (name paint) - (synopsis "A short synopsis") - (description "A longer description") - (depends ocaml) - (tags - (graphics rendering paletted))) - -; See the complete stanza docs at https://dune.readthedocs.io/en/stable/reference/dune-project/index.html diff --git a/paint/lib/dune b/paint/lib/dune deleted file mode 100644 index ceabda4..0000000 --- a/paint/lib/dune +++ /dev/null @@ -1,2 +0,0 @@ -(library - (name paint)) diff --git a/plasma/README.md b/plasma/README.md new file mode 100644 index 0000000..120ae16 --- /dev/null +++ b/plasma/README.md @@ -0,0 +1 @@ +An example of a simple plasma effect that uses a palette with a large number of colours to achieve a very smooth set of transitions. The plasma shows the kind of effects you can build just using a few simple trig functions. \ No newline at end of file diff --git a/day2/bin/dune b/plasma/bin/dune similarity index 100% rename from day2/bin/dune rename to plasma/bin/dune diff --git a/day2/bin/main.ml b/plasma/bin/main.ml similarity index 92% rename from day2/bin/main.ml rename to plasma/bin/main.ml index 425230b..9240580 100644 --- a/day2/bin/main.ml +++ b/plasma/bin/main.ml @@ -12,4 +12,4 @@ let tick t s _prev _i = let () = Screen.create 640 480 1 (Palette.generate_plasma_palette 1024) |> - Base.run "Genuary Day 2: No Palette" None tick + Base.run "Plasma" None tick diff --git a/polygons/README.md b/polygons/README.md new file mode 100644 index 0000000..b14678a --- /dev/null +++ b/polygons/README.md @@ -0,0 +1 @@ +A simple example showing how to draw and rotate polygon shapes. \ No newline at end of file diff --git a/polygons/bin/dune b/polygons/bin/dune new file mode 100644 index 0000000..394b234 --- /dev/null +++ b/polygons/bin/dune @@ -0,0 +1,4 @@ +(executable + (public_name polygons) + (name main) + (libraries claudius)) diff --git a/polygontest/bin/main.ml b/polygons/bin/main.ml similarity index 86% rename from polygontest/bin/main.ml rename to polygons/bin/main.ml index 779cee4..c316d0a 100644 --- a/polygontest/bin/main.ml +++ b/polygons/bin/main.ml @@ -27,13 +27,11 @@ let tick t s fb _i = let fb = Framebuffer.init (Screen.dimensions s) (fun _ _ -> 0) in let w, h = Screen.dimensions s in let ft = Float.of_int t in - (* let t = 100 in *) - (* let ft = 100. in *) - let p = generate_poly (w/2) (h/2) 100 (3 + ((t /500) mod 5)) (ft /. 500.) 15 in + let p = generate_poly (w/2) (h/2) 100 (3 + ((t / 100) mod 5)) (ft /. 100.) 15 in Framebuffer.render fb [p]; fb let () = Palette.of_list (0xffffff :: (Palette.to_list (Palette.generate_plasma_palette 15))) |> Screen.create 640 480 1 |> - Base.run "Polygon test" None tick + Base.run "Polygons" None tick diff --git a/polygontest/bin/dune b/polygontest/bin/dune deleted file mode 100644 index 5fa93bb..0000000 --- a/polygontest/bin/dune +++ /dev/null @@ -1,4 +0,0 @@ -(executable - (public_name polygontest) - (name main) - (libraries polygontest claudius)) diff --git a/polygontest/dune-project b/polygontest/dune-project deleted file mode 100644 index d6857df..0000000 --- a/polygontest/dune-project +++ /dev/null @@ -1,24 +0,0 @@ -(lang dune 3.12) - -(name polygontest) - -(source - (github ClaudiusFX/claudius)) - -(authors "Michael Dales ") - -(maintainers "Michael Dales " "Shreya Pawaskar ") - -(license ICS) - -(documentation https://github.com/claudiusFX/claudius-examples/tree/main/polygontest) - -(package - (name polygontest) - (synopsis "A short synopsis") - (description "A longer description") - (depends ocaml dune) - (tags - (graphics rendering paletted))) - -; See the complete stanza docs at https://dune.readthedocs.io/en/stable/dune-files.html#dune-project diff --git a/polygontest/lib/dune b/polygontest/lib/dune deleted file mode 100644 index 56854a9..0000000 --- a/polygontest/lib/dune +++ /dev/null @@ -1,2 +0,0 @@ -(library - (name polygontest)) diff --git a/red_hexagon/README.md b/red_hexagon/README.md new file mode 100644 index 0000000..8c378a3 --- /dev/null +++ b/red_hexagon/README.md @@ -0,0 +1 @@ +An example developed for [Genuary](https://genuary.art) under the theme of "Hexagons". It shows rotating shapes drawn with a cycling palette of colours, with the hexagons highlighted in a different color. \ No newline at end of file diff --git a/red_hexagon/bin/dune b/red_hexagon/bin/dune new file mode 100644 index 0000000..b522cde --- /dev/null +++ b/red_hexagon/bin/dune @@ -0,0 +1,4 @@ +(executable + (public_name red_hexagon) + (name main) + (libraries claudius)) diff --git a/day10/bin/main.ml b/red_hexagon/bin/main.ml similarity index 96% rename from day10/bin/main.ml rename to red_hexagon/bin/main.ml index bc8de2f..f91460e 100644 --- a/day10/bin/main.ml +++ b/red_hexagon/bin/main.ml @@ -53,4 +53,4 @@ let () = let pal = List.rev (Palette.to_list (Palette.generate_mono_palette 16)) in let redpal = List.map (fun x -> x lor 0xff0000) pal in Screen.create 240 136 3 (Palette.of_list (List.concat [pal ; redpal])) |> - Base.run "Genuary Day 10: Hexagons" (Some boot) tick + Base.run "Red Hexagon" (Some boot) tick diff --git a/screen_saver/README.md b/screen_saver/README.md new file mode 100644 index 0000000..efdc7d4 --- /dev/null +++ b/screen_saver/README.md @@ -0,0 +1 @@ +A recreation of a classic screensaver from the early Macintosh era. \ No newline at end of file diff --git a/screen_saver/bin/dune b/screen_saver/bin/dune new file mode 100644 index 0000000..88efbdc --- /dev/null +++ b/screen_saver/bin/dune @@ -0,0 +1,4 @@ +(executable + (public_name screen_saver) + (name main) + (libraries claudius)) diff --git a/day6/bin/main.ml b/screen_saver/bin/main.ml similarity index 100% rename from day6/bin/main.ml rename to screen_saver/bin/main.ml diff --git a/shapes/README.md b/shapes/README.md new file mode 100644 index 0000000..f38c2fa --- /dev/null +++ b/shapes/README.md @@ -0,0 +1 @@ +An example of using shape outlines to create some simple visual effects. \ No newline at end of file diff --git a/shapes/bin/dune b/shapes/bin/dune index f572b0c..3e9d5c7 100644 --- a/shapes/bin/dune +++ b/shapes/bin/dune @@ -1,4 +1,4 @@ (executable (public_name shapes) (name main) - (libraries shapes claudius)) + (libraries claudius)) diff --git a/shapes/dune-project b/shapes/dune-project deleted file mode 100644 index f517d17..0000000 --- a/shapes/dune-project +++ /dev/null @@ -1,24 +0,0 @@ -(lang dune 3.12) - -(name shapes) - -(source - (github ClaudiusFX/claudius)) - -(authors "Michael Dales ") - -(maintainers "Michael Dales " "Shreya Pawaskar ") - -(license ICS) - -(documentation https://github.com/claudiusFX/claudius-examples/tree/main/shapes) - -(package - (name shapes) - (synopsis "A short synopsis") - (description "A longer description") - (depends ocaml dune) - (tags - (graphics rendering paletted))) - -; See the complete stanza docs at https://dune.readthedocs.io/en/stable/dune-files.html#dune-project diff --git a/shapes/lib/dune b/shapes/lib/dune deleted file mode 100644 index 2cc4a09..0000000 --- a/shapes/lib/dune +++ /dev/null @@ -1,2 +0,0 @@ -(library - (name shapes)) diff --git a/vera_molnar/README.md b/vera_molnar/README.md new file mode 100644 index 0000000..ae0db84 --- /dev/null +++ b/vera_molnar/README.md @@ -0,0 +1 @@ +An attempt to recreate the style of pioneering generative artist [Vera Molnár](https://en.wikipedia.org/wiki/Vera_Molnár). \ No newline at end of file diff --git a/vera_molnar/bin/dune b/vera_molnar/bin/dune new file mode 100644 index 0000000..a3db724 --- /dev/null +++ b/vera_molnar/bin/dune @@ -0,0 +1,4 @@ +(executable + (public_name vera_molnar) + (name main) + (libraries claudius)) diff --git a/day5/bin/main.ml b/vera_molnar/bin/main.ml similarity index 69% rename from day5/bin/main.ml rename to vera_molnar/bin/main.ml index aa429dd..dff085e 100644 --- a/day5/bin/main.ml +++ b/vera_molnar/bin/main.ml @@ -6,38 +6,38 @@ let tick t s p _i = Unix.sleepf 0.02; - let buffer = if (t mod 100) == 0 then + let buffer = if (t mod 100) == 0 then Framebuffer.init (Screen.dimensions s) (fun _x _y -> 15) - else + else p in let raw_squares = List.concat ( - List.init 5 (fun x -> + List.init 5 (fun x -> let xo = x * 100 in - List.init 5 (fun y : (int * Primitives.point list) -> + List.init 5 (fun y : (int * Primitives.point list) -> let yo = y * 100 in - ((x * 5) + y), - List.map (fun (p : Primitives.point) : Primitives.point -> + ((x * 5) + y), + List.map (fun (p : Primitives.point) : Primitives.point -> {x = p.x + xo ; y = p.y + yo} ) [{x=10 ; y=10} ; {x=90; y=10} ; {x=90; y=90} ; {x=10; y=90} ] ) ) ) in - let shuffled_squares = List.map ( fun square_item -> + let shuffled_squares = List.map ( fun square_item -> let col, square = square_item in - col + ((t / 100) * 3), - List.map (fun (p : Primitives.point) : Primitives.point -> + col + ((t / 100) * 3), + List.map (fun (p : Primitives.point) : Primitives.point -> {x = p.x + (Random.int (1 + col)) - 10 ; y = p.y + (Random.int (1 + col)) - 10} ) square ) raw_squares in let primitives_list = List.map ( fun item -> - let col, square = item in Primitives.Polygon (square, (col mod ((Palette.size (Screen.palette s)) - 1))) + let col, square = item in Primitives.Polygon (square, (col mod ((Palette.size (Screen.palette s)) - 1))) ) shuffled_squares in Framebuffer.render buffer primitives_list; buffer -let () = +let () = Screen.create 500 500 1 (Palette.load_tic80_palette havrekaka_palette) |> - Base.run "Genuary Day 5: Vera Molnár" None tick + Base.run "Vera Molnár" None tick From 4df39f909689780920b278c363b0ef0f5ea366f6 Mon Sep 17 00:00:00 2001 From: Michael Dales Date: Fri, 22 Aug 2025 10:06:40 +0100 Subject: [PATCH 2/5] Remove need for odoc for examples --- .github/workflows/main.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9e9e9b1..73ea192 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -46,6 +46,3 @@ jobs: - name: Run tests run: opam exec -- dune runtest - - - name: Build docs - run: opam exec -- dune build @doc From ca27da2555434f1e5f6e6926221f593fe7c94ec1 Mon Sep 17 00:00:00 2001 From: Michael Dales Date: Fri, 22 Aug 2025 11:48:46 +0100 Subject: [PATCH 3/5] More examples tidying --- README.md | 16 +++++++++- anni_albers_too/bin/dune | 4 +++ {day112 => anni_albers_too}/bin/main.ml | 2 +- bauhaus/bin/dune | 4 +++ {day18 => bauhaus}/bin/main.ml | 0 bounce/bin/main.ml | 16 +++++----- day112/bin/dune | 4 --- day112/dune-project | 24 -------------- day112/lib/dune | 2 -- day17/bin/dune | 4 --- day17/dune-project | 24 -------------- day17/lib/dune | 2 -- day17filled/bin/dune | 4 --- day17filled/dune-project | 24 -------------- day17filled/lib/dune | 2 -- day18/bin/dune | 4 --- day18/dune-project | 24 -------------- day18/lib/dune | 2 -- day20/bin/dune | 4 --- day20/dune-project | 23 ------------- day20/lib/dune | 2 -- dsotm/bin/dune | 2 +- dsotm/dune-project | 24 -------------- dsotm/lib/dune | 2 -- fern/README.md | 1 + fern/bin/dune | 2 +- fern/bin/main.ml | 2 +- fern/dune-project | 24 -------------- fern/lib/dune | 2 -- islamic_pattern/README.md | 1 + islamic_pattern/bin/dune | 4 +++ {day17 => islamic_pattern}/bin/main.ml | 2 +- islamic_pattern_filled/README.md | 1 + islamic_pattern_filled/bin/dune | 4 +++ .../bin/main.ml | 2 +- koch/bin/dune | 4 --- koch/dune-project | 24 -------------- koch/lib/dune | 2 -- koch_snowflake/README.md | 1 + koch_snowflake/bin/dune | 4 +++ {koch => koch_snowflake}/bin/main.ml | 24 +++++++------- koch_snowflake_filled/README.md | 1 + koch_snowflake_filled/bin/dune | 4 +++ .../bin/main.ml | 32 +++++++++---------- kochtoo/bin/dune | 4 --- kochtoo/dune-project | 24 -------------- kochtoo/lib/dune | 2 -- physics/README.md | 1 + physics/bin/dune | 2 +- physics/bin/main.ml | 12 +++---- physics/dune-project | 24 -------------- physics/lib/dune | 2 -- tcc3extra/bin/dune | 4 --- tcc3extra/dune-project | 24 -------------- tcc3extra/lib/dune | 2 -- tcc5/bin/dune | 4 --- tcc5/dune-project | 24 -------------- tcc5/lib/dune | 2 -- textgrid/README.md | 1 + textgrid/bin/dune | 4 +++ {day20 => textgrid}/bin/main.ml | 2 +- tunnel/README.md | 1 + tunnel/bin/dune | 4 +++ {tcc5 => tunnel}/bin/main.ml | 6 ++-- walking_mesh/README.md | 1 + walking_mesh/bin/dune | 4 +++ {tcc3extra => walking_mesh}/bin/main.ml | 12 +++---- 67 files changed, 119 insertions(+), 407 deletions(-) create mode 100644 anni_albers_too/bin/dune rename {day112 => anni_albers_too}/bin/main.ml (97%) create mode 100644 bauhaus/bin/dune rename {day18 => bauhaus}/bin/main.ml (100%) delete mode 100644 day112/bin/dune delete mode 100644 day112/dune-project delete mode 100644 day112/lib/dune delete mode 100644 day17/bin/dune delete mode 100644 day17/dune-project delete mode 100644 day17/lib/dune delete mode 100644 day17filled/bin/dune delete mode 100644 day17filled/dune-project delete mode 100644 day17filled/lib/dune delete mode 100644 day18/bin/dune delete mode 100644 day18/dune-project delete mode 100644 day18/lib/dune delete mode 100644 day20/bin/dune delete mode 100644 day20/dune-project delete mode 100644 day20/lib/dune delete mode 100644 dsotm/dune-project delete mode 100644 dsotm/lib/dune create mode 100644 fern/README.md delete mode 100644 fern/dune-project delete mode 100644 fern/lib/dune create mode 100644 islamic_pattern/README.md create mode 100644 islamic_pattern/bin/dune rename {day17 => islamic_pattern}/bin/main.ml (98%) create mode 100644 islamic_pattern_filled/README.md create mode 100644 islamic_pattern_filled/bin/dune rename {day17filled => islamic_pattern_filled}/bin/main.ml (98%) delete mode 100644 koch/bin/dune delete mode 100644 koch/dune-project delete mode 100644 koch/lib/dune create mode 100644 koch_snowflake/README.md create mode 100644 koch_snowflake/bin/dune rename {koch => koch_snowflake}/bin/main.ml (86%) create mode 100644 koch_snowflake_filled/README.md create mode 100644 koch_snowflake_filled/bin/dune rename {kochtoo => koch_snowflake_filled}/bin/main.ml (86%) delete mode 100644 kochtoo/bin/dune delete mode 100644 kochtoo/dune-project delete mode 100644 kochtoo/lib/dune create mode 100644 physics/README.md delete mode 100644 physics/dune-project delete mode 100644 physics/lib/dune delete mode 100644 tcc3extra/bin/dune delete mode 100644 tcc3extra/dune-project delete mode 100644 tcc3extra/lib/dune delete mode 100644 tcc5/bin/dune delete mode 100644 tcc5/dune-project delete mode 100644 tcc5/lib/dune create mode 100644 textgrid/README.md create mode 100644 textgrid/bin/dune rename {day20 => textgrid}/bin/main.ml (90%) create mode 100644 tunnel/README.md create mode 100644 tunnel/bin/dune rename {tcc5 => tunnel}/bin/main.ml (88%) create mode 100644 walking_mesh/README.md create mode 100644 walking_mesh/bin/dune rename {tcc3extra => walking_mesh}/bin/main.ml (87%) diff --git a/README.md b/README.md index baf7ef7..1bd4db6 100644 --- a/README.md +++ b/README.md @@ -2,38 +2,52 @@ A library of examples of using [Claudius](https://github.com/claudiusFX/claudius), a simple retro-style graphics library for OCaml. Many originally created for [Tiny Code Christmas](https://tcc.lovebyte.party) and [Genuary](https://genuary.art). +To run these you will need to install Claudius via opam, and then you can `dune exec [example_name]`. + # Examples Directory ## Using primitives These examples just show a single feature of Claudius, and are a good place to start if you're trying to understand how Claudius works. +* [Bounce](/bounce/) - example of a bouncing ball made from ellipses. * [Polygons](/polygons/) - rotating filled polygons. * [Red Hexagon](/red_hexagon/) - a different style of rotating polyons. * [Screen saver](/screen_saver/) - a recreation of a classic screen saver effect from the early Macintosh era. * [Shapes](/shapes/) - using simple shape outlines to create some animation effects. +* [TextGrid](/textgrid/) - drawing characters using the built in font for Claudius. +* [DSOTM](/dsotm/) - using a combination of primitive shapes to build up a familiar image. ## Algorithmic effects These examples start to use Claudius to build up interesting effects based on some simple algorithms +* [Fern](/fern/) - drawing a [Bansley Fern fractal](https://en.wikipedia.org/wiki/Barnsley_fern). * [Julia Set](/julia_set/) - an animated [Julia set fractal](https://en.wikipedia.org/wiki/Julia_set). +* [Koch Snowflake](/koch_snowflake/) - an example of using recursion to draw a [Koch snowflake fractal](https://en.wikipedia.org/wiki/Koch_snowflake). +* [Koch Snowflake Filled](/koch_snowflake_filled/) - a filled in version of the [Koch snowflake example](/koch_snowflake/). * [Lorenz](/lorenz/) - an animated [Lorenz Attractor](https://en.wikipedia.org/wiki/Lorenz_system). * [Murmuration](/murmuration/) - another Lorenz Attractor, but this time used to mimic a flock of swarming birds. * [Plasma](/plasma/) - an example of a classic [plasma effect](https://en.wikipedia.org/wiki/Plasma_effect). +* [Tunnel](/tunnel/) - an example of how simple math functions can create complex looking scenes. ## Misc effects Other more complex effects created using Claudius * [Anni Albers](/anni_albers/) - a homage to leading textile artist [Anni Albers](https://en.wikipedia.org/wiki/Anni_Albers). +* [Anni Albers Also](/anni_albers_too/) - a second homage to leading textile artist [Anni Albers](https://en.wikipedia.org/wiki/Anni_Albers). +* [Islamic pattern](/islamic_pattern/) - an example playing with [Islamic geometric patterns](https://en.wikipedia.org/wiki/Islamic_geometric_patterns) and positive/negative space. +* [Islamic pattern filled](/islamic_pattern_filled/) - a solid verson of the [Islamic pattern example](/islamic_pattern/). * [Particles](/particles/) - creating a pseudo-3D point cloud of a planet. * [Landscape](/landscape/) - using the algorithm from the [Plasma example](/plasma/) to create a pseudo-3D landscape. * [Lava lamp](/lava_lamp/) - yet another effect routed in the [Plasma example](/plasma/), this time with dithering added. +* [Physics](/physics/) - an example of using a simple [Hooke's law](https://en.wikipedia.org/wiki/Hooke%27s_law) library to add physics to the [Landscape](/landscape/) example. +* [Walking Mesh](/walking_mesh/) - an example of what looks like a stateful effect being implemented functionally. * [Vera Molnár](/vera_molnar/) - a homage to pioneering digital artist [Vera Molnár](https://en.wikipedia.org/wiki/Vera_Molnár). ## Interactive programs * [Paint](/paint/) - a simple painting program in a few lines of OCaml using Claudius. * [Filedrop](/filedrop/) - a simple GIF image viewer that accepts files dropped on it. -* [keytest](/keytest/) - an example that shows what key was pressed. \ No newline at end of file +* [keytest](/keytest/) - an example that shows what key was pressed. diff --git a/anni_albers_too/bin/dune b/anni_albers_too/bin/dune new file mode 100644 index 0000000..f369867 --- /dev/null +++ b/anni_albers_too/bin/dune @@ -0,0 +1,4 @@ +(executable + (public_name anni_albers_too) + (name main) + (libraries claudius)) diff --git a/day112/bin/main.ml b/anni_albers_too/bin/main.ml similarity index 97% rename from day112/bin/main.ml rename to anni_albers_too/bin/main.ml index 20d368c..02a0b61 100644 --- a/day112/bin/main.ml +++ b/anni_albers_too/bin/main.ml @@ -51,4 +51,4 @@ let tick t s _p _i = let () = Palette.load_tic80_palette havrekaka_palette |> Screen.create 500 600 1 |> - Base.run "Genuary 11: Anni Albers" None tick + Base.run "Anni Albers Also" None tick diff --git a/bauhaus/bin/dune b/bauhaus/bin/dune new file mode 100644 index 0000000..e717568 --- /dev/null +++ b/bauhaus/bin/dune @@ -0,0 +1,4 @@ +(executable + (public_name bauhaus) + (name main) + (libraries claudius)) diff --git a/day18/bin/main.ml b/bauhaus/bin/main.ml similarity index 100% rename from day18/bin/main.ml rename to bauhaus/bin/main.ml diff --git a/bounce/bin/main.ml b/bounce/bin/main.ml index 328bca8..7e93913 100644 --- a/bounce/bin/main.ml +++ b/bounce/bin/main.ml @@ -20,8 +20,8 @@ let filled = ref true (* Squash and stopping parameters :) Must stop after some time. This is to make sure that the whole infinitesimal bounce effect (Rolling) is avoided *) let squash_factor = 0.25 let fps = 60.0 -let stop_after_frames = int_of_float (2.0 *. fps) -let bounce_vis_vel_threshold = 2.0 +let stop_after_frames = int_of_float (2.0 *. fps) +let bounce_vis_vel_threshold = 2.0 let last_bounce_t = ref 0 (* where the key states are being tracked *) @@ -49,12 +49,12 @@ let tick t s _prev (inputs : Base.input_state) = x_vel := if !x_pos > max_width /. 2.0 then -.2.0 else 2.0; y_vel := 0.0; last_bounce_t := t; - was_space_pressed := true + was_space_pressed := true end; if Base.KeyCodeSet.mem Key.X inputs.keys && not !was_x_pressed then begin filled := not !filled; - was_x_pressed := true + was_x_pressed := true end; (* Update physics *) @@ -103,14 +103,14 @@ let tick t s _prev (inputs : Base.input_state) = (* Reset key states *) if not (Base.KeyCodeSet.mem Key.Space inputs.keys) then - was_space_pressed := false; + was_space_pressed := false; if not (Base.KeyCodeSet.mem Key.X inputs.keys) then - was_x_pressed := false; + was_x_pressed := false; fb let () = Random.self_init (); - Palette.generate_plasma_palette 18 + Palette.generate_plasma_palette 18 |> Screen.create (int_of_float max_width) (int_of_float max_height) 1 - |> Base.run "Bounce Ball Mini Game" None tick \ No newline at end of file + |> Base.run "Bounce Ball" None tick \ No newline at end of file diff --git a/day112/bin/dune b/day112/bin/dune deleted file mode 100644 index 317e21e..0000000 --- a/day112/bin/dune +++ /dev/null @@ -1,4 +0,0 @@ -(executable - (public_name day112) - (name main) - (libraries day112 claudius)) diff --git a/day112/dune-project b/day112/dune-project deleted file mode 100644 index db12f7b..0000000 --- a/day112/dune-project +++ /dev/null @@ -1,24 +0,0 @@ -(lang dune 3.12) - -(name day112) - -(source - (github ClaudiusFX/claudius)) - -(authors "Michael Dales ") - -(maintainers "Michael Dales " "Shreya Pawaskar ") - -(license ICS) - -(documentation https://github.com/claudiusFX/claudius-examples/tree/main/day112) - -(package - (name day112) - (synopsis "A short synopsis") - (description "A longer description") - (depends ocaml dune) - (tags - (graphics rendering paletted))) - -; See the complete stanza docs at https://dune.readthedocs.io/en/stable/dune-files.html#dune-project diff --git a/day112/lib/dune b/day112/lib/dune deleted file mode 100644 index be4ab30..0000000 --- a/day112/lib/dune +++ /dev/null @@ -1,2 +0,0 @@ -(library - (name day112)) diff --git a/day17/bin/dune b/day17/bin/dune deleted file mode 100644 index b58533d..0000000 --- a/day17/bin/dune +++ /dev/null @@ -1,4 +0,0 @@ -(executable - (public_name day17) - (name main) - (libraries day17 claudius)) diff --git a/day17/dune-project b/day17/dune-project deleted file mode 100644 index f6c7894..0000000 --- a/day17/dune-project +++ /dev/null @@ -1,24 +0,0 @@ -(lang dune 3.12) - -(name day17) - -(source - (github ClaudiusFX/claudius)) - -(authors "Michael Dales ") - -(maintainers "Michael Dales " "Shreya Pawaskar ") - -(license ICS) - -(documentation https://github.com/claudiusFX/claudius-examples/tree/main/day17) - -(package - (name day17) - (synopsis "A short synopsis") - (description "A longer description") - (depends ocaml dune) - (tags - (graphics rendering paletted))) - -; See the complete stanza docs at https://dune.readthedocs.io/en/stable/dune-files.html#dune-project diff --git a/day17/lib/dune b/day17/lib/dune deleted file mode 100644 index 533e412..0000000 --- a/day17/lib/dune +++ /dev/null @@ -1,2 +0,0 @@ -(library - (name day17)) diff --git a/day17filled/bin/dune b/day17filled/bin/dune deleted file mode 100644 index 4874658..0000000 --- a/day17filled/bin/dune +++ /dev/null @@ -1,4 +0,0 @@ -(executable - (public_name day17filled) - (name main) - (libraries day17filled claudius)) diff --git a/day17filled/dune-project b/day17filled/dune-project deleted file mode 100644 index 53f52d5..0000000 --- a/day17filled/dune-project +++ /dev/null @@ -1,24 +0,0 @@ -(lang dune 3.12) - -(name day17filled) - -(source - (github ClaudiusFX/claudius)) - -(authors "Michael Dales ") - -(maintainers "Michael Dales " "Shreya Pawaskar ") - -(license ICS) - -(documentation https://github.com/claudiusFX/claudius-examples/tree/main/day17filled) - -(package - (name day17filled) - (synopsis "A short synopsis") - (description "A longer description") - (depends ocaml dune) - (tags - (graphics rendering paletted))) - -; See the complete stanza docs at https://dune.readthedocs.io/en/stable/dune-files.html#dune-project diff --git a/day17filled/lib/dune b/day17filled/lib/dune deleted file mode 100644 index ab6722d..0000000 --- a/day17filled/lib/dune +++ /dev/null @@ -1,2 +0,0 @@ -(library - (name day17filled)) diff --git a/day18/bin/dune b/day18/bin/dune deleted file mode 100644 index 39d454a..0000000 --- a/day18/bin/dune +++ /dev/null @@ -1,4 +0,0 @@ -(executable - (public_name day18) - (name main) - (libraries day18 claudius)) diff --git a/day18/dune-project b/day18/dune-project deleted file mode 100644 index 3721faf..0000000 --- a/day18/dune-project +++ /dev/null @@ -1,24 +0,0 @@ -(lang dune 3.12) - -(name day18) - -(source - (github ClaudiusFX/claudius)) - -(authors "Michael Dales ") - -(maintainers "Michael Dales " "Shreya Pawaskar ") - -(license ICS) - -(documentation https://github.com/claudiusFX/claudius-examples/tree/main/day18) - -(package - (name day18) - (synopsis "A short synopsis") - (description "A longer description") - (depends ocaml dune) - (tags - (graphics rendering paletted))) - -; See the complete stanza docs at https://dune.readthedocs.io/en/stable/dune-files.html#dune-project diff --git a/day18/lib/dune b/day18/lib/dune deleted file mode 100644 index 54a61ce..0000000 --- a/day18/lib/dune +++ /dev/null @@ -1,2 +0,0 @@ -(library - (name day18)) diff --git a/day20/bin/dune b/day20/bin/dune deleted file mode 100644 index 1629e8e..0000000 --- a/day20/bin/dune +++ /dev/null @@ -1,4 +0,0 @@ -(executable - (public_name day20) - (name main) - (libraries day20 claudius unix)) diff --git a/day20/dune-project b/day20/dune-project deleted file mode 100644 index 065edb6..0000000 --- a/day20/dune-project +++ /dev/null @@ -1,23 +0,0 @@ -(lang dune 3.12) - -(name day20) - -(source - (github ClaudiusFX/claudius)) - -(authors "Michael Dales ") - -(maintainers "Michael Dales " "Shreya Pawaskar ") - -(license ICS) - -(documentation https://github.com/claudiusFX/claudius-examples/tree/main/day20) -(package - (name day20) - (synopsis "A short synopsis") - (description "A longer description") - (depends ocaml dune) - (tags - (graphics rendering paletted))) - -; See the complete stanza docs at https://dune.readthedocs.io/en/stable/dune-files.html#dune-project diff --git a/day20/lib/dune b/day20/lib/dune deleted file mode 100644 index ab1d49f..0000000 --- a/day20/lib/dune +++ /dev/null @@ -1,2 +0,0 @@ -(library - (name day20)) diff --git a/dsotm/bin/dune b/dsotm/bin/dune index a2d8406..6c6d18a 100644 --- a/dsotm/bin/dune +++ b/dsotm/bin/dune @@ -1,4 +1,4 @@ (executable (public_name dsotm) (name main) - (libraries dsotm claudius)) \ No newline at end of file + (libraries claudius)) \ No newline at end of file diff --git a/dsotm/dune-project b/dsotm/dune-project deleted file mode 100644 index 737645c..0000000 --- a/dsotm/dune-project +++ /dev/null @@ -1,24 +0,0 @@ -(lang dune 3.12) - -(name dsotm) - -(source - (github ClaudiusFX/claudius)) - -(authors "Michael Dales ") - -(maintainers "Michael Dales " "Shreya Pawaskar ") - -(license ICS) - -(documentation https://github.com/claudiusFX/claudius-examples/tree/main/dsotm) - -(package - (name dsotm) - (synopsis "A short synopsis") - (description "A longer description") - (depends ocaml dune) - (tags - (graphics rendering paletted))) - -; See the complete stanza docs at https://dune.readthedocs.io/en/stable/dune-files.html#dune-project diff --git a/dsotm/lib/dune b/dsotm/lib/dune deleted file mode 100644 index 65744be..0000000 --- a/dsotm/lib/dune +++ /dev/null @@ -1,2 +0,0 @@ -(library - (name dsotm)) diff --git a/fern/README.md b/fern/README.md new file mode 100644 index 0000000..6e7b404 --- /dev/null +++ b/fern/README.md @@ -0,0 +1 @@ +An implementation of the [Barnsley fern fractal](https://en.wikipedia.org/wiki/Barnsley_fern), which slowly renders a fern leaf in increasing detail. \ No newline at end of file diff --git a/fern/bin/dune b/fern/bin/dune index 1db4728..ef4bbb7 100644 --- a/fern/bin/dune +++ b/fern/bin/dune @@ -1,4 +1,4 @@ (executable (public_name fern) (name main) - (libraries fern claudius unix)) + (libraries claudius)) diff --git a/fern/bin/main.ml b/fern/bin/main.ml index 9fe8666..a17e61a 100644 --- a/fern/bin/main.ml +++ b/fern/bin/main.ml @@ -30,4 +30,4 @@ let tick _t s fb _i = let () = Palette.of_list (List.map (fun x -> x land 0x00ff00) ( (Palette.to_list (Palette.generate_mono_palette 256)))) |> Screen.create 640 480 1 |> - Base.run "Genuary 26: Grow Something" None tick + Base.run "Grow Something" None tick diff --git a/fern/dune-project b/fern/dune-project deleted file mode 100644 index 9020249..0000000 --- a/fern/dune-project +++ /dev/null @@ -1,24 +0,0 @@ -(lang dune 3.12) - -(name fern) - -(source - (github ClaudiusFX/claudius)) - -(authors "Michael Dales ") - -(maintainers "Michael Dales " "Shreya Pawaskar ") - -(license ICS) - -(documentation https://github.com/claudiusFX/claudius-examples/tree/main/fern) - -(package - (name fern) - (synopsis "A short synopsis") - (description "A longer description") - (depends ocaml dune) - (tags - (graphics rendering paletted))) - -; See the complete stanza docs at https://dune.readthedocs.io/en/stable/dune-files.html#dune-project diff --git a/fern/lib/dune b/fern/lib/dune deleted file mode 100644 index 348b62f..0000000 --- a/fern/lib/dune +++ /dev/null @@ -1,2 +0,0 @@ -(library - (name fern)) diff --git a/islamic_pattern/README.md b/islamic_pattern/README.md new file mode 100644 index 0000000..e3f4215 --- /dev/null +++ b/islamic_pattern/README.md @@ -0,0 +1 @@ +An effect that plays with an [Islamic geometric patterns](https://en.wikipedia.org/wiki/Islamic_geometric_patterns), alternativing between rotating the positive and negative spaces. \ No newline at end of file diff --git a/islamic_pattern/bin/dune b/islamic_pattern/bin/dune new file mode 100644 index 0000000..c3c5fa4 --- /dev/null +++ b/islamic_pattern/bin/dune @@ -0,0 +1,4 @@ +(executable + (public_name islamic_pattern) + (name main) + (libraries claudius)) diff --git a/day17/bin/main.ml b/islamic_pattern/bin/main.ml similarity index 98% rename from day17/bin/main.ml rename to islamic_pattern/bin/main.ml index db72c89..9d1cf7d 100644 --- a/day17/bin/main.ml +++ b/islamic_pattern/bin/main.ml @@ -83,4 +83,4 @@ let tick t s fb _i = let () = Palette.of_list (List.rev (Palette.to_list (Palette.generate_mono_palette 128))) |> Screen.create 640 480 1 |> - Base.run "Genuary Day 17: Islamic Patterns" None tick + Base.run "Islamic Patterns" None tick diff --git a/islamic_pattern_filled/README.md b/islamic_pattern_filled/README.md new file mode 100644 index 0000000..1978568 --- /dev/null +++ b/islamic_pattern_filled/README.md @@ -0,0 +1 @@ +A filled version of the [Islamic pattern example](/islamic_pattern/). \ No newline at end of file diff --git a/islamic_pattern_filled/bin/dune b/islamic_pattern_filled/bin/dune new file mode 100644 index 0000000..0c112bf --- /dev/null +++ b/islamic_pattern_filled/bin/dune @@ -0,0 +1,4 @@ +(executable + (public_name islamic_pattern_filled) + (name main) + (libraries claudius)) diff --git a/day17filled/bin/main.ml b/islamic_pattern_filled/bin/main.ml similarity index 98% rename from day17filled/bin/main.ml rename to islamic_pattern_filled/bin/main.ml index 0ce702c..1923574 100644 --- a/day17filled/bin/main.ml +++ b/islamic_pattern_filled/bin/main.ml @@ -87,4 +87,4 @@ let tick t s fb _i = let () = Palette.of_list (List.rev (Palette.to_list (Palette.generate_mono_palette 128))) |> Screen.create 640 480 1 |> - Base.run "Genuary Day 17: Islamic Patterns" None tick + Base.run "Filled Islamic Patterns" None tick diff --git a/koch/bin/dune b/koch/bin/dune deleted file mode 100644 index 5f097d2..0000000 --- a/koch/bin/dune +++ /dev/null @@ -1,4 +0,0 @@ -(executable - (public_name koch) - (name main) - (libraries koch claudius)) diff --git a/koch/dune-project b/koch/dune-project deleted file mode 100644 index 8c5362d..0000000 --- a/koch/dune-project +++ /dev/null @@ -1,24 +0,0 @@ -(lang dune 3.12) - -(name koch) - -(source - (github ClaudiusFX/claudius)) - -(authors "Michael Dales ") - -(maintainers "Michael Dales " "Shreya Pawaskar ") - -(license ICS) - -(documentation https://github.com/claudiusFX/claudius-examples/tree/main/koch) - -(package - (name koch) - (synopsis "A short synopsis") - (description "A longer description") - (depends ocaml dune) - (tags - (graphics rendering paletted))) - -; See the complete stanza docs at https://dune.readthedocs.io/en/stable/dune-files.html#dune-project diff --git a/koch/lib/dune b/koch/lib/dune deleted file mode 100644 index 0284b27..0000000 --- a/koch/lib/dune +++ /dev/null @@ -1,2 +0,0 @@ -(library - (name koch)) diff --git a/koch_snowflake/README.md b/koch_snowflake/README.md new file mode 100644 index 0000000..8716a61 --- /dev/null +++ b/koch_snowflake/README.md @@ -0,0 +1 @@ +An implementation of the [Koch snowflake fractal](https://en.wikipedia.org/wiki/Koch_snowflake), which is a good example of using recursion in an effect. \ No newline at end of file diff --git a/koch_snowflake/bin/dune b/koch_snowflake/bin/dune new file mode 100644 index 0000000..066f971 --- /dev/null +++ b/koch_snowflake/bin/dune @@ -0,0 +1,4 @@ +(executable + (public_name koch_snowflake) + (name main) + (libraries claudius)) diff --git a/koch/bin/main.ml b/koch_snowflake/bin/main.ml similarity index 86% rename from koch/bin/main.ml rename to koch_snowflake/bin/main.ml index d225020..7ef3211 100644 --- a/koch/bin/main.ml +++ b/koch_snowflake/bin/main.ml @@ -10,13 +10,13 @@ let tic80_palette = "000:1a1c2c5d275db13e53ef7d57ffcd75a7f07038b76425717929366f3 (* ----- *) -let left (a : float) (t : turtle) : turtle = +let left (a : float) (t : turtle) : turtle = { t with angle = t.angle -. ((a /. 360.) *. 2. *. Float.pi)} -let right (a : float) (t : turtle) : turtle = +let right (a : float) (t : turtle) : turtle = { t with angle = t.angle +. ((a /. 360.) *. 2. *. Float.pi)} -let forward (dist : float) (t : turtle) : turtle = +let forward (dist : float) (t : turtle) : turtle = let x, y, _ = match t.path with | [] -> 0., 0., false | hd :: _ -> hd @@ -28,10 +28,10 @@ let forward (dist : float) (t : turtle) : turtle = ) in { t with path = newpos :: t.path } -let penup (t : turtle) : turtle = +let penup (t : turtle) : turtle = {t with mark = false} -let pendown (t : turtle) : turtle = +let pendown (t : turtle) : turtle = {t with mark = true} (* ----- *) @@ -50,7 +50,7 @@ let rec kock (length : float) (level : int) (t : turtle) : turtle = kock l (level - 1) ) -let star (length : float) (level : int) (t : turtle) : turtle = +let star (length : float) (level : int) (t : turtle) : turtle = let moved_t = penup t |> left (360. /. 3.) |> forward length |> @@ -60,10 +60,10 @@ let star (length : float) (level : int) (t : turtle) : turtle = let rec loop (index : int) (t : turtle) : turtle = match index with | 0 -> t - | _ -> + | _ -> kock length level t |> right 60. |> - loop (index - 1) + loop (index - 1) in loop 6 moved_t @@ -72,7 +72,7 @@ let star (length : float) (level : int) (t : turtle) : turtle = let tick (t : int) (screen : Screen.t) (_prev : Framebuffer.t) (_inputs : Base.input_state): Framebuffer.t = let width, height = Screen.dimensions screen in let buffer = Framebuffer.init (width, height) (fun _x _y -> 0) in - + for i = 0 to 2 do let col = (10 + (i mod 2)) in let turtle = { @@ -80,7 +80,7 @@ let tick (t : int) (screen : Screen.t) (_prev : Framebuffer.t) (_inputs : Base.i path = [ ((Float.of_int (width / 2)), (Float.of_int (height / 2)), false) ] ; mark = false ; } in - + let ft = (Float.of_int t) /. 10. and fi = Float.of_int (2 - i) in let star = ( left (fi +. (3. *. ft)) turtle |> @@ -95,10 +95,10 @@ let tick (t : int) (screen : Screen.t) (_prev : Framebuffer.t) (_inputs : Base.i ) steps) col buffer done; buffer - + (* ----- *) let () = Palette.load_tic80_palette tic80_palette |> Screen.create 640 480 1 |> - Base.run "TCC Day 7 Extra" None tick + Base.run "Koch snowflake" None tick diff --git a/koch_snowflake_filled/README.md b/koch_snowflake_filled/README.md new file mode 100644 index 0000000..9ad745a --- /dev/null +++ b/koch_snowflake_filled/README.md @@ -0,0 +1 @@ +A filled in version of the [Koch fractal example](/koch/), which is slightly more complex because ordering matter more. \ No newline at end of file diff --git a/koch_snowflake_filled/bin/dune b/koch_snowflake_filled/bin/dune new file mode 100644 index 0000000..9f1f410 --- /dev/null +++ b/koch_snowflake_filled/bin/dune @@ -0,0 +1,4 @@ +(executable + (public_name koch_snowflake_filled) + (name main) + (libraries claudius)) diff --git a/kochtoo/bin/main.ml b/koch_snowflake_filled/bin/main.ml similarity index 86% rename from kochtoo/bin/main.ml rename to koch_snowflake_filled/bin/main.ml index 2205bf7..a7298eb 100644 --- a/kochtoo/bin/main.ml +++ b/koch_snowflake_filled/bin/main.ml @@ -10,13 +10,13 @@ let tic80_palette = "000:1a1c2c5d275db13e53ef7d57ffcd75a7f07038b76425717929366f3 (* ----- *) -let left (a : float) (t : turtle) : turtle = +let left (a : float) (t : turtle) : turtle = { t with angle = t.angle -. ((a /. 360.) *. 2. *. Float.pi)} -let right (a : float) (t : turtle) : turtle = +let right (a : float) (t : turtle) : turtle = { t with angle = t.angle +. ((a /. 360.) *. 2. *. Float.pi)} -let forward (dist : float) (t : turtle) : turtle = +let forward (dist : float) (t : turtle) : turtle = let x, y, _ = match t.path with | [] -> 0., 0., false | hd :: _ -> hd @@ -28,10 +28,10 @@ let forward (dist : float) (t : turtle) : turtle = ) in { t with path = newpos :: t.path } -let penup (t : turtle) : turtle = +let penup (t : turtle) : turtle = {t with mark = false} -let pendown (t : turtle) : turtle = +let pendown (t : turtle) : turtle = {t with mark = true} (* ----- *) @@ -50,7 +50,7 @@ let rec kock (length : float) (level : int) (t : turtle) : turtle = kock l (level - 1) ) -let star ~(length : float) ~(level : int) ~(turtle : turtle) : turtle = +let star ~(length : float) ~(level : int) ~(turtle : turtle) : turtle = let moved_t = penup turtle |> left (360. /. 3.) |> forward length |> @@ -60,10 +60,10 @@ let star ~(length : float) ~(level : int) ~(turtle : turtle) : turtle = let rec loop (index : int) (t : turtle) : turtle = match index with | 0 -> t - | _ -> + | _ -> kock length level t |> right 60. |> - loop (index - 1) + loop (index - 1) in loop 6 moved_t @@ -71,21 +71,21 @@ let star ~(length : float) ~(level : int) ~(turtle : turtle) : turtle = let tick (t : int) (screen : Screen.t) (_prev : Framebuffer.t) (_inputs : Base.input_state) : Framebuffer.t = let width, height = Screen.dimensions screen in - - let stars = List.init 3 (fun i -> + + let stars = List.init 3 (fun i -> let col = (10 + i) in let turtle = { angle = 0. ; path = [ ((Float.of_int (width / 2)), (Float.of_int (height / 2)), false) ] ; mark = false ; } in - + let ft = (Float.of_int t) /. 10. and fi = Float.of_int (2 - i) in let length = (Float.rem (2. *. (ft +. (fi *. 150.))) 450.) in let star = ( let t = left (fi +. (3. *. ft)) turtle in - star - ~length:length + star + ~length:length ~level:(abs (Int.of_float (5. *. sin (ft /. 10.)))) ~turtle:t ) in @@ -93,7 +93,7 @@ let tick (t : int) (screen : Screen.t) (_prev : Framebuffer.t) (_inputs : Base.i (length, steps, col) ) |> List.sort (fun a b -> - let lena, _, _ = a + let lena, _, _ = a and lenb, _, _ = b in Int.of_float(lenb -. lena) ) in @@ -111,10 +111,10 @@ let tick (t : int) (screen : Screen.t) (_prev : Framebuffer.t) (_inputs : Base.i ) steps) col buffer ) stars; buffer - + (* ----- *) let () = Palette.load_tic80_palette tic80_palette |> Screen.create 640 480 1 |> - Base.run "TCC Day 7 Extra Extra" None tick + Base.run "Koch Snowflake Filled" None tick diff --git a/kochtoo/bin/dune b/kochtoo/bin/dune deleted file mode 100644 index ad4c9c9..0000000 --- a/kochtoo/bin/dune +++ /dev/null @@ -1,4 +0,0 @@ -(executable - (public_name kochtoo) - (name main) - (libraries kochtoo claudius)) diff --git a/kochtoo/dune-project b/kochtoo/dune-project deleted file mode 100644 index 2e3b841..0000000 --- a/kochtoo/dune-project +++ /dev/null @@ -1,24 +0,0 @@ -(lang dune 3.12) - -(name kochtoo) - -(source - (github ClaudiusFX/claudius)) - -(authors "Michael Dales ") - -(maintainers "Michael Dales " "Shreya Pawaskar ") - -(license ICS) - -(documentation https://github.com/claudiusFX/claudius-examples/tree/main/kochtoo) - -(package - (name kochtoo) - (synopsis "A short synopsis") - (description "A longer description") - (depends ocaml dune) - (tags - (graphics rendering paletted))) - -; See the complete stanza docs at https://dune.readthedocs.io/en/stable/dune-files.html#dune-project diff --git a/kochtoo/lib/dune b/kochtoo/lib/dune deleted file mode 100644 index 0900c90..0000000 --- a/kochtoo/lib/dune +++ /dev/null @@ -1,2 +0,0 @@ -(library - (name kochtoo)) diff --git a/physics/README.md b/physics/README.md new file mode 100644 index 0000000..19139f9 --- /dev/null +++ b/physics/README.md @@ -0,0 +1 @@ +Based on the [Landscape](/landscape/) example, this uses the `hooke` library from opam, which implements [Hooke's law](https://en.wikipedia.org/wiki/Hooke%27s_law) of spring dynamics to add some physics to an example. \ No newline at end of file diff --git a/physics/bin/dune b/physics/bin/dune index 7fe4f19..dac9adb 100644 --- a/physics/bin/dune +++ b/physics/bin/dune @@ -1,4 +1,4 @@ (executable (public_name physics) (name main) - (libraries physics claudius hooke)) + (libraries claudius hooke)) diff --git a/physics/bin/main.ml b/physics/bin/main.ml index c77452c..3142c26 100644 --- a/physics/bin/main.ml +++ b/physics/bin/main.ml @@ -10,8 +10,8 @@ type item = { target : float ; } -let init_spheres (_t : int) = - Array.init grid_depth (fun _z -> +let init_spheres (_t : int) = + Array.init grid_depth (fun _z -> Array.init grid_width (fun _x -> { spring = Spring.make ~delta_time:(30. /. 5_000.) ~angular_freq:7. ~damping_ratio:0.15 ; @@ -23,7 +23,7 @@ let init_spheres (_t : int) = let spheres = init_spheres 42 -let calc_y fx fz ft = +let calc_y fx fz ft = let prey = ((sin ((sin (ft /. 2.)) +. fx /. 50.) *. 3.) +. (sin((fz /. 50.) -. ft)) *. 3.) in if prey > 0. then prey *. 3. else prey @@ -33,7 +33,7 @@ let reset_spheres (t : int) (spheres : item array array) = let fz = (Float.of_int z) *. 8. in Array.mapi_inplace (fun x _ -> let fx = ((Float.of_int (x - (grid_width / 2))) *. 3.) in - let y1 = calc_y fx fz ft + let y1 = calc_y fx fz ft and y2 = calc_y fx fz (ft +. 20.) in { spring = Spring.make ~delta_time:(30. /. 5_000.) ~angular_freq:7. ~damping_ratio:0.15; @@ -65,7 +65,7 @@ let tick (t : int) (screen : Screen.t) (_prev : Framebuffer.t) (_inputs : Base.i Array.iteri (fun x item -> let y = item.snapshot.position in let fx = ((Float.of_int (x - (grid_width / 2))) *. 3.) in - let px = (width / 2) + Int.of_float (fx /. (fz *. 1.8 -. 1200.) *. 1200.) + let px = (width / 2) + Int.of_float (fx /. (fz *. 1.8 -. 1200.) *. 1200.) and py = (Int.of_float ((y -. 40.) /. (fz *. 1.8 -. 1200.) *. 1200.)) + 100 and col = ((Int.of_float (y *. 4.)) mod palsize) in let dot = (20. /. (78. -. (fz /. 8.))) in @@ -80,4 +80,4 @@ let tick (t : int) (screen : Screen.t) (_prev : Framebuffer.t) (_inputs : Base.i let () = Palette.of_list (0x666666 :: (Palette.to_list (Palette.generate_plasma_palette 255))) |> Screen.create 640 480 1 |> - Base.run "Genuary Day 15: Use a Physics Library" None tick \ No newline at end of file + Base.run "Use a Physics Library" None tick \ No newline at end of file diff --git a/physics/dune-project b/physics/dune-project deleted file mode 100644 index bc39e39..0000000 --- a/physics/dune-project +++ /dev/null @@ -1,24 +0,0 @@ -(lang dune 3.12) - -(name physics) - -(source - (github ClaudiusFX/claudius)) - -(authors "Michael Dales ") - -(maintainers "Michael Dales " "Shreya Pawaskar ") - -(license ICS) - -(documentation https://github.com/claudiusFX/claudius-examples/tree/main/physics) - -(package - (name physics) - (synopsis "A short synopsis") - (description "A longer description") - (depends ocaml dune) - (tags - (graphics rendering paletted))) - -; See the complete stanza docs at https://dune.readthedocs.io/en/stable/dune-files.html#dune-project diff --git a/physics/lib/dune b/physics/lib/dune deleted file mode 100644 index 25b48dc..0000000 --- a/physics/lib/dune +++ /dev/null @@ -1,2 +0,0 @@ -(library - (name physics)) diff --git a/tcc3extra/bin/dune b/tcc3extra/bin/dune deleted file mode 100644 index d4a2a9c..0000000 --- a/tcc3extra/bin/dune +++ /dev/null @@ -1,4 +0,0 @@ -(executable - (public_name tcc3extra) - (name main) - (libraries tcc3extra claudius)) diff --git a/tcc3extra/dune-project b/tcc3extra/dune-project deleted file mode 100644 index f40551e..0000000 --- a/tcc3extra/dune-project +++ /dev/null @@ -1,24 +0,0 @@ -(lang dune 3.12) - -(name tcc3extra) - -(source - (github ClaudiusFX/claudius)) - -(authors "Michael Dales ") - -(maintainers "Michael Dales " "Shreya Pawaskar ") - -(license ICS) - -(documentation https://github.com/claudiusFX/claudius-examples/tree/main/tcc3extra) - -(package - (name tcc3extra) - (synopsis "A short synopsis") - (description "A longer description") - (depends ocaml dune) - (tags - (graphics rendering paletted))) - -; See the complete stanza docs at https://dune.readthedocs.io/en/stable/dune-files.html#dune-project diff --git a/tcc3extra/lib/dune b/tcc3extra/lib/dune deleted file mode 100644 index 1cf84b2..0000000 --- a/tcc3extra/lib/dune +++ /dev/null @@ -1,2 +0,0 @@ -(library - (name tcc3extra)) diff --git a/tcc5/bin/dune b/tcc5/bin/dune deleted file mode 100644 index beed256..0000000 --- a/tcc5/bin/dune +++ /dev/null @@ -1,4 +0,0 @@ -(executable - (public_name tcc5) - (name main) - (libraries tcc5 claudius)) diff --git a/tcc5/dune-project b/tcc5/dune-project deleted file mode 100644 index d0524bc..0000000 --- a/tcc5/dune-project +++ /dev/null @@ -1,24 +0,0 @@ -(lang dune 3.12) - -(name tcc5) - -(source - (github ClaudiusFX/claudius)) - -(authors "Michael Dales ") - -(maintainers "Michael Dales " "Shreya Pawaskar ") - -(license ICS) - -(documentation https://github.com/claudiusFX/claudius-examples/tree/main/tcc5) - -(package - (name tcc5) - (synopsis "A short synopsis") - (description "A longer description") - (depends ocaml dune) - (tags - (graphics rendering paletted))) - -; See the complete stanza docs at https://dune.readthedocs.io/en/stable/dune-files.html#dune-project diff --git a/tcc5/lib/dune b/tcc5/lib/dune deleted file mode 100644 index b8b2642..0000000 --- a/tcc5/lib/dune +++ /dev/null @@ -1,2 +0,0 @@ -(library - (name tcc5)) diff --git a/textgrid/README.md b/textgrid/README.md new file mode 100644 index 0000000..92bd7f3 --- /dev/null +++ b/textgrid/README.md @@ -0,0 +1 @@ +Another example inspired by two [Genuary](https://genuary.art) prompts, mixing typography and an 8x8 grid. \ No newline at end of file diff --git a/textgrid/bin/dune b/textgrid/bin/dune new file mode 100644 index 0000000..fcfa6ed --- /dev/null +++ b/textgrid/bin/dune @@ -0,0 +1,4 @@ +(executable + (public_name textgrid) + (name main) + (libraries claudius)) diff --git a/day20/bin/main.ml b/textgrid/bin/main.ml similarity index 90% rename from day20/bin/main.ml rename to textgrid/bin/main.ml index 3f803a5..478566c 100644 --- a/day20/bin/main.ml +++ b/textgrid/bin/main.ml @@ -19,4 +19,4 @@ let tick t s fb _i = let () = Palette.of_list (List.rev (0xff0000 :: (Palette.to_list (Palette.generate_mono_palette 255)))) |> Screen.create 200 200 2 |> - Base.run "Genuary 20/23: Generative Typography and 8x8" None tick + Base.run "Generative Typography and 8x8" None tick diff --git a/tunnel/README.md b/tunnel/README.md new file mode 100644 index 0000000..22c9c6f --- /dev/null +++ b/tunnel/README.md @@ -0,0 +1 @@ +Inspired by one of the challenges from [Tiny Code Christmas](https://tcc.lovebyte.party), this example shows how by stacking two different math functions, one to create concentric circles and one to create a fan of lines from the centre of the screen, you can create something that looks like more than the sum of its parts. \ No newline at end of file diff --git a/tunnel/bin/dune b/tunnel/bin/dune new file mode 100644 index 0000000..b653b0d --- /dev/null +++ b/tunnel/bin/dune @@ -0,0 +1,4 @@ +(executable + (public_name tunnel) + (name main) + (libraries claudius)) diff --git a/tcc5/bin/main.ml b/tunnel/bin/main.ml similarity index 88% rename from tcc5/bin/main.ml rename to tunnel/bin/main.ml index 5c9a6b8..66b30f6 100644 --- a/tcc5/bin/main.ml +++ b/tunnel/bin/main.ml @@ -12,10 +12,10 @@ let tick t s _p _i = and y = Float.of_int (j - (h / 2)) in let d1 = (float_of_int w) /. sqrt ((x *. x) +. (y *. y) +. 1.0) and c1 = ((atan2 y x) +. Float.pi) *. (fcolors /. (2.0 *. Float.pi)) in - let c2 = c1 +. (sin (ft /. 70.0) *. Float.pi *. 2.0) + let c2 = c1 +. (sin (ft /. 70.0) *. Float.pi *. 2.0) and d2 = d1 +. (Float.rem (ft /. 10.0) fcolors) in let p = (int_of_float (Float.floor c2)) lxor (int_of_float (Float.floor d2)) in - let pindex = (p mod colors) in + let pindex = (p mod colors) in if pindex < 0 then (colors + pindex) else pindex ) in Framebuffer.filled_circle (w / 2) (h / 2) 15. 1 buffer; @@ -24,4 +24,4 @@ let tick t s _p _i = let () = Palette.load_tic80_palette vapour_palette |> Screen.create 640 480 1 |> - Base.run "TCC Day 5" None tick \ No newline at end of file + Base.run "Tunnel" None tick \ No newline at end of file diff --git a/walking_mesh/README.md b/walking_mesh/README.md new file mode 100644 index 0000000..c7868ce --- /dev/null +++ b/walking_mesh/README.md @@ -0,0 +1 @@ +An example of how you can have a functional effect that looks like it must store a lot of state, but doesn't. Watching the effect one would perhaps assume we store the mesh in an array somewhere, but in fact each frame is generated for every update, making this effect functional in nature. \ No newline at end of file diff --git a/walking_mesh/bin/dune b/walking_mesh/bin/dune new file mode 100644 index 0000000..93a6d87 --- /dev/null +++ b/walking_mesh/bin/dune @@ -0,0 +1,4 @@ +(executable + (public_name walking_mesh) + (name main) + (libraries claudius)) diff --git a/tcc3extra/bin/main.ml b/walking_mesh/bin/main.ml similarity index 87% rename from tcc3extra/bin/main.ml rename to walking_mesh/bin/main.ml index 4f58067..ee4d940 100644 --- a/tcc3extra/bin/main.ml +++ b/walking_mesh/bin/main.ml @@ -10,7 +10,7 @@ type line = { b : point ; } -let generate_mono_palette (size : int) : int list = +let generate_mono_palette (size : int) : int list = List.init size (fun (index : int): int -> let fi = float_of_int index and fsize = float_of_int size in let ch = (cos (fi *. ((2.0 *. Float.pi) /. fsize)) *. 127.0) +. 128.0 in @@ -21,7 +21,7 @@ let generate_mono_palette (size : int) : int list = let generat_points (count : int) (t : int) (screen : Screen.t) : point list = let w, h = Screen.dimensions screen in Random.init 42; - List.init count (fun index -> + List.init count (fun index -> { x = ((Random.int w) + (((index + 1) * t) / 200)) mod w ; y = ((Random.int h) + (((index + 1) * t) / 200)) mod h ; @@ -31,8 +31,8 @@ let generat_points (count : int) (t : int) (screen : Screen.t) : point list = let distance (p1 : point) (p2 : point) : int = int_of_float (Float.sqrt((Float.pow (float_of_int (p2.x - p1.x)) 2.) +. (Float.pow (float_of_int (p2.y - p1.y)) 2.))) -let lines_from_points (points : point list) (threshold : int) : line list = - List.concat (List.map ( fun (outer : point) -> +let lines_from_points (points : point list) (threshold : int) : line list = + List.concat (List.map ( fun (outer : point) -> List.filter_map ( fun (inner : point) : line option -> let d = distance inner outer in if (d > 0) && (d <= threshold) then Option.some { @@ -51,7 +51,7 @@ let tick t s _p _i = let threshold = 80 + (int_of_float ((sin (ft /. 10.)) *. 20.)) in let points = generat_points 150 t s in - let lines = lines_from_points points threshold in + let lines = lines_from_points points threshold in List.iter (fun (v : line) -> let d = distance v.a v.b in let c = (((threshold - d) * ((Palette.size (Screen.palette s)) - 1)) / (threshold - 1)) in @@ -65,4 +65,4 @@ let tick t s _p _i = let () = Palette.of_list (generate_mono_palette 16) |> Screen.create 640 480 1 |> - Base.run "TCC Day 3 Extra" None tick + Base.run "Walking mesh" None tick From e8f2fef86daffc90903345fd359b283bc009a0a0 Mon Sep 17 00:00:00 2001 From: Michael Dales Date: Fri, 22 Aug 2025 13:03:07 +0100 Subject: [PATCH 4/5] Fix typo --- islamic_pattern/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/islamic_pattern/README.md b/islamic_pattern/README.md index e3f4215..c134ae8 100644 --- a/islamic_pattern/README.md +++ b/islamic_pattern/README.md @@ -1 +1 @@ -An effect that plays with an [Islamic geometric patterns](https://en.wikipedia.org/wiki/Islamic_geometric_patterns), alternativing between rotating the positive and negative spaces. \ No newline at end of file +An effect that plays with an [Islamic geometric patterns](https://en.wikipedia.org/wiki/Islamic_geometric_patterns), alternating between rotating the positive and negative spaces. \ No newline at end of file From 4da0d5f36790990f370104955080d9eca1b99e59 Mon Sep 17 00:00:00 2001 From: Michael Dales Date: Fri, 22 Aug 2025 13:30:54 +0100 Subject: [PATCH 5/5] Fix bauhaus example that no longer rendered properly. --- bauhaus/bin/main.ml | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/bauhaus/bin/main.ml b/bauhaus/bin/main.ml index 67547fe..bc5664c 100644 --- a/bauhaus/bin/main.ml +++ b/bauhaus/bin/main.ml @@ -3,7 +3,7 @@ open Claudius let outer_radius = 140. let inner_radius = 100. -let prev = Framebuffer.init (480, 480) (fun _ _ -> 0) +let double_buffer = Framebuffer.init (480, 480) (fun _x _y -> 0) let boot s = let max_col = (Palette.size (Screen.palette s)) - 1 in @@ -17,22 +17,19 @@ let boot s = let y = Int.of_float ((outer_radius +. 1.) *. (sin angle)) in Framebuffer.pixel_write (x + (w/2)) (y + (h/2)) (max_col - 1) fb done; - Framebuffer.map2_inplace (fun _ p -> p) prev fb; fb -let tick_d t s _fb _i = +let tick_d t s prev _i = let w, h = Screen.dimensions s in let cx = (w/2) and cy = (h/2) in - let delta = Framebuffer.init (w, h) (fun _x _y -> 0) in + Framebuffer.map_inplace (fun _ -> 0) double_buffer; Framebuffer.mapi_inplace (fun x y ofb -> let op = Framebuffer.pixel_read x y ofb in match op with | None -> 0 | Some (p) -> match p with - | 0 -> 0 - | 255 -> 255 - | i -> ( + | 254 -> ( let dx = Float.of_int(x - cx) and dy = Float.of_int(y - cy) in let wobble = 0.05 *. sin((Float.of_int t) /. 100.) in @@ -40,13 +37,11 @@ let tick_d t s _fb _i = and radius = sqrt ((dy *. dy) +. (dx *. dx)) in let nx = Int.of_float ((radius +. 2.) *. (cos angle)) in let ny = Int.of_float ((radius +. 2.) *. (sin angle)) in - let col = i in - Framebuffer.pixel_write (nx + cx) (ny + cy) col delta; - col - 1 - ) + Framebuffer.pixel_write (nx + cx) (ny + cy) 254 double_buffer; + 255) + | x -> x ) prev; - Framebuffer.map2_inplace (+) prev delta; - Framebuffer.map (fun p -> if p >= 0 && (p < 256) then p else 0) prev + Framebuffer.map2 (fun b a -> if a != 0 then a else b) prev double_buffer let tick t s fb i =