8.13
Diagrama: A diagram drawing library🔗ℹ
Digrama is a library for drawing diagrams on top of pict.
1 Diagrama API Reference🔗ℹ
Warning: The API presented here is unstable, and may change without warning.
Is it a Diagram. Diagrams are computations that
draw, well, diagrams. Diagrams have a state which consists
of a current drawing location, a notion of units, a
line-width, and line-color.
Diagrams are pict-convertible?. When diagrams are
drawn the whole image is shifted such that the minimum x and
y coordinate are shifted to the origin. When diagrams are
converted to pict?s the starting coordinates are
always (0,0).
1.1 Basic diagram constructors🔗ℹ
An empty diagram.
Convert this p into a diagram which just draws p.
The part of p designated by align controls
which part of p is placed at the current location. For
example 'cc centers it.
Draw the given path. The path is interpreted in terms
of the current location and units, and the current location
after drawing the path is the location of the last
point in the paths. The path is not mutated.
The fill-style is the same as the same argument
from draw-path.
Examples:
Creates a diagram which draws a line from the current
location to (x,y). The line moves only
horizontally and vertically. If h-first is
not #f it moves horizontally then vertically, otherwise
it does the reverse.
Example:
Create a diagram which draws a line from the current location
d away in the given direction.
Makes an empty diagram which moves the current drawing
location to (x,y), with
(0,0) being in the upper left.
Example:
Makes an empty diagram which moves the current location
by d in the corresponding direction.
Make an empty diagram that names ta location
name.
If
x and
y given that location is
named, otherwise the current location is names.
This will overwrite any existing locations which have a name
equal?
to
name.
Move to the location with the given name. Errors
if no location has that name.
Draw a line from the current location to the location with
the given
name. Errors if no location has that
name. The line is drawn like
line-to.
Example:
Example:
Create an empty diagram that changes the current
size of the coordinate system to u. The default
is 12.
Examples:
Create an empty diagram that changes
the current line color.
Example:
Create an empty diagram that changes
the current line width.
Add text to the diagram one unit in the given direction.
Example:
Draws a grid over the current diagram with length/width of each
cell of unit length.
Examples:
1.2 Diagram composition🔗ℹ
Draw all of the ds one after another.
Example:
Draw all of the ds one after another, then
draw d1 at with initial state of the diagram.
Examples:
Draw all of
d one after another,
then resort the current units and location
to what they were at the start of the
save.
Like
save except the bounds of the diagram are are
restored after the
ds are draw. This allows for
drawing outside of the bounds of the resulting
pict?.
Draw d1 and d2 with the current
state, and place a black dot at the current location. The
resulting state is the state from d2.
Example:
Draw all of the diagrams in order, with each being drawn
with the initial state. The resulting state is that of the
last diagram.
Example:
Draw all of the diagrams in order, with each being drawn
with the initial state. The resulting state is that of the
first diagram.
Example:
Draw the diagrams in order, with each starting at the
location on the corner of the previous specified by
ud and lr. The first diagram
is drawn at the current location.
(for/after (for-clauses ...) body-or-break ... body)
|
|
(for*/after (for-clauses ...) body-or-break ... body)
|
|
(for/*> (for-clauses ...) body-or-break ... body)
|
|
(for*/*> (for-clauses ...) body-or-break ... body)
|
|
(for/<* (for-clauses ...) body-or-break ... body)
|
|
(for*/<* (for-clauses ...) body-or-break ... body)
|
|
Your friendly neighborhood
for forms, for building
diagrams using
after,
*>, and
<*.
1.3 Reflecting on the drawing state🔗ℹ
There are several ways to directly inspect the current
drawing state. These are all fairly low level operations
that are most likely useful for making new combinators, or when
making pict?’s that scale to the current unit size (for
example unit-grid and start-at are defined
with these).
Build a diagram using the current (x,y) location.
Build a diagram given the current bounding box. See with-state
for the order of arguments to builder.
Build a diagram using the current color.
Build a diagram using the current line width.
Build a diagram given the current units.
Examples:
Build a diagram using the the given named location.
1.4 Circuit Helpers🔗ℹ
diagrama/circuit has helpers for drawing
circuit diagrams. Note that it is easy to accidentally draw
lines on top of gates: before is designed to help
with this.
Make a diagram that draws the given gate, each gate facing
to the right.
or-gate and
and-gate are
three units square, and designed to take in up to three
input wires.
buffer and
register are
roughly the same size, but are designed to take only one
input. If
n1,
n2, or
n3 are not
#f, then the upper, middle, or lower input
(respectively) are negated.
out does the same for
the output. If
tag1,
tag2 or
tag3
a wire is drawn for those inputs, and its endpoint is named
by the given tag.
tag4 does the same for the
output.
The drawn gate is centered at the current location.
Examples: