Skip to content

Reference

Aravinda VK edited this page Aug 1, 2026 · 10 revisions

Canvas

size    width    height    background newDrawing    newPage   

Export

saveAs   

Units

px    pt    cm    inch    mm    degrees    radians   

Colors

fill    stroke    fillAlpha    strokeAlpha    noFill    noStroke    tint    background   

Primitives

point    line    rect    square    oval    circle    polygon    triangle   

State

saveState    restoreState    savedState   

Drawing

newPath    curveTo    moveTo    lineTo    arcTo    drawPath   

Text

text    textSize    font   

Transform

translate    rotate    scale   

Grid

grid    gridCell    gridArea    nextGridCell    prevGridCell   

Image

image    imageSize    imageWidth    imageHeight    background    tint    noTint   

size

ctx.size(PAPER);
ctx.size(double width);
ctx.size(double width, double height);
Size ctx.size;

Set or get the size of the Paper.

Get the size of the Paper

auto s = ctx.size;
writefln("Width: %s  Height: %s", s.width, s.height);

Example:

auto s = ctx.size;

// Draw a rectangle that fits half of the paper
//       X  Y  W            H
ctx.rect(0, 0, s.width / 2, s.height);

// Draw horizontal line
//       X1   Y1   X2             Y2
ctx.line(100, 100, s.width - 200, 100); 

Set the paper size while initializing the Chitra context. Alternatively, set the size dynamically.

auto ctx = new Chitra; // Default paper size is 700x700
ctx.size(1600, 900);

A4 Paper

auto ctx = new Chitra("a4");
// OR
auto ctx = new Chitra;
ctx.size("a4");

Example (Set the Paper size same as image size)

auto ctx = new Chitra;

auto img = ctx.imageSize("tiger.png");
ctx.size(img.width, img.height);

width

ctx.width;

Returns width of the Paper.

Example:

// Draw a rectangle that fits half of the paper
//       X  Y  W              H
ctx.rect(0, 0, ctx.width / 2, 200);

// Draw horizontal line
//       X1   Y1   X2               Y2
ctx.line(100, 100, ctx.width - 200, 100); 

height

ctx.height;

Returns height of the Paper.

Example:

// Draw a rectangle that fits half of the paper
//       X  Y  W    H
ctx.rect(0, 0, 400, ctx.height / 2);

// Draw vertical line
//       X1   Y1   X2   Y2
ctx.line(100, 100, 100, ctx.height - 200); 

point

ctx.point(x, y);

Draw a point on the Paper. Default width of the point is 1pt. Customize the width and color using strokeWeight and stroke commands.

Drawing a point is same as drawing a zero width line with strokeCap set to ROUND. point(x, y) is same as

ctx.strokeCap(ROUND);
ctx.line(x, y, x, y); // zero width line

Example:

ctx.strokeWeight(10);
ctx.stroke("red");
ctx.point(100, 100);

Red Dot

Clone this wiki locally