Joystick position: Difference between revisions

m
→‎{{header|OCaml}}: minor updates
m (→‎{{header|OCaml}}: minor updates)
Line 644:
{{libheader|SFML}}
 
Using the SFML with its OCaml bindings [httphttps://github.com/fccm/ocaml-sfml.forge.ocamlcore.org/ ocaml-sfml]:
 
<lang ocaml>let remove x = List.filter (fun y -> y <> x)
let buttons_string b =
String.concat " " (List.map string_of_int b)
 
let position app x y =
let view = SFRenderWindow.getView app in
Line 657:
(hw +. ((x /. 100.0) *. hw),
hh +. ((y /. 100.0) *. hh))
 
let cross =
[| 1.0, 1.0; 10.0, 1.0; 10.0, -1.0; 1.0, -1.0;
1.0, -10.0; -1.0, -10.0; -1.0, -1.0; -10.0, -1.0;
-10.0, 1.0; -1.0, 1.0; -1.0, 10.0; 1.0, 10.0; |]
 
let () =
let app = SFRenderWindow.make (800, 600) "Joystick Position" in
Line 673:
SFText.setString text (buttons_string b);
let x, y = position app x y in
SFShape.setPosition shape (x, y);
SFRenderWindow.clear app SFColor.black;
SFRenderWindow.drawText app text ();
Line 682:
| SFEvent.JoystickButtonPressed (0, button) -> ((x, y), button::b)
| SFEvent.JoystickButtonReleased (0, button) -> ((x, y), remove button b)
| SFEvent.JoystickMoved (0, SFEventSFJoystick.JoystickXX, av) -> ((av, y), b)
| SFEvent.JoystickMoved (0, SFEventSFJoystick.JoystickYY, av) -> ((x, av), b)
| _ -> joyd
in
Line 700:
in
loop ((0.0, 0.0), [])</lang>
 
Run with the command:
$ ocaml -I /tmp/ocaml-sfml/src sfml_system.cma sfml_window.cma sfml_graphics.cma joy.ml
 
=={{header|PicoLisp}}==