module Graphics: sig end
exception Graphic_failure of string
Initializations
|
val open_graph : string -> unit
val close_graph : unit -> unit
val set_window_title : string -> unit
val clear_graph : unit -> unit
val size_x : unit -> int
Graphics.size_y
を見て下さい。val size_y : unit -> int
0 .. size_x()-1
と 0 .. size_y()-1
になります。この画面外に対する描画は (例外など発生させず) クリッピングされます。画面左下が原点 (0,0) です。
Colors
|
type color = int
0..255
の範囲をとります。3 つの値は int
: 0xRRGGBB
となります。RR
は赤の値を 2 桁の 16 数、GG
は緑、BB
は青を表します。val rgb : int -> int -> int -> color
rgb r g b
は、赤 r
、緑 g
、青 b
の値から、その色を表す数を返します。r
、g
、b
は 0..255
の範囲です。val set_color : color -> unit
val background : color
Graphics.foreground
を見て下さい。val foreground : color
Graphics.clear_graph
では画面を background
で塗りつぶし、カレントカラーを foreground
に設定します。
Some predefined colors
|
val black : color
val white : color
val red : color
val green : color
val blue : color
val yellow : color
val cyan : color
val magenta : color
Point and line drawing
|
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
は、カレントポイントを横に dx 、縦に dy 移動した点に移動します。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
はカレントポイントから d
まで三次元ベジエ曲線を描きます。b
と c
をコントロールポイントとし、カレントポイントは d
へ移されます。val draw_rect : int -> int -> int -> int -> unit
draw_rect x y w h
は、左下角を x,y
にとり横幅 w
、縦幅 h
である四角形を描きます。カレントポイントは移動しません。val draw_poly_line : (int * int) array -> unit
draw_poly_line points
は与えられた点の配列を順につないで線を描きます。配列の要素は多角形の頂点の座標で、この多角形は閉じている必要はありません。カレントポイントは変更されません。val draw_poly : (int * int) array -> unit
draw_poly polygon
は与えられた多角形を描きます。配列の要素は多角形の頂点の座標です。カレントポイントは変更されません。val draw_segments : (int * int * int * int) array -> unit
draw_segments segments
は与えられた線の配列を取り、すべての線を描画します。線は (x0, y0, x1, y1)
という 4 要素からなり、(x0, y0)
と (x1, y1)
が点の端点の座標です。カレントポイントは変更されません。val draw_arc : int -> int -> int -> int -> int -> int -> unit
draw_arc x y rx ry a1 a2
は楕円の弧を描きます。中心は x,y
で、水平軸が rx
、垂直軸が ry
、開始角度 a1
、終了角度 a2
となります (角度の単位は度) 。カレントポイントは変更されません。val draw_ellipse : int -> int -> int -> int -> unit
draw_ellipse x y rx ry
は楕円を描きます。中心が x,y
で、水平軸が rx
、垂直軸が ry
となります。カレントポイントは変更されません。val draw_circle : int -> int -> int -> unit
draw_circle x y r
は円を描きます。中心が x,y
、半径が r
となります。カレントポイントは変更されません。val set_line_width : int -> unit
set_line_width 0
を指定することで特別なアルゴリズムを使用し幅 1 ピクセルの線を高速に描けますが、このアルゴリズムは set_line_width 1
を指定したときに使用されるアルゴリズムより不正確です。
Text drawing
|
val draw_char : char -> unit
Graphics.draw_string
を見て下さい。val draw_string : string -> unit
val set_font : string -> unit
set_font
の引数の解釈は実装依存です。val set_text_size : int -> unit
set_text_size
の引数の解釈は実装依存です。val text_size : string -> int * int
Filling
|
val fill_rect : int -> int -> int -> int -> unit
fill_rect x y w h
は左下角に x,y
をとり、横幅 w
、縦幅 h
である四角形をカレントカラーで塗りつぶして描画します。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
と同じです。
Images
|
type image
val transp : color
val make_image : color array array -> image
Graphic_failure
が発生します。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
は横幅 w
ピクセル、縦幅 h
ピクセルの新しいイメージを作成します。blit_image
とあわせて使用します。初期イメージはランダムです (ただし透過色を含まないことは保証されます) 。val blit_image : image -> int -> int -> unit
blit_image img x y
は画面の指定された四角形内のピクセルをイメージ img
へコピーします (img
を書き換えます) 。四角形は左下角に x,y
をとり、横幅と縦幅はイメージのサイズと同じです。img
のなかで透過色の点は変更されず透過色のままです。
Mouse and keyboard events
|
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
を含む場合、関数はただちに現在の状態を返します。マウスカーソルがグラフィックウィンドウの外にある場合、mouse_x
と mouse_y
フィールドは 0..size_x()-1, 0..size_y()-1
の範囲外になります。キー押下はキューされ、Key_pressed
が指定されるたびに 1 つずつ返します。
Mouse and keyboard polling
|
val mouse_pos : unit -> int * int
mouse_pos()
は 0..size_x()-1, 0..size_y()-1
の範囲外の点を返します。val button_down : unit -> bool
true
を、そうでない場合 false
を返します。val read_key : unit -> char
val key_pressed : unit -> bool
true
を返します。つまりこれが true
を返せば read_key
はブロックしません。
Sound
|
val sound : int -> int -> unit
sound freq dur
は周波数 freq
ヘルツの音を dur
ミリ秒間鳴らします。
Double buffering
|
val auto_synchronize : bool -> unit
アニメーション中のちらつきを押さえるために、画面への描画を無効にし backing store のみに描画を行い、画面への再描画を明示的に行うことが出来ます。
auto_synchronize false
とすると画面への描画を無効にします。この後の描画命令はすべて backing store のみに行われます。
auto_synchronize true
とすると (synchronize
を行うように) backing store の内容を画面へ再描画し、画面への描画を有効にします。この後の描画命令はすべて画面と backing store の両方に行われます。
デフォルトの描画モードは auto_synchronize true
になっています。
val synchronize : unit -> unit
val display_mode : bool -> unit
Graphics.remember_mode
を見て下さい) 。デフォルトでディスプレイモードはオンです。val remember_mode : bool -> unit
Graphics.display_mode
を見て下さい) 。デフォルトでリメンバーモードはオンです。