This repository was archived by the owner on Feb 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbouncr.ml
63 lines (40 loc) · 1.44 KB
/
bouncr.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
open Printf
module T = ANSITerminal
(* http://stackoverflow.com/a/10789674 *)
let minisleep (seconds:float) =
ignore (Unix.select [] [] [] seconds)
let x : int ref = ref 120
let y : int ref = ref 1
let x' : int ref = ref (1)
let y' : int ref = ref (-1)
let moveit (s:string) =
let str_len : int = String.length s in
let all_colors = [T.Black; T.Red; T.Green; T.Yellow;
T.Blue; T.Magenta; T.Cyan; T.White; T.Default] in
let all_styles = [T.Bold; T.Underlined; T.Blink] in
let color _ : T.color =
let n = Random.int (List.length all_colors) in
List.nth all_colors n in
let last_height = ref 0 in
while true do
let x_size, y_size = T.size () in
(* You can uncomment the next line to not overwrite the current screen.
* But why would you want to? *)
(* T.scroll (y_size - !last_height); *)
last_height := y_size;
if (!x + str_len - 1) >= x_size then (x' := -1; x := x_size - str_len + 1);
if !y >= y_size then (y' := -1; y := y_size);
if !x <= 1 then (x' := 1; x := 1);
if !y <= 1 then (y' := 1; y := 1);
x := !x + !x';
y := !y + !y';
let style = ref [T.Foreground (color ()); T.Background (color ())] in
style := List.rev_append
!style
(List.filter (fun _ -> Random.bool ()) all_styles);
T.set_cursor !x !y;
T.print_string !style s;
flush stdout;
minisleep 0.1;
done
let x = moveit "Happy Birthday Renda";;