module Graphics:Machine-independent graphics primitives.sig
..end
exception Graphic_failure of string
val open_graph : string -> unit
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
Graphics.size_y
.val size_y : unit -> int
0 .. size_x()-1
and 0 .. size_y()-1
.
Drawings outside of this rectangle are clipped, without causing
an error. The origin (0,0) is at the lower left corner.typecolor =
int
0..255
. The three components are packed in
an int
: 0xRRGGBB
, where RR
are the two hexadecimal digits for
the red component, GG
for the green component, BB
for the
blue component.val rgb : int -> int -> int -> color
rgb r g b
returns the integer encoding the color with red
component r
, green component g
, and blue component b
.
r
, g
and b
are in the range 0..255
.val set_color : color -> unit
val background : color
Graphics.foreground
.val foreground : color
Graphics.clear_graph
fills the screen with the background
color.
The initial drawing color is foreground
.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
rmoveto dx dy
translates the current point by the given vector.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
curveto b c d
draws a cubic Bezier curve starting from
the current point to point d
, with control points b
and
c
, and moves the current point to d
.val draw_rect : int -> int -> int -> int -> unit
draw_rect x y w h
draws the rectangle with lower left corner
at x,y
, width w
and height h
.
The current point is unchanged.
Raise Invalid_argument
if w
or h
is negative.val draw_poly_line : (int * int) array -> unit
draw_poly_line points
draws the line that joins the
points given by the array argument.
The array contains the coordinates of the vertices of the
polygonal line, which need not be closed.
The current point is unchanged.val draw_poly : (int * int) array -> unit
draw_poly polygon
draws the given polygon.
The array contains the coordinates of the vertices of the
polygon.
The current point is unchanged.val draw_segments : (int * int * int * int) array -> unit
draw_segments segments
draws the segments given in the array
argument. Each segment is specified as a quadruple
(x0, y0, x1, y1)
where (x0, y0)
and (x1, y1)
are
the coordinates of the end points of the segment.
The current point is unchanged.val draw_arc : int -> int -> int -> int -> int -> int -> unit
draw_arc x y rx ry a1 a2
draws an elliptical arc with center
x,y
, horizontal radius rx
, vertical radius ry
, from angle
a1
to angle a2
(in degrees). The current point is unchanged.
Raise Invalid_argument
if rx
or ry
is negative.val draw_ellipse : int -> int -> int -> int -> unit
draw_ellipse x y rx ry
draws an ellipse with center
x,y
, horizontal radius rx
and vertical radius ry
.
The current point is unchanged.
Raise Invalid_argument
if rx
or ry
is negative.val draw_circle : int -> int -> int -> unit
draw_circle x y r
draws a circle with center x,y
and
radius r
. The current point is unchanged.
Raise Invalid_argument
if r
is negative.val set_line_width : int -> unit
set_line_width 0
selects a width of 1 pixel
and a faster, but less precise drawing algorithm than the one
used when set_line_width 1
is specified.
Raise Invalid_argument
if the argument is negative.val draw_char : char -> unit
Graphics.draw_string
.val draw_string : string -> unit
val set_font : string -> unit
set_font
is implementation-dependent.val set_text_size : int -> unit
set_text_size
is implementation-dependent.val text_size : string -> int * int
val fill_rect : int -> int -> int -> int -> unit
fill_rect x y w h
fills the rectangle with lower left corner
at x,y
, width w
and height h
, with the current color.
Raise Invalid_argument
if w
or h
is negative.val fill_poly : (int * int) array -> unit
val fill_arc : int -> int -> int -> int -> int -> int -> unit
Graphics.draw_arc
.val fill_ellipse : int -> int -> int -> int -> unit
Graphics.draw_ellipse
.val fill_circle : int -> int -> int -> unit
Graphics.draw_circle
.type
image
val transp : color
val make_image : color array array -> image
Graphic_failure
is raised.val dump_image : image -> color array array
val draw_image : image -> int -> int -> unit
val get_image : int -> int -> int -> int -> image
Graphics.fill_rect
.val create_image : int -> int -> image
create_image w h
returns a new image w
pixels wide and h
pixels tall, to be used in conjunction with blit_image
.
The initial image contents are random, except that no point
is transparent.val blit_image : image -> int -> int -> unit
blit_image img x y
copies screen pixels into the image img
,
modifying img
in-place. The pixels copied are those inside the
rectangle with lower left corner at x,y
, and width and height
equal to those of the image. Pixels that were transparent in
img
are left unchanged.type
status = {
|
mouse_x : |
(* | X coordinate of the mouse | *) |
|
mouse_y : |
(* | Y coordinate of the mouse | *) |
|
button : |
(* | true if a mouse button is pressed | *) |
|
keypressed : |
(* | true if a key has been pressed | *) |
|
key : |
(* | the character for the key pressed | *) |
type
event =
| |
Button_down |
(* | A mouse button is pressed | *) |
| |
Button_up |
(* | A mouse button is released | *) |
| |
Key_pressed |
(* | A key is pressed | *) |
| |
Mouse_motion |
(* | The mouse is moved | *) |
| |
Poll |
(* | Don't wait; return immediately | *) |
val wait_next_event : event list -> status
Poll
is given in the event list, return immediately
with the current status. If the mouse cursor is outside of the
graphics window, the mouse_x
and mouse_y
fields of the event are
outside the range 0..size_x()-1, 0..size_y()-1
. Keypresses
are queued, and dequeued one by one when the Key_pressed
event is specified.val mouse_pos : unit -> int * int
mouse_pos()
returns a point outside of the range
0..size_x()-1, 0..size_y()-1
.unit -> bool
: true
if the mouse button is pressed, false
otherwise.val read_key : unit -> char
val key_pressed : unit -> bool
true
if a keypress is available; that is, if read_key
would not block.val sound : int -> int -> unit
sound freq dur
plays a sound at frequency freq
(in hertz)
for a duration dur
(in milliseconds).val auto_synchronize : bool -> unit
To avoid flicker during animations, it is possible to turn off on-screen drawing, perform a number of drawing operations in the backing store only, then refresh the on-screen window explicitly.
auto_synchronize false
turns on-screen drawing off. All
subsequent drawing commands are performed on the backing store
only.
auto_synchronize true
refreshes the on-screen window from
the backing store (as per synchronize
), then turns on-screen
drawing back on. All subsequent drawing commands are performed
both on screen and in the backing store.
The default drawing mode corresponds to auto_synchronize true
.
val synchronize : unit -> unit
val display_mode : bool -> unit
Graphics.remember_mode
below). Default display mode is on.val remember_mode : bool -> unit
Graphics.display_mode
above).
Default remember mode is on.