Posts tagged metafont

Summer Project: Meta(font|post) in Racket

:: graphics, hobby, metafont, metapost, tikz

The summer holiday is getting closer. This means there is time to focus on hacking. Last year my summer project was to implement a matrix library and a number theory library.

This year I have decided to write a graphics library inspired by the approach taken by Metafont, Metapost and Tikz. The basic concept in these libraries is a path. The existing Racket library pict on the other hand is based on pictures.

Bezier curves will be used to draw the paths. Drawing a Bezier curve is straight forward; the builtin graphics library, racket/draw has support for this in the form of curve-to.

What is needed is convenient ways of specifying and manipulating paths.

The first problem will be this: Given points P0, P3, P6, ..., Pn. Draw a "pretty" curve through these points. That is, determine which Bezier curves is to be drawn between P0 and P3, between P3 and P6 etc.

John D. Hobby and Donald Knuth introduced the algorithm now known as "Hobby’s Algorithm" in Metafont to solve this problem. It is the central algorithm of the library.

The second problem is to introduce syntax for specifying paths. There is no doubt that the popularity of MetaPost in TeX circles is the concise syntax - so I’ll see how much it makes sense to steal.

The third problem is to support for specifying points based on linear equations. Luckily the grunt works is already done - the matrix library contains equation solvers.

Breaking large project into chunks help tremendously. Just witness how fast the number of completed Racket tasks went up on RosettaCode.

  1. Draw a Bezier curve using racket/draw

  2. Explain Hobby’s algorithm

  3. Implement Hobby’s algorithm

  4. Design syntax for paths

  5. Implement syntax for paths

  6. Document syntax for paths

  7. Predefinitions for standard paths

  8. Examples - inspration from the Metafontbook and Tikz

  9. Linear expressions and "linear variables"

  10. Syntax for linear expressions and linear variables.

  11. From fonts to paths

  12. Higher order path operations

  13. Bounding boxes for paths

  14. Intersections between curves

  15. Coloration of areas

  16. Bitmaps

  17. Relation to picts?