[ANN] ease-caml 0.1.7 - Easing library for OCaml

Hi everyone,

I am happy to introduce: ease-caml (on opam) - an easing library for OCaml.

Why?

In video games you often want to manage animations and transitions. Usually this requires deforming a floating point value from one value to another (often continuously) over time so that an object moves from one place to another. Such a deformation is often referred to as an easing or tween. It can be hard to keep track of tweens. In Lua, there are various libraries like hump.timer and Flux which help manage and organize the tweens you have made so you can easily create different kinds and have a single source of updating them. ease-caml is inspired by those libraries and is intended to help with OCaml game development.

Also, I mentioned games above: Whether you use SDL, Raylib, or pretty much anything else, you can use this library. It just requires an update loop.

Example

Here is a small example of a bouncing ball (uses raylib-ocaml).

type circle =
{
  r: float;
  x: float;
  y: float ref;
}

let ball : circle = { r = 40.0; x = 400.0; y = ref ~-.40.0 }
let ty = Tween.make_tween ball.y 225.0 ~ef:Easers.bounce 1.0
let tm = Tween.new_manager ()

let setup () =
  Raylib.init_window 800 450 "simple_tween";
  Raylib.set_target_fps 60;
  Tween.add ty tm

let rec loop () =
  if Raylib.window_should_close () then Raylib.close_window ()
  else (
    let open Raylib in
    Tween.update tm (get_frame_time ());
    begin_drawing ();
    clear_background Color.raywhite;
    draw_circle_v (Vector2.create ball.x !(ball.y)) ball.r Color.maroon;
    end_drawing ();
    loop ()
  )

let () = setup () |> loop

(Note as a new user I cannot put more than 2 links. If you need help finding hump.timer, Flux, or raylib-ocaml, please let me know!)

8 Likes

Very neat! I am trying to make a game but only using OCaml for the server component, but maybe it will grow complex enough that I can make use of this library on server side too.

1 Like