Skip to content

Instantly share code, notes, and snippets.

@mdales
Created December 28, 2023 20:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdales/fb53bbfc0e0feaa78ac6a43f858c9cd4 to your computer and use it in GitHub Desktop.
Save mdales/fb53bbfc0e0feaa78ac6a43f858c9cd4 to your computer and use it in GitHub Desktop.
OCaml vs TIC-80
let boot (screen : Tcc.screen) : Framebuffer.framebuffer =
Framebuffer.init screen.width screen.height (fun _x _y -> 0)
let tick (t : int) (screen : Tcc.screen) (_prev : Framebuffer.framebuffer) : Framebuffer.framebuffer =
let ft = (Float.of_int t) *. 0.02 in
let buffer = Framebuffer.init screen.width screen.height (fun _x _y -> 0) in
for z = 0 to 75 do
let fz = (Float.of_int z) *. 8. in
for x = -30 to 30 do
let fx = ((Float.of_int x) *. 3.) in
let y = ((sin ((sin (ft /. 2.)) +. fx /. 50.) *. 3.) +. (sin((fz /. 50.) -. ft)) *. 3.) in
let px = (screen.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) + 6 in
Framebuffer.filled_circle px py (20 / (20 - (z / 4))) (if col < 0 then col + ((List.length screen.palette) - 1) else col) buffer
done
done;
buffer
(* ----- *)
let () =
let screen : Tcc.screen = {
width = 640 ;
height = 480 ;
scale = 1 ;
palette = 0x666666 :: Palette.generate_plasma_palette 15 ;
} in
Tcc.tcc_init screen "TCC Day 9 extra" boot tick
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment