Colour bars/Display: Difference between revisions

Content added Content deleted
(added ocaml)
Line 122: Line 122:
60 NEXT
60 NEXT
70 CALL &bb06 ' wait for key press</lang>
70 CALL &bb06 ' wait for key press</lang>

=={{header|OCaml}}==

<lang ocaml>open Graphics

let round x =
int_of_float (floor (x +. 0.5))

let () =
open_graph "";
let cols = size_x () in
let rows = size_y () in
let colors = [| black; red; green; blue; magenta; cyan; yellow; white |] in
let n = Array.length colors in
let bar_width = (float cols) /. (float n) in
Array.iteri (fun i color ->
let x1 = bar_width *. (float i) in
let x2 = bar_width *. (float (succ i)) in
set_color color;
fill_rect (round x1) 0 (round x2) rows;
) colors;
ignore (read_key ());
;;</lang>

execute with:
$ ocaml graphics.cma display_colour_bars.ml


=={{header|Perl}}==
=={{header|Perl}}==