AGG (Anti-Grain Geometry) extension for Rebol3 (version 3.14.1 and higher)
(This is still work in progress!)
agg: import agg img: agg/draw 600x600 [pen red line-width 5 triangle 0x0 600x600 300x600] save %temp.png img
Draws scalable vector graphics to an image
image[image! pair!]commands[block!]
The AGG Draw dialect provides comprehensive 2D vector graphics capabilities through Rebol's block-based syntax. Each command configures state or immediately renders geometry with flexible coordinate input.
Sets fill color or toggles filling for subsequent path rendering. Supports solid colors and linear gradients.
Parameters:
| Type | Description |
|---|---|
tuple! |
RGBA color value (e.g. 255.0.0.128) |
logic! |
true=enabled, false=disabled |
linear |
Linear gradient: tuple! number! (color, position) |
Example:
fill 255.128.0.255 ; Semi-transparent orange fill fill false ; Disable filling
Sets stroke color or toggles stroking for path outlines.
Parameters:
| Type | Description |
|---|---|
tuple! |
RGBA stroke color |
logic! |
true=enabled, false=disabled |
Example:
pen 0.0.255.255 ; Blue stroke pen false ; No outline
Sets stroke thickness for subsequent paths.
Parameters:
| Type | Description |
|---|---|
number! |
Line thickness in pixels/world units |
Example:
line-width 3.0Controls corner join style between path segments.
Parameters:
| Mode | Description |
|---|---|
'miter |
Sharp corners (extends until limit) |
'bevel |
Cut-off corners |
'round |
Circular corners |
'miter-round |
Miter with rounded truncation |
'miter-revert |
Miter with bevel fallback |
Defines appearance of path endpoints.
Parameters:
| Style | Description |
|---|---|
'butt |
Flat end perpendicular to direction |
'square |
Square extension beyond endpoint |
'round |
Circular semicircle cap |
'round-in |
Inner circular cap |
'triangle |
Outward-pointing triangle |
'triangle-in |
Inward-pointing triangle |
integer! |
Raw cap enum value |
Global transparency multiplier for all operations.
Parameters:
| Type | Description |
|---|---|
number! |
0.0=transparent, 1.0=opaque |
Controls anti-aliasing and gamma correction.
Parameters:
| Type | Description |
|---|---|
number! |
Gamma value (0.5-4.0 typical) |
logic! |
true=normal (1.0), false=off |
none! |
Disable anti-aliasing |
Size for subsequent point drawing commands.
Parameters:
| Type | Description |
|---|---|
number! |
Point radius |
pair! |
Diameter/extent (non-uniform) |
Sets Porter-Duff/SVG compositing mode.
Modes: 'clear, 'source-copy, 'source-over, 'destination-over, 'source-in, 'destination-in, 'source-out, 'destination-out, 'source-atop, 'destination-atop, 'xor, 'add, 'multiply, 'screen, 'overlay, 'darken, 'lighten, 'color-dodge, 'color-burn, 'hard-light, 'soft-light, 'difference, 'exclusion
Draws open polyline (stroke only) from point sequence.
Parameters (coords):
| Type | Description |
|---|---|
pair! + |
Sequential pairs (first=moveTo, rest=lineTo) |
vector! |
X/Y coordinates (2 values per point) |
block! |
Block of pair coordinates |
Example:
line 10x10 50x20 80x40 120x10
Renders closed polygon from vertices.
Parameters (coords):
| Type | Description |
|---|---|
pair! 3+ |
3+ individual pairs |
vector! |
X/Y coordinates (2 per point) |
block! |
Block of pairs |
Renders one or more triangles from vertex triplets.
Parameters (coords):
| Type | Description |
|---|---|
pair! 3+ |
Sequential triplets per triangle |
vector! |
Flattened: x1 y1 x2 y2 x3 y3... |
block! |
Block of 3-pair triplets |
Draws points using current point-size.
Parameters (coords):
| Type | Description |
|---|---|
pair! + |
Individual coordinates |
vector! |
X/Y pairs |
block! |
Block of pairs |
Draws rectangle (optionally rounded).
Parameters:
| Param | Type | Description |
|---|---|---|
top-left |
pair! |
Top-left corner |
bottom-right/size |
pair! |
Opposite corner/size |
radius-x |
number! |
Horizontal radius (opt) |
radius-y |
number! |
Vertical radius (opt) |
Draws ellipse/circle by center and radii.
Parameters:
| Param | Type | Description |
|---|---|---|
center |
pair! |
Ellipse center |
radius-x |
number! |
Horizontal radius |
radius-y |
number! |
Vertical radius (opt) |
Ellipse from bounding rectangle.
Parameters:
| Param | Type | Description |
|---|---|---|
top-left |
pair! |
Bounding box corner |
size |
pair! |
Width/height |
Elliptical arc with closure options.
Parameters:
| Param | Type | Description |
|---|---|---|
center |
pair! |
Ellipse center |
radius |
pair! |
X/Y radii |
begin |
number! |
Start angle (degrees) |
sweep |
number! |
Sweep angle (degrees) |
type |
'open/'pie/'chord |
Closure style (opt) |
Cubic Bézier spline segments.
Parameters:
| Param | Type | Description |
|---|---|---|
start |
pair! |
Initial position (moveTo) |
segments |
pair! 3+ |
control1 control2 end (per segment) |
Example:
cubic 10x10 30x50 70x50 90x10
Shifts coordinate origin.
Parameters: offset pair! (dx, dy)
Scales coordinate system.
Parameters: number! (uniform) or pair! (sx, sy)
Applies shear transformation.
Parameters: angles pair!/number!, optional pivot pair!
Rotates around center.
Parameters: angle number! (degrees), optional center pair!
Compound affine transform.
Parameters: center pair! (opt), then rotate/scale-x/scale-y/translate
Full 2D affine matrix.
Parameters: vector!/block! (6 values: sx shy shx sy tx ty)
Returns identity transform.
Rectangular clipping region.
Parameters: top-left pair!, bottom-right pair!
Clears entire surface to transparent black.
Clears clip region (optional fill color).
Parameters: tuple! color or unset! (transparent)
State isolation context.
Parameters: block! of drawing commands
Example:
push [pen red line 10x10 100x100] ; Original pen restored
Loads font resource.
Parameters: file! path or string! name
Renders text string.
Parameters:
| Param | Type | Description |
|---|---|---|
position |
pair! |
Baseline position |
height |
number! |
Font height (opt) |
content |
string! |
Text to render |
Renders complex path from sub-dialect.
Parameters: path-data block! with path commands (move, line, arc, curve, close, etc.)
Blits image with optional scaling.
Parameters:
| Param | Type | Description |
|---|---|---|
img |
image! |
Source image |
position |
pair! |
Destination top-left |
scale |
pair!/percent! |
Size or scale factor (opt) |
The AGG Path DSL defines a sub-dialect for constructing complex vector paths within the shape command of the draw dialect. Paths are built sequentially from a current "pen" position, supporting absolute and relative coordinates for maximum flexibility.
Paths support filling, stroking, or both based on the outer draw state's fill/pen settings. Multiple subpaths can be defined before closing.
Moves the path pen to an absolute position (starts new subpath).
Parameters:
| Type | Description |
|---|---|
position |
pair! XY coordinates |
Example:
shape [move 10x10 ...]Moves pen by relative offset (starts new subpath).
Parameters:
| Type | Description |
|---|---|
offset |
pair! Delta (dx, dy) |
Adds one or more absolute line segments from current position.
Parameters:
| Type | Description |
|---|---|
points |
pair! + Absolute endpoint coordinates (batched) |
Example:
shape [move 0x0 line 50x0 50x50 0x50]
Adds relative line segments.
Parameters:
| Type | Description |
|---|---|
deltas |
pair! + Relative deltas from current position |
Horizontal line to absolute X (Y unchanged).
Parameters: x number!
Horizontal relative delta X.
Parameters: dx number!
Vertical line to absolute Y (X unchanged).
Parameters: y number!
Vertical relative delta Y.
Parameters: dy number!
Adds elliptical arc (SVG-style parameters).
Parameters:
| Param | Type | Description |
|---|---|---|
end-point |
pair! |
Arc endpoint coordinates |
rx |
number! |
X-axis radius |
ry |
number! |
Y-axis radius |
rotation |
number! |
Ellipse rotation (degrees) |
sweep |
logic! |
true=positive sweep direction |
large |
logic! |
true=large-arc (>180°) |
Relative endpoint version.
Parameters:
| Param | Type | Description |
|---|---|---|
end-delta |
pair! |
Relative endpoint delta |
Absolute cubic Bézier (C1, C2, end).
Parameters:
| Param | Type | Description |
|---|---|---|
control1 |
pair! |
First control point |
control2 |
pair! |
Second control point |
end-point |
pair! |
Endpoint coordinates |
Example:
shape [move 10x10 curve 30x50 70x50 90x10]
All-relative cubic Bézier.
Parameters: Relative control1, control2, end-delta pair!
Smooth cubic (first control relative/reflected).
Parameters: control1 pair! (relative), end-point pair!
Fully relative smooth cubic.
Parameters: control1 pair! (relative), end-delta pair!
Absolute quadratic Bézier (single control).
Parameters:
| Param | Type | Description |
|---|---|---|
control |
pair! |
Control point |
end-point |
pair! |
Endpoint |
Relative quadratic.
Parameters: Relative control, end-delta pair!
Smooth quadratic (reflected control).
Parameters: control pair! (relative/reflected)
Relative smooth quadratic.
Parameters: end-delta pair!
Closes current subpath to its starting point with a straight line.
Parameters: None
Example (Closed Rectangle with Curve):
shape [ move 10x10 line 90x10 90x50 10x50 curv 30x30 50x70 close ]
Usage in Draw: Paths are consumed by shape in the main draw dialect, inheriting fill/pen state. All commands support batching multiple segments for efficiency.