PyX — Examples: Basic drawing

In this first section we demonstrate basic drawing features of PyX. The goal is to present some of the basic concepts of the PyX package like canvases, paths and styles.

Overview for this section

path.png

Basic paths

This first path example demonstrates how to create a canvas, how to draw some simple geometric objects onto it and how to write the result into a PostScript or PDF file. more ...

pathitem.png

Constructing paths from pathitems

In this example, some simple paths are constructed out of pathitems, which are the basic building blocks of paths. While we only use moveto, lineto and closepath instances, we can already see some features of paths in PyX. more ...

metapost.png

Creating paths with MetaPost-like parameters

Some simple paths are created by prescribing five points on the path. The curves between them are automatically chosen such that the result looks smooth. more ...

style.png

Stroke and fill attributes

The previous example anticipated a simple case of setting an attribute when stroking paths. This example shows a few more use-cases.

Attributes can be passed in a list as the second optional argument of the stroke or fill methods of a canvas instance. more ...

strokefill.png

Stroke and fill paths at the same time

In order to stroke and fill a path, you could call the fill and stroke methods of a canvas instance one after the other. However, such a solution is not optimal since the path would be written into the output file twice. Instead, you can use the filled decorator within a stroke method call as an additional attribute. more ...

arrow.png

Adding an arrow when stroking a path

The example shows how to use an arrow decorator instance to add an arrow to a path when it is stroked. Instead of using a default arrow instance, we create a highly customized arrow head. more ...