1<!DOCTYPE html>
2<html>
3<head>
4<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
5<meta name="generator" content="hevea 2.18">
6<link rel="stylesheet" type="text/css" href="manual.css">
7<title>Chapter&#XA0;30&#XA0;&#XA0;The graphics library</title>
8</head>
9<body>
10<a href="libthreads.html"><img src="previous_motif.gif" alt="Previous"></a>
11<a href="index.html"><img src="contents_motif.gif" alt="Up"></a>
12<a href="libdynlink.html"><img src="next_motif.gif" alt="Next"></a>
13<hr>
14<h1 class="chapter" id="sec536">Chapter&#XA0;30&#XA0;&#XA0;The graphics library</h1>
15<p>The <span class="c003">graphics</span> library provides a set of portable drawing primitives.
16Drawing takes place
17in a separate window that is created when <span class="c003">Graphics.open_graph</span> is called.</p><blockquote class="quote"><span class="c007">Unix:</span>&#XA0;&#XA0;
18This library is implemented under the X11 windows system.
19Programs that use the <span class="c003">graphics</span> library must be linked as follows:
20<pre>
21        ocamlc <span class="c009">other options</span> graphics.cma <span class="c009">other files</span>
22</pre>
23For interactive use of the <span class="c003">graphics</span> library, do:
24<pre>
25        ocamlmktop -o mytop graphics.cma
26        ./mytop
27</pre>
28or (if dynamic linking of C libraries is supported on your platform),
29start <span class="c003">ocaml</span> and type <span class="c003">#load "graphics.cma";;</span>.<p>Here are the graphics mode specifications supported by
30<span class="c003">Graphics.open_graph</span> on
31the X11 implementation of this library:
32the argument to <span class="c003">Graphics.open_graph</span> has the format
33<span class="c003">"</span><span class="c009">display-name geometry</span><span class="c003">"</span>,
34where <span class="c009">display-name</span> is the name of the X-windows display to
35connect to, and <span class="c009">geometry</span> is a standard X-windows geometry
36specification. The two components are separated by a space. Either can
37be omitted, or both. Examples:
38</p><dl class="description"><dt class="dt-description">
39<span class="c006">Graphics.open_graph "foo:0"</span></dt><dd class="dd-description">
40connects to the display <span class="c003">foo:0</span> and creates a window with the default geometry
41</dd><dt class="dt-description"><span class="c006">Graphics.open_graph "foo:0 300x100+50-0"</span></dt><dd class="dd-description">
42connects to the display <span class="c003">foo:0</span> and creates a window 300 pixels wide
43by 100 pixels tall, at location (50,0)
44</dd><dt class="dt-description"><span class="c006">Graphics.open_graph " 300x100+50-0"</span></dt><dd class="dd-description">
45connects to the default display and creates a window 300 pixels wide
46by 100 pixels tall, at location (50,0)
47</dd><dt class="dt-description"><span class="c006">Graphics.open_graph ""</span></dt><dd class="dd-description">
48connects to the default display and creates a window with the default
49geometry.
50</dd></dl></blockquote><blockquote class="quote"><span class="c007">Windows:</span>&#XA0;&#XA0;
51This library is available both for standalone compiled programs and
52under the toplevel application <span class="c003">ocamlwin.exe</span>. For the latter, this
53library must be loaded in-core by typing
54<pre>        #load "graphics.cma";;
55</pre></blockquote><p>The screen coordinates are interpreted as shown in the figure below.
56Notice that the coordinate system used is the same as in mathematics:
57<span class="c009">y</span> increases from the bottom of the screen to the top of the screen,
58and angles are measured counterclockwise (in degrees).
59Drawing is clipped to the screen.
60</p><div class="center">
61<img src="libgraph.gif">
62</div><ul class="ftoc2"><li class="li-links">
63<a href="libref/Graphics.html">Module <span class="c003">Graphics</span>: machine-independent graphics primitives</a>
64</li></ul>
65<hr>
66<a href="libthreads.html"><img src="previous_motif.gif" alt="Previous"></a>
67<a href="index.html"><img src="contents_motif.gif" alt="Up"></a>
68<a href="libdynlink.html"><img src="next_motif.gif" alt="Next"></a>
69</body>
70</html>
71