Changing, Copying and Moving Shapes ✂️¶
Shapes with names can be changed, copied and moved
Changing a Shape 🎨¶
Once a shape has a name, you can change any of its properties. Write the name, a dot, the property, =, and the new value:
// Default canvas: 800 wide, 600 tall, white
circle ball at 150, 150 having radius 40
ball.fill = "orange"
ball.radius = 70
draw ball
The dot means "the ... of": ball.fill is "the fill of ball".
You can use math and variables too:
// Default canvas: 800 wide, 600 tall, white
number grow = 3
circle bubble at 150, 150 having radius 20, fill "lightblue"
bubble.radius = bubble.radius * grow
draw bubble
Changes after drawing
Your picture shows every shape the way it is at the end of your program. So if you change a shape after you draw it, the picture shows the change:
```veelang
// Default canvas: 800 wide, 600 tall, white draw circle sun at 150, 150 having radius 50, fill "yellow" sun.fill = "orange" ```
Moving a Shape 🚚¶
A shape's position is a property too. Change at to move it somewhere else:
// Default canvas: 800 wide, 600 tall, white
square box at 20, 20 having size 60, fill "teal"
box.at = 200, 150
draw box
Or move it in just one direction with x (across) or y (down):
// Default canvas: 800 wide, 600 tall, white
circle ball at 60, 100 having radius 30, fill "red"
ball.x = 250
draw ball
Copying a Shape 📋¶
To make a copy, make a new shape with = and the name of the shape to copy:
// Default canvas: 800 wide, 600 tall, white
circle first at 80, 100 having radius 40, fill "gold", stroke "orange", thickness 4
circle second = first
second.x = 200
draw first
draw second
second starts out exactly like first: same size, same colors, same place. That's why we move it with second.x, or it would sit right on top of first!
A copy is its own shape. Changing the copy doesn't change the original:
// Default canvas: 800 wide, 600 tall, white
circle original at 80, 100 having radius 40, fill "skyblue"
circle copy = original
copy.x = 200
copy.fill = "pink"
draw original
draw copy
One Shape, One Draw ☝️¶
Each shape can be drawn once. If you try to draw the same shape again, VeeLang tells you:
// Default canvas: 800 wide, 600 tall, white
draw circle c at 100, 100 having radius 30
draw c
That's because drawing a shape again could mean "copy it" or "move it", and VeeLang doesn't want to guess. Say what you mean instead:
- Want two of them? Make a copy (
circle c2 = c) and draw the copy. - Want it somewhere else? Move it (
c.at = 200, 100).
Every shape also needs its own name. Two shapes called c would be confusing, so this is a mistake too:
// Default canvas: 800 wide, 600 tall, white
circle c at 50, 50
circle c at 150, 50
Let's Build a Row of Trees 🌳¶
Make one tree, then copy it and move the copies:
// Default canvas: 800 wide, 600 tall, white
circle tree1 at 60, 120 having radius 40, fill "forestgreen"
circle tree2 = tree1
tree2.x = 170
circle tree3 = tree1
tree3.x = 280
tree3.fill = "olivedrab"
draw tree1
draw tree2
draw tree3
draw rectangle at 0, 160 having width 400, length 40, fill "saddlebrown"
Challenge Time! 🏆¶
- 🌟 Challenge 1: Make one square window, then copy it to make four windows in a row.
- 🌟 Challenge 2: Make a ball, then use
ball.yto move it down so it sits on the ground. - 🌟 Challenge 3: Copy a shape three times, giving each copy a different color.
What's Next? 🚀¶
You can now change shapes with name.property = value, move them with at, x and y, and copy them with =.
Next up: shapes inside shapes, for building bigger things out of smaller ones! 🪆