Shapes Made of Parts: a Body or a Recipe? 🧩¶
Two ways to build a shape out of other shapes, and how to choose
VeeLang has two ways to make one shape out of several:
- a shape with a body: an ordinary shape with parts inside its
{ }; - a recipe: a new kind of shape, written once with
shape, that you can draw as often as you like.
They look alike, and both keep their parts together. But they are different things, and they answer some questions differently.
A Shape With a Body ☀️¶
Any shape can have parts. Put them in { } after it:
Canvas paper having width 300, length 200
draw circle sun at 150, 100 having radius 40, fill "gold" {
line from 0, -50 to 0, -75 having thickness 4, color "orange"
line from 0, 50 to 0, 75 having thickness 4, color "orange"
line from -50, 0 to -75, 0 having thickness 4, color "orange"
line from 50, 0 to 75, 0 having thickness 4, color "orange"
}
The sun is a circle. It has its own radius and its own fill, and the rays are extra parts that go everywhere it goes. The rays' numbers are measured from the sun's at, so 0, -50 is just above the sun.
A Recipe 🍪¶
A recipe describes a kind of shape. On its own it draws nothing; each draw makes a new one:
Canvas paper having width 400, length 200
shape face having size 100, skin "gold" {
circle head at 0, 0 having radius size / 2, fill skin
circle at -size / 5, -size / 8 having radius size / 12, fill "black"
circle at size / 5, -size / 8 having radius size / 12, fill "black"
}
draw face at 100, 100
draw face at 280, 100 having size 140, skin "pink"
A face is only its parts. There is no "face" shape underneath them, the way the sun is a circle. What you can change about a face is its settings (size, skin), and changing a setting builds its parts again.
Side by Side ⚖️¶
| Shape with a body | Recipe | |
|---|---|---|
| What it is | one shape, made once | a kind of shape; each draw makes a new one |
| A shape of its own underneath | yes: the sun is a circle | no: a face is only its parts |
| What you can change | its own properties (sun.fill, sun.radius) |
its settings (size, skin) |
| Its parts, from outside | open: you can change them (sun.ray.color = "red") |
sealed: only its settings change it |
| Using the drawing's shapes and numbers | yes (at moon.center) |
no: only its own settings and parts |
| Where the parts' numbers start | the shape's at |
the recipe's 0, 0, which goes where you draw it |
| Making more | copy it: circle sun2 = sun |
draw it again: draw face at ... |
| Where you write it | anywhere, even in a loop | at the top, above where you use it |
Both move, turn and grow as one piece: sun.angle = 45 turns the rays with the sun, and move moves a face and all its parts.
The Same Question, Two Answers: fill 🎨¶
.fill always changes a shape's own fill.
The sun has its own fill, because it's a circle. So sun.fill changes the circle, and the rays keep their colour:
Canvas paper having width 300, length 200
draw circle sun at 150, 100 having radius 40, fill "gold" {
line from 0, -50 to 0, -75 having thickness 4, color "orange"
line from 0, 50 to 0, 75 having thickness 4, color "orange"
}
sun.fill = "red"
A face has no shape of its own underneath, so it has no fill at all:
shape face {
circle head at 0, 0 having radius 50, fill "gold"
}
draw face sam at 100, 100
sam.fill = "pink"
To let people change a face's colour, the recipe gives it a setting, like skin above. Then sam.skin = "pink" works, and the recipe decides which parts change. The eyes stay black.
Open and Sealed 📦¶
A shape with a body is open: you can reach inside and change any part by its full name.
Canvas paper having width 300, length 200
draw circle sun at 150, 100 having radius 40, fill "gold" {
line ray from 0, -50 to 0, -75 having thickness 4, color "orange"
}
sun.ray.color = "red"
A recipe is sealed: what's inside belongs to the recipe. You change a face only through its settings, and a face can only use its own settings and parts, not other shapes in the drawing. Reaching in is a mistake:
shape face having skin "gold" {
circle head at 0, 0 having radius 50, fill skin
}
draw face sam at 100, 100
sam.head.fill = "pink"
That's what makes a recipe easy to share: everything it needs comes in through its settings, and nothing outside can break it.
Which One Should I Use? 🤔¶
- Making one thing, like the sun in this picture? Use a shape with a body.
- Making the same kind of thing many times, maybe a bit different each time? Write a recipe.
- Want other people to change it without knowing how it's built? A recipe with settings: they only need to know the settings.
- Keep changing the same part from outside? That's a sign it wants to be a recipe, with a setting for that part.