Library
Module
Module type
Parameter
Class
Class type
Machine-independent graphics primitives compatible with Async.
Show the graphics window or switch the screen to graphic mode. 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. Its interpretation is implementation-dependent. If the empty string is given, a sensible default is selected.
Return the size of the graphics window. Coordinates of the screen pixels range over 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.
A color is specified by its R, G, B components. Each component is in the range 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
Set the current drawing color.
val background : color
val foreground : color
Default background and foreground colors (usually, either black foreground on a white background or white foreground on a black background). Async_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 point_color : int -> int -> color
Return the color of the given point in the backing store (see "Double buffering" below).
Draw a line with endpoints the current point and the given point, and move the current point to the given point.
Draw a line with endpoints the current point and the current point translated of the given vector, and move the current point to this point.
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
.
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.
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.
draw_poly polygon
draws the given polygon. The array contains the coordinates of the vertices of the polygon. The current point is unchanged.
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.
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.
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.
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.
Set the width of points and lines drawn with the functions above. Under X Windows, 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.
Draw a character or a character string with lower left corner at current position. After drawing, the current position is set to the lower right corner of the text drawn.
Set the font used for drawing text. The interpretation of the argument to set_font
is implementation-dependent.
Set the character size used for drawing text. The interpretation of the argument to set_text_size
is implementation-dependent.
Return the dimensions of the given text, if it were drawn with the current font and size.
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.
Fill the given polygon with the current color. The array contains the coordinates of the vertices of the polygon.
Fill an elliptical pie slice with the current color. The parameters are the same as for Async_graphics.draw_arc
.
Fill an ellipse with the current color. The parameters are the same as for Async_graphics.draw_ellipse
.
Fill a circle with the current color. The parameters are the same as for Async_graphics.draw_circle
.
The abstract type for images, in internal representation. Externally, images are represented as matrices of colors.
val transp : color
In matrices of colors, this color represent a 'transparent' point: when drawing the corresponding image, all pixels on the screen corresponding to a transparent pixel in the image will not be modified, while other points will be set to the color of the corresponding point in the image. This allows superimposing an image over an existing background.
Convert the given color matrix to an image. Each sub-array represents one horizontal line. All sub-arrays must have the same length; otherwise, exception Graphic_failure
is raised.
val draw_image : image -> int -> int -> unit
Draw the given image with lower left corner at the given point.
val get_image : int -> int -> int -> int -> image
Capture the contents of a rectangle on the screen as an image. The parameters are the same as for Async_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.
val on_click :
?start:unit Async.Deferred.t ->
?stop:unit Async.Deferred.t ->
(status -> unit) ->
unit
on_click ?start ?stop f
runs f
for every mouse click event starting when start
becomes determined and stopping when stop
becomes determined.
It is guaranteed that if stop
becomes determined, even during evaluation of f
, then f
will not be called again for a subsequent mouse click.
val on_mousedown :
?start:unit Async.Deferred.t ->
?stop:unit Async.Deferred.t ->
(status -> unit) ->
unit
on_mousedown ?start ?stop f
runs f
for every mouse down event starting when start
becomes determined and stopping when stop
becomes determined.
It is guaranteed that if stop
becomes determined, even during evaluation of f
, then f
will not be called again for a subsequent mouse click.
val on_mouseup :
?start:unit Async.Deferred.t ->
?stop:unit Async.Deferred.t ->
(status -> unit) ->
unit
on_mouseup ?start ?stop f
runs f
for every mouse up event starting when start
becomes determined and stopping when stop
becomes determined.
It is guaranteed that if stop
becomes determined, even during evaluation of f
, then f
will not be called again for a subsequent mouse click.
val on_mousemove :
?start:unit Async.Deferred.t ->
?stop:unit Async.Deferred.t ->
(status -> unit) ->
unit
on_mousemove ?start ?stop f
runs f
for every mouse move event starting when start
becomes determined and stopping when stop
becomes determined.
It is guaranteed that if stop
becomes determined, even during evaluation of f
, then f
will not be called again for a subsequent mouse click.
val on_keypress :
?start:unit Async.Deferred.t ->
?stop:unit Async.Deferred.t ->
(status -> unit) ->
unit
on_keypress ?start ?stop f
runs f
for every key press event starting when start
becomes determined and stopping when stop
becomes determined.
It is guaranteed that if stop
becomes determined, even during evaluation of f
, then f
will not be called again for a subsequent mouse click.
sound freq dur
plays a sound at frequency freq
(in hertz) for a duration dur
(in milliseconds).
By default, drawing takes place both on the window displayed on screen, and in a memory area (the 'backing store'). The backing store image is used to re-paint the on-screen window when necessary.
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
.
Synchronize the backing store and the on-screen window, by copying the contents of the backing store onto the graphics window.
Set display mode on or off. When turned on, drawings are done in the graphics window; when turned off, drawings do not affect the graphics window. This occurs independently of drawing into the backing store (see the function Async_graphics.remember_mode
below). Default display mode is on.
Set remember mode on or off. When turned on, drawings are done in the backing store; when turned off, the backing store is unaffected by drawings. This occurs independently of drawing onto the graphics window (see the function Async_graphics.display_mode
above). Default remember mode is on.