Anonymous user
Image noise: Difference between revisions
a pur ocaml version
(a pur ocaml version) |
|||
Line 303:
ocamlfind opt -linkpkg -package sdl noise_fps_sdl.ml
./a.out
Or in a more idiomatic way, using the modules Graphics and Unix from the standard OCaml library:
<lang ocaml>open Graphics
let white = (rgb 255 255 255)
let black = (rgb 0 0 0)
let t_last = ref (Unix.gettimeofday())
let () =
open_graph "";
let width = 320
and height = 240 in
resize_window width height;
try
while true do
for y = 0 to pred height do
for x = 0 to pred width do
set_color (if Random.bool() then white else black);
plot x y
done;
done;
let t = Unix.gettimeofday() in
Printf.printf "- fps: %f\n" (1.0 /. (t -. !t_last));
t_last := t
done
with _ ->
flush stdout;
close_graph ()</lang>
run this script with:
ocaml unix.cma graphics.cma g.ml
=={{header|PureBasic}}==
|