Skip to content

Canvas and Layers

The paper you draw on, and how to stack your drawing in layers.


Canvas

Canvas paper having width 400, length 300, fill "lightyellow"
draw circle at 200, 150 having radius 100, fill "orange"
Syntax Canvas name having width ..., length ..., fill "..."
width how far across the paper goes; 800 if not given
length how far down the paper goes; 600 if not given
fill the paper's color; white if not given
Where the very first line of the program
How many at most one. Without one, you get an 800 by 600 white canvas.
Name any name you like; layers use it to say which canvas they go on

Rules:

  • Like every VeeLang word, Canvas works in any capitals: Canvas, canvas and CANVAS all work.
  • A canvas has no other properties: color or stroke on a canvas is a mistake.
  • You can read and change a canvas's width, length and fill later, at once or over time, like a shape's (see below).
  • Positions on the canvas start at 0, 0 in the top-left corner (see Positions and Parts).
draw circle at 100, 100 having radius 50
Canvas paper having width 400, length 300

Reading and changing the canvas

paper.width, paper.length and paper.fill are the canvas's size and color, so a shape can be placed in the middle whatever size the canvas is. Change them like a shape's properties, at once or in N seconds:

Canvas paper having width 400, length 200, fill "lightblue"
draw circle sun at paper.width / 2, 60 having radius 30, fill "gold"
paper.fill = "navy" in 2 seconds
paper.length = 400 in 1 second
draw text at 20, 300 having content "More room!", size 30, color "white"
Read paper.width, paper.length, paper.fill
Change paper.length = 400, paper.fill = "navy" in 2 seconds
Growing the top-left stays at 0, 0, so a taller canvas has more room at the bottom and a wider one more room on the right. The whole canvas is always shown, so the picture looks smaller as it grows.

A canvas has nothing else to read or change: paper.radius is a mistake.

Learn it step by step: Canvas and Layers


Drawing order

Canvas paper having width 250, length 250
draw square at 50, 50 having size 120, fill "blue"
draw circle at 160, 160 having radius 60, fill "red"
Rule shapes are drawn in the order they're written, like stickers: each new one goes on top
Parts a shape's parts go on top of it, in the order they're written in its { }
Shapes made earlier, drawn later go where their draw line is

Learn it step by step: Canvas and Layers


Layers

Canvas paper having width 400, length 300

Layer sky on paper having {
  rectangle at 0, 0 having width 400, length 200, fill "skyblue"
  circle sun at 320, 60 having radius 30, fill "gold"
}

Layer ground on paper having {
  rectangle at 0, 200 having width 400, length 100, fill "forestgreen"
}

draw circle at sun.center having radius 10, fill "orange"
Syntax Layer name on canvasName having { ... }
Needs a Canvas line, whose name goes after on
Inside { } shapes, without draw, plus repeat and variables (gap = 50). Shapes inside a layer can have parts of their own.
Positions measured from the canvas corner, as usual (not from the layer)
Names a shape in a layer is used by its own name: sun.center, not sky.sun
Layer names each layer needs its own name, different from every shape's

Rules:

  • Layer can be written with a capital or not: Layer and layer both work.
  • draw can't be used inside a layer, and a layer can't go inside another layer.
  • A layer itself can't be changed, moved or turned. The shapes in it can: sun.fill = "orange".

Learn it step by step: Canvas and Layers


Stacking layers: above and below

Canvas paper having width 400, length 300

Layer front on paper having {
  circle at 200, 150 having radius 80, fill "tomato"
}

Layer back on paper having {
  square at 60, 60 having size 180, fill "royalblue"
} below front
No word the layer goes on top of everything written before it
above name or over name the layer goes just above layer name
below name or under name the layer goes just below layer name
Where it goes after the closing }

Rules:

  • name must be a layer written earlier. A shape's name is a mistake (vee.layer.notLayer).
  • Shapes outside layers stack in the order they're written, with each layer where it's written (or where above/below puts it).

Here three layers are written red, blue, green, but over red puts green between red and blue:

Canvas paper having width 300, length 200

Layer red on paper having {
  circle at 100, 100 having radius 50, fill "red"
}
Layer blue on paper having {
  circle at 160, 100 having radius 50, fill "blue"
}
Layer green on paper having {
  circle at 130, 140 having radius 50, fill "green"
} over red

Learn it step by step: Canvas and Layers


Adding a shape to a layer: add

A shape drawn while the program runs (when something is clicked, or in a repeat) lands on top of everything. To put it in a layer instead, add it with add:

Canvas paper
Layer lines on paper
draw circle a at 50, 50 having radius 30, fill "pink"
draw circle b at 150, 50 having radius 30, fill "pink"
draw line l from a.center to b.center having thickness 8, stroke "black"
add l to lines

The line is in the layer lines, which was written before the circles, so it goes under them.

Syntax add shape to layerName or add bunchName to layerName
Where any time, including inside when, repeat and forever
Order the shape goes on top of what the layer already holds; add it again to bring it back to the top

Notes:

  • It is written like adding to a bunch. A name that is a layer puts the shape in the layer.
  • A shape that is in a layer already moves out of it into the new one.
  • A part of another shape (face.nose) can't be moved into a layer.