Book contents
- Frontmatter
- Contents
- Preface
- Introduction
- I Basic Principles
- II Applications
- 5 Formal Terms, Pattern Matching, Unification
- 6 Balanced Trees
- 7 Graphs and Problem Solving
- 8 Syntactic Analysis
- 9 Geometry and Drawings
- 10 Exact Arithmetic
- III Implementation
- Quick Reference to the Syntax of Caml Light
- How to Get Caml, MLgraph, and the Examples
- References
- Index
- Index of Types and Functions
9 - Geometry and Drawings
Published online by Cambridge University Press: 05 June 2012
- Frontmatter
- Contents
- Preface
- Introduction
- I Basic Principles
- II Applications
- 5 Formal Terms, Pattern Matching, Unification
- 6 Balanced Trees
- 7 Graphs and Problem Solving
- 8 Syntactic Analysis
- 9 Geometry and Drawings
- 10 Exact Arithmetic
- III Implementation
- Quick Reference to the Syntax of Caml Light
- How to Get Caml, MLgraph, and the Examples
- References
- Index
- Index of Types and Functions
Summary
This chapter is devoted to functionally programming geometric drawings. We use types and graphic functions from the library MLgraph, and we briefly describe them before we use them.
The graphic approach of MLgraph is the same as PostScript, a language used particularly for programming laser printers. This approach is oriented toward programming drawings meant to illustrate documents, rather than toward the display of drawings on screen, though there is software to display PostScript drawings as well. Such software provides a reasonable approximation of the drawings, but the quality is limited by the actual screen resolution.
PostScript is an imperative language, indeed, a low-level imperative language, which was not meant to be used directly but rather to be generated by software to produce drawings or to type-set text. The approach we present here uses the graphic model of PostScript, but replaces that language by Caml. This enables us to provide much higher level construction functions for drawing.
The graphic model of PostScript freely uses an infinite Cartesian plane with no limit on the coordinates. The basic objects are initially sketched on this plane in absolute coordinates, but a user can then freely apply transformations to modify their size and position. Such transformations rapidly get out of the constraints about positioning and let us construct complicated drawings by functionally combining simpler ones.
At first glance, producing drawings by programming seems less pleasant than using software to draw interactively, especially if we want to produce a particular design rapidly.
- Type
- Chapter
- Information
- The Functional Approach to Programming , pp. 281 - 336Publisher: Cambridge University PressPrint publication year: 1998