rotated & colour literals
Two small conveniences for figures: rotated labels and native colour literals.
rotated <degrees>
A per-string text attribute (binding like ljust — to the string it
follows). Angles are counter-clockwise, pic’s convention; the rotation
pivots on the text’s anchor point.
.PS
margin = 0.12
A: arrow right 2.4 "gradient ascent" rotated 18 above
"y axis" rotated 90 at A.start + (-0.3, 0.55)
arrow from A.start up 1.1 dashed
.PE- Composes with the font attributes:
"note" bold rotated 45. fitand standalone-text bounds cover the rotated extent, so a rotated caption gets a properly sized box.- Like classic pic, labels attached to lines/boxes may overflow the canvas
edge — give the drawing breathing room with
margin. - Math lines (
$…$undertexlabels) ignore it.
aligned — follow the line
aligned (pikchr’s spelling) rotates a label to the host segment’s angle
automatically, so edge labels ride their line. It works on linear objects
(line/arrow/spline) and normalizes the angle to keep the text upright — a
leftward or downward segment reads horizontally, never upside down.
.PS
margin = 0.12
arrow from (0,0) to (2.4,1.3) "gradient ascent" aligned above
arrow from (0,0) to (2.4,-1.1) "descent" aligned below
.PEColour literals: rgb(r,g,b) and 0xRRGGBB
The colour grammar (for outlined, shaded, color, hatchcolor and
gradient) accepts two native literal forms besides names and strings:
.PS
box shaded rgb(27,94,32) "rgb()" bold wid 1
circle outlined 0xb3261e rad 0.35 at last box.e + (0.9,0) "hex" italic
.PErgb(r,g,b)takes full expressions (rgb(v, v/2, 0)), components 0–255; out-of-range values are an error.0xRRGGBBfollows Pikchr’s numeric colours;0x…is a general hexadecimal number literal, usable anywhere a number is.- Why not bare
#1b5e20? In pic,#starts a comment — the quoted formshaded "#1b5e20"has always worked and still does.
A colour can also be held in a variable or computed, so a palette defined
once drives a whole figure (handy for the for-loops that plot the
easing curves):
.PS
accent = 0x2f855a
box outlined accent "variable" wid 1
circle shaded (accent + 0x60) rad 0.35 at last box.e + (0.9,0) "expr" italic
.PE- A bareword that names a variable resolves to its value as a
0xRRGGBBcolour (accent = 0x2f855a; … outlined accent); a bareword that is not a variable stays a literal colour name (outlined crimson), so existing sources are unaffected. - Wrap an expression in parentheses for arithmetic in colour position
(
shaded (accent + 0x60)), just likergb()takes expressions. - A quoted
"0xRRGGBB"string is normalised to#rrggbb(the bare literal already worked; the string form no longer slips through as invalid colour).
Any unknown colour name — a typo ("crimsom"), a malformed hex
("#12g456") — is flagged with an invalid_color warning in the --json
bundle (with a “did you mean” suggestion), instead of silently rendering blank.
The colour is still passed through unchanged, so the warning is advisory and
never blocks rendering. Valid forms — the CSS named
colours, #hex,
rgb()/hsl(), and the dvips/xcolor names the dpic corpus uses (Dandelion,
Goldenrod, …) — stay quiet.