Bunches¶
A bunch is many things kept together under one name, so your drawing can count them, pick one of them, go through them all or change them all at once. list means the same as bunch: write whichever you like.
Making a bunch¶
bunch colors = "red", "orange", "gold"
Write bunch, a name, = and the things to keep, with commas between them. A bunch can hold any kind of thing: numbers, words (like colours), true or false, places, keys, shapes, and even other bunches:
Canvas wall having width 400, length 200
bunch colors = "red", "orange", "gold"
bunch sizes = 20, 30, 40
bunch arrows = key leftarrow, key rightarrow
draw circle a at 80, 100 having radius 20
draw circle b at 200, 100 having radius 20
draw circle c at 320, 100 having radius 20
list balls = a, b, c
balls.fill = "pink"
bunch garden on its own makes an empty bunch, to fill later.
Say it like a sentence if you like: bunch named garden and bunch called colors = "red", "gold" are the same as bunch garden and bunch colors = "red", "gold". (list called lights works too.)
bunch called colors = "red", "gold"
bunch named garden
list called lights = "red", "green"
draw circle at 50, 50 having radius 20, fill colors[2]
One bunch holds one kind of thing: all numbers, all words or all shapes, say. bunch mixed = 1, "red" is a mistake. Make two bunches instead.
Which one is it?¶
Two shapes can be compared with is and is not. It is true when they are the same shape, wherever each name came from, even if two other shapes look exactly alike. That finds which place in a bunch a shape has:
draw circle a at 60, 60 having radius 20, fill "gray"
draw circle b at 140, 60 having radius 20, fill "gray"
draw circle c at 220, 60 having radius 20, fill "gray"
bunch row = a, b, c
draw text label at 20, 130 having content "Click a circle", size 20
when any n in row is clicked {
repeat row.count times with i {
if row[i] is n {
label.content = "That was number " + i
}
}
}
row[i] is n is true only for the item that was clicked. Only is and is not work for shapes: a > b is a mistake, and so is comparing a shape with a number or words. To check whether a shape is none, see any and every.
Counting, and picking one¶
| Write | What it gives |
|---|---|
colors.count |
how many things are in it |
item 2 of colors |
the second thing |
colors[2] |
the second thing too: the same as item 2 of colors |
colors.first |
the first thing |
colors.last |
the last thing |
The first thing is item 1, the second is item 2, and so on, just like count in a repeat. So colors[count] picks a different colour each time round:
Canvas wall having width 400, length 200
bunch colors = "red", "orange", "gold", "green"
repeat colors.count times {
draw circle at 80 * count, 100 having radius 30, fill colors[count]
}
Some languages, like Python and JavaScript, call the first thing item 0. VeeLang starts at 1, so colors[0] is a mistake.
To read or change something about one shape in a bunch, put a dot after it: balls[2].x, balls.first.fill = "red". With the words, put brackets round them first: (item 2 of balls).x. To move, turn, grow, show or hide one shape, both ways work: move balls[2] by 10, 0 and move item 2 of balls by 10, 0.
Adding things¶
add "blue" to colors
Puts one more thing at the end of the bunch:
Canvas wall having width 400, length 200
bunch sizes = 10
add 20 to sizes
add 30 to sizes
repeat for each s in sizes {
draw circle at 6 * s, 100 having radius s, fill "skyblue"
}
If the bunch doesn't exist yet, add makes it. A shape can be in as many bunches as you like, and in the same bunch twice: then it counts twice.
Taking things out: remove¶
| Write | What it takes out |
|---|---|
remove balls[2] |
the second thing |
remove item 2 of balls |
the second thing too |
remove b from balls |
b, wherever it is in balls |
remove b |
inside repeat for each b in balls or when any b in balls …: the one it is on |
The things after it move up one place. A shape you take out stays on the drawing: it just isn't in the bunch any more. (To make it go away, hide it too.)
Canvas wall having width 400, length 200
repeat 5 times {
draw circle at 60 * count, 100 having radius 20
} add to balls
repeat for each b in balls {
if b.x > 150 {
remove b
}
}
balls.fill = "skyblue"
The three circles on the right are taken out, so only the two on the left turn blue. remove balls[9] in a bunch of 5 is the same mistake as reading balls[9].
Keeping what a block makes: add to¶
repeat 5 times {
...
} add to balls
Each time round the loop, what it made goes into the bunch:
Canvas field having width 400, length 200
repeat 5 times {
draw circle at 60 * count, 100 having radius 20, fill "skyblue"
} add to balls
balls[3].fill = "tomato"
- If one time round makes one shape, that shape goes in. A shape with its own
{ }, or one drawn from a recipe, is one shape: its parts come with it. - If it makes several shapes, they go in together as one thing holding them. It moves, turns and grows as one piece. Its place (
at) is the top-left corner of the smallest box around all of them. - If it makes nothing, nothing goes in.
A flower made of a big circle and a small one is one thing in the bunch:
Canvas garden having width 400, length 200, fill "lightgreen"
repeat 3 times {
draw circle at 100 * count, 100 having radius 30, fill "pink"
draw circle middle at 100 * count, 100 having radius 10, fill "gold"
} add to flowers
turn flowers[2] by 45
flowers[3].middle.fill = "orange"
move flowers.last by 0, 40
Something made of several shapes has no fill of its own, so flowers.fill = "red" is a mistake. To colour all the petals, put each one in a bunch of its own as you draw it, with add to at the end of the draw:
Canvas garden having width 400, length 200, fill "lightgreen"
bunch petals
repeat 3 times {
draw circle at 100 * count, 100 having radius 30 add to petals
draw circle at 100 * count, 100 having radius 10, fill "gold"
} add to flowers
petals.fill = "violet"
Or make the flower a recipe with a setting for its colour.
add to can go after any block that makes things:
| After | One thing for |
|---|---|
repeat, repeat for each, forever |
each time round |
when … is clicked, when … is pressed, when … touches |
each time it runs |
if … { } otherwise { } |
the branch that ran, if it made something |
together { } |
each line in it |
a layer's { } |
everything in it |
Canvas field having width 400, length 300, fill "lightgreen"
bunch garden
draw rectangle ground at 0, 200 having width 400, length 100, fill "sienna"
when ground is clicked {
draw circle at 40 + 40 * garden.count, 180 having radius 15, fill "pink"
} add to garden
Click the ground to plant a flower. Each one goes into garden.
A bunch made while a loop goes round is part of what that time round made. Here each row holds its own bunch of dots, reached with a dot:
Canvas board having width 400, length 200
repeat 2 times with r {
repeat 3 times with c {
draw circle at 60 * c, 60 * r having radius 15
} add to dots
} add to rows
rows[1].dots[2].fill = "tomato"
rows[2].dots.fill = "skyblue"
Bunches inside a shape¶
bunch, add, add to and remove work inside a shape's { } and inside a recipe too. There, the bunch is one of the shape's parts, and it is reached like a part, with a dot:
Canvas garden having width 400, length 300, fill "lightgreen"
shape flower having tint "pink" {
bunch across = 0, 25, 0, -25
bunch down = -25, 0, 25, 0
repeat 4 times {
circle at across[count], down[count] having radius 14, fill tint
} add to petals
circle middle at 0, 0 having radius 12, fill "gold"
}
draw flower rose at 120, 150 having tint "tomato"
draw flower daisy at 280, 150 having tint "white"
draw text at 20, 30 having content "A rose has " + rose.petals.count + " petals"
A recipe's parts are still changed only through its settings, so rose.petals.fill = "red" is a mistake: give the recipe a setting instead, as tint is here.
Going through a bunch: repeat for each¶
repeat for each f in garden {
...
}
Runs its lines once for each thing in the bunch, in order, with f naming that thing:
Canvas sky having width 400, length 200, fill "midnightblue"
bunch sizes = 5, 10, 15, 20
repeat for each s in sizes {
draw circle at 16 * s, 100 having radius s, fill "gold"
}
f can be any name you like. It can't be given a new value, and it can't be a name you already use.
It goes through the bunch as it is while it goes: something added on the way is gone through too, and taking out the thing it is on doesn't skip the next one. Here each circle adds a bigger one, until they are big enough:
Canvas sky having width 400, length 200, fill "midnightblue"
bunch sizes = 5
repeat for each s in sizes {
if s < 40 {
add s * 2 to sizes
}
draw circle at 4 * s + 40, 100 having radius s, fill "gold"
}
A loop that adds something every time round never ends. If it never waits either, the drawing stops it with a message.
Changing them all at once¶
A change to a bunch is that change to each thing in it, all at the same time:
Canvas field having width 400, length 200
repeat 4 times {
draw square at 80 * count, 50 having size 40, fill "gold"
} add to boxes
turn boxes by 90 in 2 seconds
boxes.fill = "orange" in 1 second
move boxes by 0, 80 in 1 second
Each box turns around its own middle, not around the middle of them all. move, turn, grow, shrink, show, hide, stop and changing a property with = all work on a bunch. With in … seconds, they all change together, and the next line waits for them once.
A change that one of its things can't take is the same mistake as for one of them: move scores by 10, 0 with a bunch of numbers is a mistake, just as moving one number is.
A bunch is not a group: its shapes stay separate shapes. To make one picture out of parts, use a shape with a { } body or a recipe.
Clicking, pressing or touching any of them: when any¶
when any f in garden is clicked {
...
}
Runs when any shape in the bunch is clicked, with f naming the one that was clicked. It works for shapes added to the bunch later too:
Canvas field having width 400, length 300, fill "lightgreen"
bunch garden
draw rectangle ground at 0, 200 having width 400, length 100, fill "sienna"
when ground is clicked {
draw circle at 40 + 40 * garden.count, 180 having radius 15, fill "pink"
} add to garden
when any f in garden is clicked {
grow f by 2 in 1 second
}
Click the ground to plant flowers, then click a flower to make it grow.
when any k in arrows is pressed runs for any key in a bunch of keys. when any … touches works with one shape, or with any on both sides, once for each pair that starts touching:
Canvas field having width 400, length 300, fill "lightgreen"
draw circle ball at 20, 150 having radius 15, fill "tomato"
repeat 5 times {
draw circle at 70 * count, 150 having radius 8, fill "gold"
} add to coins
when any c in coins touches ball {
hide c
}
move ball to 380, 150 in 4 seconds
The bunch has to be made above the when any. when garden is clicked, without any, is a mistake: a bunch can't be clicked itself.
Is any of them touching? any and every¶
if any c in coins is touching ball {
...
} otherwise {
...
}
any c in coins is touching ball is true when at least one coin is touching the ball. When it is, c is the first coin that is (the first in the bunch, in the order they were added), and the lines run once, for that one coin. otherwise runs when no coin is touching. if ball is touching any c in coins means the same, and any can go on both sides: c and d are then the first pair that touch.
Canvas field having width 400, length 200, fill "lightgreen"
draw circle ball at 150, 100 having radius 25, fill "tomato"
repeat 4 times {
draw circle at 70 * count, 100 having radius 10, fill "gold"
} add to coins
if any c in coins is touching ball {
c.fill = "orange"
} otherwise {
ball.fill = "gray"
}
if ball is touching coins, without any, is a mistake that shows you this way. So is any c in coins with nothing after it: say what to check, like is touching ball. (is touching is the only check so far.)
To do something to every coin that is touching, go through them yourself:
Canvas field having width 400, length 200, fill "lightgreen"
draw circle ball at 150, 100 having radius 55, fill "tomato"
repeat 4 times {
draw circle at 70 * count, 100 having radius 10, fill "gold"
} add to coins
repeat for each c in coins {
if c is touching ball {
c.fill = "orange"
}
}
Are all of them touching? every¶
every c in coins is touching ball is true only when all the coins are touching the ball. An empty bunch counts as false: with no coins, no coin is touching. It doesn't give c a name, because it is about all of them, not one:
Canvas field having width 400, length 200, fill "lightgreen"
draw circle ball at 150, 100 having radius 90, fill "tomato"
repeat 3 times {
draw circle at 100 + 25 * count, 100 having radius 10, fill "gold"
} add to coins
if every c in coins is touching ball {
ball.fill = "gold"
} otherwise {
ball.fill = "gray"
}
Waiting for one: repeat until any¶
any and every are true or false, so they can be the check of a repeat until or a repeat while too. With repeat until any, the coin that ended the wait is called c on the lines after the loop:
Canvas field having width 400, length 200, fill "lightgreen"
draw circle ball at 20, 100 having radius 15, fill "tomato"
repeat 4 times {
draw circle at 70 * count + 50, 100 having radius 10, fill "gold"
} add to coins
move ball to 380, 100 in 6 seconds
repeat until any c in coins is touching ball {
wait 0.05 seconds
}
c.fill = "pink"
While the loop is still waiting, c is none: nothing. Check with c is none or c is not none. Using something of none (c.fill, c.x) is a mistake the program tells you about while it runs, so check first:
if c is not none {
c.fill = "pink"
}
c is only given a name when the check is just the any, or the any joined to other checks with and. Under or, under not and under repeat while, any is only true or false and doesn't name anything.
Bunches of animations¶
add to after play animation { … }, or at the end of a draw that takes time, keeps something with two sides: the animation and the shape it made.
Canvas garden having width 400, length 300, fill "lightblue"
bunch growing
draw rectangle ground at 0, 250 having width 400, length 50, fill "green"
when ground is clicked {
play animation {
draw circle flower at 50 * growing.count, 230 having radius 10, fill "pink"
grow flower by 3 in 4 seconds
} add to growing
}
when any g in growing is clicked {
stop g
}
Click the ground to grow a flower, and click a flower to stop it growing. The animation goes into the bunch as soon as it starts, so growing.count already counts it while it draws its flower. Each statement picks the side it needs:
stop growing[2]andif growing[2] is playinguse the animation.hide,move,turn,grow, changing a property andwhen any … is clickeduse the shape.growing[2].shapeandgrowing[2].animationname a side outright.
A side that's empty (hiding what an animation that made nothing kept) is a mistake that says so.
A bunch of bunches¶
A bunch can hold other bunches, like the rows of a grid. grid[2][3] is the third thing in the second row:
Canvas board having width 400, length 300
bunch grid
repeat 3 times with r {
repeat 4 times {
draw square at 70 * count, 70 * r having size 50, fill "white"
} add to row
add row to grid
}
grid[2].fill = "skyblue"
grid[3][4].fill = "tomato"
A change to grid changes every square in every row.
Following one of them: @¶
@ follows a property of a shape. It can follow a shape from a bunch too, so a line can join two shapes that were picked while the drawing runs:
draw circle a at 60, 60 having radius 14, draggable true
draw circle b at 240, 120 having radius 14, draggable true
bunch nodes = a, b
bunch picked
when any n in nodes is clicked {
add n to picked
if picked.count == 2 {
draw line from @picked[1].center to @picked[2].center having endhead "arrow", thickness 2
remove item 1 of picked
remove item 1 of picked
}
}
Click a, then b, and an arrow joins them. Drag either circle and the arrow follows. Emptying picked afterwards lets the next two clicks make another arrow. @picked.first.center, @picked.last.center and @(item 2 of picked).center all work.
The line follows the shapes that were picked[1] and picked[2] when the line was drawn. If the bunch changes afterwards, the line keeps following the same two shapes.
Where a bunch lives¶
A bunch is a name like any other. Made at the top of the drawing, everything after it can use it, and it keeps growing with each click. Made inside a repeat or a when (with add or add to and a new name), it's a new bunch each time round, and it's gone afterwards, like any name made there. That is how row above starts empty for each row.
To keep one bunch for every time round, make it first, at the top: bunch garden.
Things in a bunch are the things themselves¶
A shape in a bunch is the shape itself, not a copy. Changing balls[2] changes that ball, and so does changing the ball by its own name. A hidden shape stays in its bunches.
Mistakes¶
| Mistake | Why |
|---|---|
colors[0] |
the first thing is item 1 |
colors[9] or remove colors[9] in a bunch of 4 |
there is no item 9 |
bunch b = 1, "red" |
one bunch holds one kind of thing |
garden.first in an empty bunch |
there's nothing in it yet |
flowers.fill = "red" when each flower is several shapes |
something made of several shapes has no fill of its own |
when garden is clicked |
write when any f in garden is clicked |
if ball is touching coins |
write if any c in coins is touching ball |
if any c in coins |
say what to check: if any c in coins is touching ball |
c.fill while c is none |
check if c is not none first |
balls.radius |
a bunch has a count, a first and a last; pick one ball first: balls.first.radius |
remove 3 |
say which bunch: remove 3 from sizes |