Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ jobs:
with:
ocaml-compiler: ${{ matrix.ocaml-compiler }}

- name: Update apt
run: sudo apt update

- name: Install requirements
run: sudo apt install -y libsdl2-dev

Expand Down
24 changes: 9 additions & 15 deletions day20/bin/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,14 @@ let tick t s fb _i =
| 255 -> if special then 255 else 254
| p -> p - 1
) fb;
match (Screen.font s) with
| None -> fb;
| Some (font) -> (
let x = Random.int 8 and y = Random.int 8 in
let ch = char_of_int (Random.int 256) in
let col = if (((t / 200) mod 8) == x) then 255 else 254 in
let _ = Framebuffer.draw_char ((x * 22) + 20) ((y * 22) + 15) font ch col fb in ();
); fb
let font = Screen.font s in
let x = Random.int 8 and y = Random.int 8 in
let ch = char_of_int (Random.int 256) in
let col = if (((t / 200) mod 8) == x) then 255 else 254 in
let _ = Framebuffer.draw_char ((x * 22) + 20) ((y * 22) + 15) font ch col fb in ();
fb

let () =
match Font.load_psf_font "thirdparty/tamzen-font/psf/TamzenForPowerline10x20.psf" with
| Error (reason) -> Printf.printf "Failed to read: %s" reason
| Ok font -> (
Palette.of_list (List.rev (0xff0000 :: (Palette.to_list (Palette.generate_mono_palette 255)))) |>
Screen.create_with_font 200 200 2 font |>
Base.run "Genuary 20/23: Generative Typography and 8x8" None tick
)
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
4 changes: 4 additions & 0 deletions filedrop/bin/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(executable
(public_name filedrop)
(name main)
(libraries filedrop claudius giflib))
77 changes: 77 additions & 0 deletions filedrop/bin/main.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
open Claudius
open Giflib

let image : GIF.t option ref = ref None

let draw_gif t s gif fb =
let c = GIF.image_count gif in
let frame = ((t / 2) mod c) in
let i = GIF.get_image gif frame in

let new_pal = Palette.of_list ( 0x000000 :: 0xFFFFFF :: List.map (fun (r, g, b) ->
b + (g * 256) + (r * 256 * 256)
) (Array.to_list (Image.palette i))) in
Screen.update_palette s new_pal;

let sw, sh = Screen.dimensions s
and gw, gh = GIF.dimensions gif
and iw, ih = Image.dimensions i
and ixoff, iyoff = Image.offset i
and pixels = Image.pixels i in
let transparent = match (Image.transparent i) with
| None -> -1
| Some x -> x
in
let sxoff = (sw - gw) / 2
and syoff = (sh - gh) / 2 in
for x = 0 to (iw - 1) do
for y = 0 to (ih - 1) do
let v = pixels.(x + (y * iw)) in
if (v != transparent) then
Framebuffer.pixel_write (x + sxoff + ixoff) (y + syoff + iyoff) (v + 2) fb
done
done;

fb

let boot s =
let fb = Framebuffer.init (Screen.dimensions s) (fun _ _ -> 0) in
let font = Screen.font s in
ignore (Framebuffer.draw_string 10 10 font "Drop a GIF here" 1 fb);
fb

let tick t s prev (inputs : Base.input_state) =

let filename = List.fold_left (fun acc ev ->
match ev with
| Event.DropFile pth -> Some pth
| _ -> acc
) None inputs.events in

let updated = match filename with
| None -> false
| Some filename -> (
(match Filename.extension filename with
| ".gif" -> image := Some (GIF.from_file filename)
| _ -> image := None);
true
)
in

match !image, updated with
| None, true -> boot s
| None, false -> prev
| Some img, false -> (
match GIF.image_count img with
| 1 -> prev
| _ -> draw_gif t s img prev
)
| Some img, true -> (
Framebuffer.init (Screen.dimensions s) (fun _ _ -> 0) |>
draw_gif t s img
)

let () =
Palette.of_list (0x000000 :: 0xFFFFFF :: (Palette.to_list (Palette.generate_plasma_palette 256))) |>
Screen.create 640 480 1 |>
Base.run "File drop test" (Some boot) tick
26 changes: 26 additions & 0 deletions filedrop/dune-project
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
(lang dune 3.17)

(name filedrop)

(generate_opam_files true)

(source
(github username/reponame))

(authors "Author Name <author@example.com>")

(maintainers "Maintainer Name <maintainer@example.com>")

(license LICENSE)

(documentation https://url/to/documentation)

(package
(name filedrop)
(synopsis "A short synopsis")
(description "A longer description")
(depends ocaml)
(tags
("add topics" "to describe" your project)))

; See the complete stanza docs at https://dune.readthedocs.io/en/stable/reference/dune-project/index.html
31 changes: 31 additions & 0 deletions filedrop/filedrop.opam
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
synopsis: "A short synopsis"
description: "A longer description"
maintainer: ["Maintainer Name <maintainer@example.com>"]
authors: ["Author Name <author@example.com>"]
license: "LICENSE"
tags: ["add topics" "to describe" "your" "project"]
homepage: "https://github.com/username/reponame"
doc: "https://url/to/documentation"
bug-reports: "https://github.com/username/reponame/issues"
depends: [
"dune" {>= "3.17"}
"ocaml"
"odoc" {with-doc}
]
build: [
["dune" "subst"] {dev}
[
"dune"
"build"
"-p"
name
"-j"
jobs
"@install"
"@runtest" {with-test}
"@doc" {with-doc}
]
]
dev-repo: "git+https://github.com/username/reponame.git"
2 changes: 2 additions & 0 deletions filedrop/lib/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(library
(name filedrop))
2 changes: 2 additions & 0 deletions filedrop/test/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(test
(name test_filedrop))
Empty file added filedrop/test/test_filedrop.ml
Empty file.
37 changes: 15 additions & 22 deletions fonts/bin/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,20 @@ let prose2 = "Hello to FieldFX, thanks for the inspirations and encouragement!"
let tick t s fb _i =
let width, height = Screen.dimensions s in
Framebuffer.map_inplace (fun _ -> 0) fb;
match (Screen.font s) with
| None -> fb
| Some font -> (
let prose1_width = Framebuffer.draw_string 0 0 font prose1 0 fb in
(* let prose2_width = Framebuffer.draw_string 0 0 font prose2 0 fb in *)
let slow_t = t / 20 in
let pos1 = (slow_t mod (width + (1 * prose1_width))) - prose1_width in
let _ = Framebuffer.draw_string pos1 10 font prose1 (1 + ((slow_t / 10) mod 8)) fb in ();
for i = 0 to ((String.length prose2) - 1) do
let ft = (Float.of_int t) /. 100. in
let c = String.get prose2 i in
let _ = Framebuffer.draw_char (width + ((width - slow_t + (i * 15)) mod width)) ((Int.of_float (40. *. sin ((ft +. Float.of_int(i)) *. 0.1))) + (height / 2)) font c 3 fb in ();
done;
fb
)
let font = Screen.font s in
let prose1_width = Framebuffer.draw_string 0 0 font prose1 0 fb in
(* let prose2_width = Framebuffer.draw_string 0 0 font prose2 0 fb in *)
let slow_t = t / 2 in
let pos1 = (slow_t mod (width + (1 * prose1_width))) - prose1_width in
let _ = Framebuffer.draw_string pos1 10 font prose1 (1 + ((slow_t / 10) mod 8)) fb in ();
for i = 0 to ((String.length prose2) - 1) do
let ft = (Float.of_int t) /. 100. in
let c = String.get prose2 i in
let _ = Framebuffer.draw_char (width + ((width - slow_t + (i * 15)) mod width)) ((Int.of_float (40. *. sin ((ft +. Float.of_int(i)) *. 0.1))) + (height / 2)) font c 3 fb in ();
done;
fb

let () =
match Font.load_psf_font "thirdparty/tamzen-font/psf/TamzenForPowerline10x20.psf" with
| Error (reason) -> Printf.printf "Failed to read: %s" reason
| Ok font -> (
Palette.load_tic80_palette tic80_palette |>
Screen.create_with_font 240 136 3 font |>
Base.run "Font testing" None tick
)
Palette.load_tic80_palette tic80_palette |>
Screen.create 240 136 3 |>
Base.run "Font testing" None tick
24 changes: 8 additions & 16 deletions keytest/bin/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@ let pos = ref (0, 0)

let tick _t s _prev (inputs : Base.input_state) =
let fb = Framebuffer.init (Screen.dimensions s) (fun _x _y -> 0) in
(
match (Screen.font s) with
| None -> ()
| Some font -> (
List.iteri (fun i c ->
let s = Printf.sprintf "0x%08x" (Base.PlatformKey.to_backend_keycode c) in
ignore(Framebuffer.draw_string 5 (i * 12) font s 8 fb)
) (Base.KeyCodeSet.to_list inputs.keys)
));
let font = Screen.font s in
List.iteri (fun i c ->
let s = Printf.sprintf "0x%08x" (Base.PlatformKey.to_backend_keycode c) in
ignore(Framebuffer.draw_string 5 (i * 12) font s 8 fb)
) (Base.KeyCodeSet.to_list inputs.keys);

let dx, dy = List.fold_right (
fun c (x, y) ->
Expand All @@ -33,10 +29,6 @@ let tick _t s _prev (inputs : Base.input_state) =
(* ----- *)

let () =
match Font.load_psf_font "thirdparty/tamzen-font/psf/TamzenForPowerline10x20.psf" with
| Error (reason) -> Printf.printf "Failed to read: %s" reason
| Ok font -> (
Palette.of_list (List.rev (Palette.to_list (Palette.generate_plasma_palette 16))) |>
Screen.create_with_font 640 480 1 font |>
Base.run "Keyboard test" None tick
)
Palette.of_list (List.rev (Palette.to_list (Palette.generate_plasma_palette 16))) |>
Screen.create 640 480 1 |>
Base.run "Keyboard test" None tick
8 changes: 4 additions & 4 deletions paint/bin/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ let tick _ s buffer (inputs : Base.input_state) : Framebuffer.t =

List.iter (fun e ->
match e with
| Mouse.Button_up (Left, _) -> (
| Event.MouseButtonUp (Left, _) -> (
last_coord := None;
)
| Mouse.Button_down (Left, (x, y)) -> (
| Event.MouseButtonDown (Left, (x, y)) -> (
if (x >= (w - size)) then (
col := y / size
);
last_coord := Some (x, y)
)
| Mouse.Drag (Left, (x, y)) -> (
| Event.MouseDrag (Left, (x, y)) -> (

match !last_coord with
| None -> (
Expand All @@ -55,7 +55,7 @@ let tick _ s buffer (inputs : Base.input_state) : Framebuffer.t =
)
)
| _ -> ()
) ( Mouse.get_events inputs.mouse);
) inputs.events;
buffer

let () =
Expand Down
33 changes: 13 additions & 20 deletions triangles/bin/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -71,25 +71,18 @@ let tick t s fb _i =
Framebuffer.draw_circle (width / 2) (height / 2) 100. (col / 3) fb;
Framebuffer.draw_circle (width / 2) (height / 2) 50. (col / 2) fb;

match (Screen.font s) with
| None -> fb
| Some font -> (
filled_triangle
((Int.of_float (50. *. (sin (ft)))) + (width / 2))
((Int.of_float (50. *. (cos (ft)))) + (height / 2))
((Int.of_float (150. *. (sin (ft +. (Float.pi *. 1.5))))) + (width / 2))
((Int.of_float (150. *. (cos (ft +. (Float.pi *. 1.5))))) + (height / 2))
((Int.of_float (100. *. (sin (ft +. 2.)))) + (width / 2))
((Int.of_float (100. *. (cos (ft +. 2.)))) + (height / 2))
col fb font;
fb
)
let font = Screen.font s in
filled_triangle
((Int.of_float (50. *. (sin (ft)))) + (width / 2))
((Int.of_float (50. *. (cos (ft)))) + (height / 2))
((Int.of_float (150. *. (sin (ft +. (Float.pi *. 1.5))))) + (width / 2))
((Int.of_float (150. *. (cos (ft +. (Float.pi *. 1.5))))) + (height / 2))
((Int.of_float (100. *. (sin (ft +. 2.)))) + (width / 2))
((Int.of_float (100. *. (cos (ft +. 2.)))) + (height / 2))
col fb font;
fb

let () =
match Font.load_psf_font "thirdparty/tamzen-font/psf/TamzenForPowerline10x20.psf" with
| Error (reason) -> Printf.printf "Failed to read: %s" reason
| Ok font -> (
Palette.of_list (List.rev (Palette.to_list (Palette.generate_mono_palette 16))) |>
Screen.create_with_font 640 480 1 font |>
Base.run "Triangle testing" None tick
)
Palette.of_list (List.rev (Palette.to_list (Palette.generate_mono_palette 16))) |>
Screen.create 640 480 1 |>
Base.run "Triangle testing" None tick
Loading