Chapter 29 The graphics library

The graphics library provides a set of portable drawing primitives.Drawing takes placein a separate window that is created when Graphics.open_graph is called.

Unix:This library is implemented under the X11 windows system.Programs that use the graphics library must be linked as follows:
  1. ocamlc other options graphics.cma other files
For interactive use of the graphics library, do:
  1. ocamlmktop -o mytop graphics.cma ./mytop
or (if dynamic linking of C libraries is supported on your platform),start ocaml and type #load "graphics.cma";;.

Here are the graphics mode specifications supported byGraphics.open_graph onthe X11 implementation of this library:the argument to Graphics.open_graph has the format"display-name geometry",where display-name is the name of the X-windows display toconnect to, and geometry is a standard X-windows geometryspecification. The two components are separated by a space. Either canbe omitted, or both. Examples:

Graphics.open_graph "foo:0"
connects to the display foo:0 and creates a window with the default geometry
Graphics.open_graph "foo:0 300x100+50-0"
connects to the display foo:0 and creates a window 300 pixels wideby 100 pixels tall, at location (50,0)
Graphics.open_graph " 300x100+50-0"
connects to the default display and creates a window 300 pixels wideby 100 pixels tall, at location (50,0)
Graphics.open_graph ""
connects to the default display and creates a window with the defaultgeometry.
Windows:This library is available both for standalone compiled programs andunder the toplevel application ocamlwin.exe. For the latter, thislibrary must be loaded in-core by typing
  1. #load "graphics.cma";;

The screen coordinates are interpreted as shown in the figure below.Notice that the coordinate system used is the same as in mathematics:y increases from the bottom of the screen to the top of the screen,and angles are measured counterclockwise (in degrees).Drawing is clipped to the screen.

Chapter 29  The graphics library - 图1