Module Graphics_js

Javascript binding for Graphics lib

include module type of Graphics
exception Graphic_failure of string
val close_graph : unit -> unit
val set_window_title : string -> unit
val resize_window : int -> int -> unit
val clear_graph : unit -> unit
val size_x : unit -> int
val size_y : unit -> int
type color = int
val rgb : int -> int -> int -> color
val set_color : color -> unit
val background : color
val foreground : color
val black : color
val white : color
val red : color
val green : color
val blue : color
val yellow : color
val cyan : color
val magenta : color
val plot : int -> int -> unit
val plots : (int * int) array -> unit
val point_color : int -> int -> color
val moveto : int -> int -> unit
val rmoveto : int -> int -> unit
val current_x : unit -> int
val current_y : unit -> int
val current_point : unit -> int * int
val lineto : int -> int -> unit
val rlineto : int -> int -> unit
val curveto : (int * int) -> (int * int) -> (int * int) -> unit
val draw_rect : int -> int -> int -> int -> unit
val draw_poly_line : (int * int) array -> unit
val draw_poly : (int * int) array -> unit
val draw_segments : (int * int * int * int) array -> unit
val draw_arc : int -> int -> int -> int -> int -> int -> unit
val draw_ellipse : int -> int -> int -> int -> unit
val draw_circle : int -> int -> int -> unit
val set_line_width : int -> unit
val draw_char : char -> unit
val draw_string : string -> unit
val set_font : string -> unit
val set_text_size : int -> unit
val text_size : string -> int * int
val fill_rect : int -> int -> int -> int -> unit
val fill_poly : (int * int) array -> unit
val fill_arc : int -> int -> int -> int -> int -> int -> unit
val fill_ellipse : int -> int -> int -> int -> unit
val fill_circle : int -> int -> int -> unit
type image
val transp : color
val make_image : color array array -> image
val dump_image : image -> color array array
val draw_image : image -> int -> int -> unit
val get_image : int -> int -> int -> int -> image
val create_image : int -> int -> image
val blit_image : image -> int -> int -> unit
type status = {
  1. mouse_x : int;
  2. mouse_y : int;
  3. button : bool;
  4. keypressed : bool;
  5. key : char;
}
type event =
  1. | Button_down
  2. | Button_up
  3. | Key_pressed
  4. | Mouse_motion
  5. | Poll
val wait_next_event : event list -> status
val loop_at_exit : event list -> (status -> unit) -> unit
val key_pressed : unit -> bool
val sound : int -> int -> unit
val auto_synchronize : bool -> unit
val synchronize : unit -> unit
val display_mode : bool -> unit
val remember_mode : bool -> unit

Initializations

type context

type of a graphic context

val open_graph : string -> unit

Open a graphics window. The graphics window is cleared and the current point is set to (0, 0). The string argument is used to pass optional information on the desired graphics mode, the graphics window size, and so on. Specification can be found at http://www.w3schools.com/jsref/met_win_open.asp. Note: an extra specification is available, "target", to specifies the target attribute or the name of the window.

use a canvas to setup the current context

val get_context : unit -> context

Get the current context

val set_context : context -> unit

Set the current context

Mouse and keyboard events

val loop : event list -> (status -> unit) -> unit

Loops forever and listen to the given events. Those events automatically returns a status record, which is used by the function given in argument.

Mouse and keyboard polling

val mouse_pos : unit -> (int * int) Lwt.t

Return the position of the mouse cursor, relative to the graphics window. If the mouse cursor is outside of the graphics window, mouse_pos() returns a point outside of the range 0..size_x()-1, 0..size_y()-1.

val button_down : unit -> bool Lwt.t

Return true if the mouse button is pressed, false otherwise.

val read_key : unit -> char Lwt.t

Wait for a key to be pressed, and return the corresponding character. Keypresses are queued.