CanvasHandle — raster vector canvas
Diese Seite ist derzeit nur englisch — die JSDoc-Kommentare in der Engine sind englisch verfasst. Eine deutsche Auto-Generierung folgt, sobald die Methoden mit
@apidoc-de-Tags ausgestattet sind. — Zur Übersicht
CanvasHandle is the raster-backed vector drawing surface returned by Engine.createCanvas(). Use it for filled / stroked paths, gradients, and to composite vector artwork into a raster ImageHandle via toImage().
Classes
CanvasHandle
A vector drawing canvas backed by tiny-skia.
Obtain one via Engine.createCanvas(w, h).
Call toImage() to get an ImageHandle you can save or composite.
const cv = Engine.createCanvas(400, 300);
cv.fill(0.2, 0.5, 1, 1)
.drawPath(Engine.createPath().circle(200, 150, 80));
const img = cv.toImage();
img.save("out.png");
Accessors
height
Get Signature
get height(): number;
Returns
number
id
Get Signature
get id(): number;
Returns
number
width
Get Signature
get width(): number;
Returns
number
Constructors
Constructor
new CanvasHandle(
id,
width,
height): CanvasHandle;
Parameters
| Parameter | Type |
|---|---|
id |
number |
width |
number |
height |
number |
Returns
Methods
drawPath()
drawPath(path, stroke?): this;
Draw a PathHandle. stroke=true strokes; default fills. Returns this.
Parameters
| Parameter | Type | Default value |
|---|---|---|
path |
PathHandle |
undefined |
stroke |
boolean |
false |
Returns
this
drawPathStr()
drawPathStr(svgStr, stroke?): this;
Draw an SVG path string. stroke=true strokes; default fills. Returns this.
Parameters
| Parameter | Type | Default value |
|---|---|---|
svgStr |
string |
undefined |
stroke |
boolean |
false |
Returns
this
fill()
fill(color): this;
Set solid fill color. Accepts a Color (Pixel or hex string). Returns this.
Parameters
| Parameter | Type |
|---|---|
color |
Color |
Returns
this
free()
free(): void;
Returns
void
linearGradient()
linearGradient(
p1,
p2,
colors,
stops): this;
Set fill to a linear gradient.
Parameters
| Parameter | Type | Description |
|---|---|---|
p1 |
Px | [number, number] |
Start point. Accepts a Px (px(x, y)) or a [x, y] tuple. |
p2 |
Px | [number, number] |
End point. Same accepted forms as p1. |
colors |
(Color | [number, number, number, number])[] |
Array of stop colors. Each element may be a hex string ("#16213e"), a Pixel, or a raw [r, g, b, a] float-tuple (each ∈ [0..1]). Mix freely. |
stops |
number[] |
Array of positions ∈ [0..1], one per color. |
Returns
this
pen()
pen(color, width): this;
Set stroke color and width. Accepts a Color (Pixel or hex string). Returns this.
Parameters
| Parameter | Type |
|---|---|
color |
Color |
width |
number |
Returns
this
radialGradient()
radialGradient(
center,
r,
colors,
stops): this;
Set fill to a radial gradient.
Parameters
| Parameter | Type | Description |
|---|---|---|
center |
Px | [number, number] |
Center point. Accepts a Px (px(x, y)) or a [x, y] tuple. |
r |
number |
Outer radius in pixels. |
colors |
(Color | [number, number, number, number])[] |
Stop colors — see linearGradient for accepted forms. |
stops |
number[] |
Array of positions ∈ [0..1], one per color. |
Returns
this
restore()
restore(): this;
Restore last saved state. Returns this.
Returns
this
rotate()
rotate(angle): this;
Pre-rotate the transform by angle degrees. Returns this.
Parameters
| Parameter | Type |
|---|---|
angle |
number |
Returns
this
save()
save(): this;
Save current paint/transform state. Returns this.
Returns
this
scale()
scale(sx, sy): this;
Pre-scale the transform. Returns this.
Parameters
| Parameter | Type |
|---|---|
sx |
number |
sy |
number |
Returns
this
toImage()
toImage(): ImageHandle;
Convert this canvas to an ImageHandle. The canvas remains valid.
Returns
translate()
translate(x, y): this;
Pre-translate the transform. Returns this.
Parameters
| Parameter | Type |
|---|---|
x |
number |
y |
number |
Returns
this