├── .gitignore ├── .ocamlformat ├── LICENSE ├── README.md ├── camlwalk.opam ├── dune ├── dune-project ├── ocaml_commercial_jingle.wav ├── ocamlwalk.ml └── sprites.png /.gitignore: -------------------------------------------------------------------------------- 1 | _build/ 2 | _opam/ 3 | *.install 4 | .DS_Store 5 | -------------------------------------------------------------------------------- /.ocamlformat: -------------------------------------------------------------------------------- 1 | version = 0.26.1 2 | profile = default 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2023 Antonin Décimo 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | “Software”), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OCaml Walk 2 | 3 | > The caml walks, OCaml runs. 4 | 5 | Antonin & Engil collab' 6 | 7 | Photography from Eadweard Muybridge. 8 | -------------------------------------------------------------------------------- /camlwalk.opam: -------------------------------------------------------------------------------- 1 | # This file is generated by dune, edit dune-project instead 2 | opam-version: "2.0" 3 | synopsis: "The camel walks, OCaml runs" 4 | maintainer: ["Antonin Décimo "] 5 | authors: ["Antonin Décimo "] 6 | license: "MIT" 7 | homepage: "https://github.com/MisterDA/ocamlwalk" 8 | bug-reports: "https://github.com/MisterDA/ocamlwalk/issues" 9 | depends: [ 10 | "dune" {>= "3.11"} 11 | "tsdl" {>= "1.0.0"} 12 | "tsdl-image" {>= "0.6"} 13 | "odoc" {with-doc} 14 | ] 15 | build: [ 16 | ["dune" "subst"] {dev} 17 | [ 18 | "dune" 19 | "build" 20 | "-p" 21 | name 22 | "-j" 23 | jobs 24 | "@install" 25 | "@runtest" {with-test} 26 | "@doc" {with-doc} 27 | ] 28 | ] 29 | dev-repo: "git+https://github.com/MisterDA/ocamlwalk.git" 30 | -------------------------------------------------------------------------------- /dune: -------------------------------------------------------------------------------- 1 | (executable 2 | (public_name ocamlwalk) 3 | (name ocamlwalk) 4 | (libraries tsdl tsdl-image)) 5 | -------------------------------------------------------------------------------- /dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.11) 2 | 3 | (authors "Antonin Décimo ") 4 | (maintainers "Antonin Décimo ") 5 | (source (github MisterDA/ocamlwalk)) 6 | (license MIT) 7 | 8 | (generate_opam_files true) 9 | 10 | (package 11 | (name camlwalk) 12 | (synopsis "The camel walks, OCaml runs") 13 | (depends 14 | (tsdl (>= 1.0.0)) 15 | (tsdl-image (>= 0.6)))) 16 | -------------------------------------------------------------------------------- /ocaml_commercial_jingle.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MisterDA/ocamlwalk/47363a426d39767c6380d1d388727f062cee8c2d/ocaml_commercial_jingle.wav -------------------------------------------------------------------------------- /ocamlwalk.ml: -------------------------------------------------------------------------------- 1 | open Tsdl 2 | 3 | let unwrap msg = function 4 | | Error (`Msg e) -> 5 | Sdl.log "%s: %s" msg e; 6 | exit 1 7 | | Ok v -> v 8 | 9 | let run = ref true 10 | 11 | let main () = 12 | Sdl.init Sdl.Init.(video + events + audio) |> unwrap "Init error"; 13 | let _tsdl_image = Tsdl_image.Image.(init Init.png) in 14 | let w = 240 and h = 200 in 15 | let window = 16 | let flags = Sdl.Window.(opengl + borderless + resizable + allow_highdpi) in 17 | Sdl.create_window ~w ~h "SDL OpenGL" flags |> unwrap "Create window error" 18 | in 19 | Sdl.set_window_bordered window false; 20 | Sdl.set_window_title window "ocamlrun"; 21 | let renderer = Sdl.create_renderer window |> unwrap "Create renderer" in 22 | let texture = 23 | Tsdl_image.Image.load_texture renderer "sprites.png" 24 | |> unwrap "Couldn't load image" 25 | in 26 | let frames = 20 in 27 | let quads = 28 | Array.init frames (fun i -> Sdl.Rect.create ~x:(w * i) ~y:0 ~w ~h) 29 | in 30 | let i = ref 0 in 31 | let event = Sdl.Event.create () in 32 | 33 | let audio_spec = 34 | Sdl. 35 | { 36 | as_freq = 0; 37 | as_format = Sdl.Audio.f32; 38 | as_channels = 2; 39 | as_silence = 0; 40 | as_samples = 0; 41 | as_size = 0l; 42 | as_callback = None; 43 | } 44 | in 45 | let rw_ops = 46 | Sdl.rw_from_file "ocaml_commercial_jingle.wav" "r" |> unwrap "rw_from_file" 47 | in 48 | let audio_spec, data = 49 | Sdl.load_wav_rw rw_ops audio_spec Bigarray.Float32 |> unwrap "load_wav_rw" 50 | in 51 | let id, _audio_spec = 52 | Sdl.open_audio_device None false audio_spec Sdl.Audio.allow_any_change 53 | |> unwrap "audio_device" 54 | in 55 | 56 | Sdl.queue_audio id data |> unwrap "queue audio"; 57 | Sdl.pause_audio_device id false; 58 | 59 | while Sdl.get_queued_audio_size id > 0 && !run do 60 | if Sdl.poll_event (Some event) && Sdl.Event.(get event typ = quit) then 61 | run := false; 62 | Sdl.render_clear renderer |> unwrap "Render clear"; 63 | Sdl.set_render_draw_color renderer 255 255 255 255 64 | |> unwrap "Render draw color"; 65 | Sdl.render_copy ~src:quads.(!i) renderer texture |> unwrap "Render copy"; 66 | incr i; 67 | if !i >= frames then i := 0; 68 | Sdl.render_present renderer; 69 | Sdl.delay 35l 70 | done; 71 | 72 | Tsdl_image.Image.quit (); 73 | Sdl.destroy_window window; 74 | Sdl.quit (); 75 | 76 | Array.set Sys.argv 0 "ocamlrun"; 77 | let ocamlrun = 78 | Unix.create_process "ocamlrun" Sys.argv Unix.stdin Unix.stdout Unix.stderr 79 | in 80 | let status = 81 | match Unix.waitpid [] ocamlrun with 82 | | _, Unix.WEXITED status -> status 83 | | _, Unix.WSIGNALED _ -> 1 84 | | _, Unix.WSTOPPED _ -> 1 85 | in 86 | exit status 87 | 88 | let () = main () 89 | -------------------------------------------------------------------------------- /sprites.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MisterDA/ocamlwalk/47363a426d39767c6380d1d388727f062cee8c2d/sprites.png --------------------------------------------------------------------------------