Assorted

These examples are meant to demonstrate the type of output you can expect to create with protograf. They are not meant to be exhaustive or comprehensive!

Bear in mind that the images shown in these examples are lower-resolution screenshots; the original PDFs that can be generated from the source scripts will demonstrate full scalability.

A Clock

Title

A Wall Clock

Script

clock.py

Discussion

This example shows how to create a complex element - a clock - by combining multiple Circles, each with different properties.

Only the first circle — the clock’s outline border and its title — has a fill color set but the rest do not:

Circle(
    cx=3, cy=4.5, radius=2.5,
    stroke_width=6,
    label="PROTO", label_size=6, label_my=1)

The other circles - which each have a fill color of None so as to be transparent - make use of the radii property to draw some aspect of the clock, for example the hour marks:

Circle(
   cx=3, cy=4.5, radius=2.3,
   stroke="white", fill=None,
   radii=steps(0, 360, 30),
   radii_stroke_width=1.5,
   radii_length=0.3,
   radii_offset=2.2)

Here the setting of various radii_ properties allows the marks to be generated.

Of interest is the use of the steps() function to create the list of angles needed to specify where the offset radii used for the hours are to be drawn.

Screenshot

../_images/clock.png

Miscellaneous Things 1

Title

Miscellaneous Things #1

Script

objects.py

Discussion

The first page of this set of examples shows how to construct various “compound” shapes by making use of special properties of different shapes.

Screenshot

../_images/objects_1.png

Miscellaneous Things 2

Title

Miscellaneous Things #2

Script

objects.py

Discussion

The second page of this set of examples shows how to construct various “compound” shapes by making use of special properties of different shapes.

Screenshot

../_images/objects_2.png

Miscellaneous Things 3

Title

Miscellaneous Things #3

Script

objects.py

Discussion

The third page of this set of examples shows how to construct various “compound” shapes by making use of special properties of different shapes.

Screenshot

../_images/objects_3.png

Chords

Title

Chords (in a circle)

Script

large_objects.py

Discussion

This example shows how to construct a simple effect by combining a basic shape — a Chord — with a Python loop:

for i in range(0, 200):
    Chord(shape=Circle(
            cx=2, cy=2, radius=2, fill=None),
          angle=Random(360),
          angle1=Random(360))

Here the for loop runs for 200 times. Each time it does so, the Random() command generates a random value between 1 and 360 i.e. corresponding to degrees around a circle, to assign to the Chord’s start and end points; then each Chord is drawn as usual.

Also see Python loops for more details.

Screenshot

../_images/chords.png

Compass Rose

Title

Compass Rose (circles and stars)

Script

large_objects.py

Discussion

This example shows how to construct the effects of a compass by overlapping Stars onto Circles

Font("Times-Italic", size=14)
eye = Common(cx=2, cy=3)
Circle(
    common=eye,
    radius=2,
    stroke_width=1,
    fill=None,
    radii=steps(0, 360, 5),
    radii_offset=1.85,
    radii_length=0.1,
    radii_stroke_width=1,
    heading="N")
Circle(
    common=eye,
    radius=1.2,
    stroke_width=1,
    fill=None)
Star(
     common=eye,
     radius=1.4,
     rays=4,
     show_radii=True,
     rotation=45,
     stroke_width=1,
     slices=["black", "white"],
     radii_stroke_width=1,
     inner_fraction=0.25,
)
Star(common=eye,
     radius=2.2,
     rays=4,
     inner_fraction=0.25,
     stroke_width=1,
     slices=["black", "white"],
 )

Screenshot

../_images/compass_rose.png

Rondel

Title

Rondel (circle radii and sectors)

Script

large_objects.py

Discussion

This example shows how to construct a simple effect by using data from a Python loop combined with radii labels:

circ = Common(cx=2, cy=3, radius=2)

# information needed
radii = list(range(0, 360, 60))
colrs = [
    "lightsteelblue", "cyan", "gold",
    "chartreuse", "tomato", "white", ]
labels = [
    'Build', 'Trade', 'Income',
    'Plant', 'Explore', 'Harvest']

# rondel colors
for colr, angle in zip(colrs, radii):
    Sector(
        common=circ,
        fill=colr,
        stroke="sienna", stroke_width=2,
        angle_start=angle - 30,
        angle_width=60)
# rondel text
Circle(
    common=circ,
    stroke="#A0522D",
    stroke_width=3,
    fill=None,
    radii=radii,
    radii_offset=0.75,
    radii_length=1,
    radii_stroke_width=0.01,
    radii_labels=labels,
    radii_labels_font="Times-Roman",
    dot=0.2)

In this example, using the “offset” for the radii allows the label — which is centred on the radius line — to be moved further outward.

Also see Python loops for more details.

Screenshot

../_images/rondel.png

Process Flow Diagram

Title

Process Flow Diagram

Script

processflow.py

Discussion

This example shows how to construct a diagram by drawing a series of Rectangles with Text as part of a Python function. These Rectangles are then connected by Lines via the link property of each line.

Part of the function looks like:

def draw_step(x, y, title, detail):
    box = Rectangle(
        x=x, y=y,
        width=5, height=4,
        stroke_width=1, rounded=True)

It can be seen that the location of the Rectangle will depend on the x and y values supplied to the function when it is used.

The function is used as follows:

step1 = draw_step(
    x=1, y=5,
    title="User Details",
    detail="<li>Fill out form</li><li>Submit form</li>")

Also see Python function for more details on how to construct a function.

The connecting lines are drawn as follows:

Line(links=[
        (step1, "p", "e"),
        (step2, "p", "w")],
     stroke_width=1,
     dot=0.1,
     arrow=True)

For more detail about links, see the customised Line section.

Screenshot

../_images/process_flow_diagram.png

World Clocks

Title

World Clocks

Script

world_clocks.py

Discussion

This example shows how to reuse a complex element — a clock — by means of a set of Python functions; see Python functions for more details.

This is a fairly complex script — a mini program really — which is likely only to be legible to a Python programmer! It’s probably far beyond the scope of this library’s intended use…

The script essentially “wraps” the clock creation approach described above into a function which is accessed for each city, or place, whose clock should be displayed.

The script also uses other functions to calculate the position of the clock hands based on the current time of the day; this is a bit fiddly because the hour hand angle changes in relation to the number of minutes. The clock face and the hand colors are changed depending on the day/night and light/dark cycles.

Further ideas:

  • Wrap a call to this script via a command that gets runs each minute e.g. via cron on Linux; this will produce an updated image of times which could be displayed automatically on screen by a suitable viewer.

  • Add a link to an API that generates quotes; use this quote for the header text so that a new quote appears each time the script is run.

Screenshot

../_images/world_clocks.png