Skip to content

Numbers and Variables

The values VeeLang works with (numbers, text and true/false), the maths you can do with numbers, and variables: names that hold a value.

Kind Looks like Used for
number 40, 2.5, -10 sizes, positions, angles, how many times
text "Hello!", "tomato" words to write, colors, fonts
true or false true, false things that are on or off, and checks

Numbers

draw circle at 120, 100 having radius 2.5 * 20, fill "orange"
draw circle at -10, 100 having radius 40, fill "skyblue"
  • A number can be whole (40) or have a dot for "and a bit" (2.5).
  • Write a number on both sides of the dot: 0.5, not .5.
  • A minus sign in front makes a number below zero: -10. A position below zero is off the canvas, to the left or above it.

Learn it step by step: Numbers and Math

Maths

draw rectangle at 20, 20 having width 2 + 3 * 10, length 20, fill "orange"
draw rectangle at 20, 60 having width (2 + 3) * 10, length 20, fill "teal"
draw circle at 200, 100 having radius 90 / 2, fill "pink"
Sign What it does Example Answer
+ add 10 + 5 15
- take away 10 - 5 5
* times 10 * 5 50
/ divide 10 / 4 2.5
% what's left over after dividing 10 % 3 1
  • *, / and % happen before + and -: 2 + 3 * 10 is 32.
  • Brackets ( ) happen first: (2 + 3) * 10 is 50.
  • A minus sign works in front of anything: -size, -(2 + 3), 5 - -3 (which is 8).
  • Dividing by zero is a mistake.
  • Maths works only on numbers. "Hi " + "Sam" is a mistake.

Learn it step by step: Numbers and Math

Rounding

round makes a whole number from a number: 7 sweets shared by 3 friends is 2 each, with 1 left over.

sweets = 7
draw text at 30, 50 having content "Each friend gets " + round down (sweets / 3), size 24
draw text at 30, 100 having content "Boxes of 3 needed: " + round up (sweets / 3), size 24
draw text at 30, 150 having content "About: " + round (sweets / 3), size 24
Words What it does Example Answer
round to the nearest whole number; halves go up round 2.5 3
round down to the whole number below round down 2.9 2
round up to the whole number above round up 2.1 3
  • round rounds only the number straight after it. To round maths, put it in brackets: round down (sweets / 3). Without them, round down sweets / 3 rounds sweets and then divides.
  • A negative number in brackets: round down (-2.5) is -3.
  • round, down and up can still be names of your variables.

Where VeeLang needs a whole number, like how many times to repeat, maths that a computer works out a hair away from one counts as it: repeat 0.7 / 0.1 times repeats 7 times.

Sine and cosine

sin and cos (sine and cosine) turn an angle into a number between -1 and 1. The angle is in degrees, like in turn. They are how you put things round a circle: cos gives how far across, sin how far down.

draw circle tip at 100 + 50 * cos 30, 100 + 50 * sin 30 having radius 6, fill "red"

Write the angle straight after the word. To work something out first, put it in brackets, like sin (a + 30). A variable works too.

sides = 6
repeat sides times with n {
  draw circle at 150 + 80 * cos (360 / sides * n), 150 + 80 * sin (360 / sides * n) having radius 8
}
  • Angle 0 is straight across to the right. The drawing counts down from the top, so bigger angles go clockwise, like turn.
  • The answers are neat: cos 90 is 0, sin 180 is 0 and sin 30 is 0.5.
  • sin and cos take only the number straight after them. sin 30 + 10 is sin 30, plus 10.
  • sin @a.x follows a.x, and is worked out again whenever it changes.
  • sin and cos can still be names of your variables.

Random numbers

random 1 to 6 picks a number, like rolling a dice. It goes anywhere a number goes:

repeat 20 times {
  draw circle at random 20 to 780, random 20 to 580 having radius random 3 to 8, fill "gold"
}
draw text at 30, 50 having content "You rolled " + random 1 to 6, size 30
  • With two whole numbers, it picks a whole number, and both ends can come up: random 1 to 6 gives 1, 2, 3, 4, 5 or 6.
  • If an end has a decimal, it picks any number between them: random 0.5 to 2 might give 1.37.
  • Each end is everything up to to and after it: random 1 to 6 * 10 picks from 1 to 60. Use brackets to work with the number it picks: (random 1 to 6) * 10 gives 10, 20 … 60.
  • A forever or a click picks a new number every time it runs.
  • The numbers stay the same while you change the code, so the picture doesn't jump about. A drawing that moves gets new ones when you press Restart or Play again; for a picture that doesn't move, reload the page.

Numbers from shapes

A named shape's numbers can be used anywhere a number goes: box.width, ball.radius, box.center.x.

draw rectangle box at 40, 40 having width 160, length 60, fill "gold"
draw circle at box.center.x, box.bottomLeft.y + 40 having radius box.length / 2, fill "tomato"
  • A point like box.center can stand in for both numbers of a position: draw circle at box.center.
  • .x is the number across and .y the number down: box.center.x.
  • Shapes lists what you can read from each shape.

Learn it step by step: Numbers and Math

Text

draw text at 30, 80 having content "Hello!", size 40, color "purple"
  • Text goes in double quotes: "Hello!".
  • Text is used for words (content), colors (fill "pink") and fonts (font "cursive").
  • + joins text: "Score: " + score puts the number on the end of the words, and "Hi " + name joins two texts. With two numbers, + still adds.
  • A number can be content on its own: content score shows the number.
  • A number in text has at most two decimals: 10 / 3 shows 3.33.
  • + works from left to right, so "Score: " + 1 + 2 shows Score: 12. To add first, use brackets: "Score: " + (1 + 2) shows Score: 3.
score = 0
draw text label at 30, 60 having content "Score: " + score, size 30
draw circle coin at 200, 150 having radius 30, fill "gold"
when coin is clicked {
  score = score + 1
  label.content = "Score: " + score
}

Learn it step by step: Text

True and false

lit = true
if lit {
  draw circle at 150, 100 having radius 40, fill "gold"
}
  • true and false are values of their own, for things that are on or off.
  • A check is true or false too, so it can be kept: fast = speed > 3. See Choices and Repeating.
  • not turns true into false and back: lit = not lit.
  • They can also be written True and False.

A place

A variable can hold a place, written as two numbers, with or without brackets:

home = (60, 100)
draw circle ball at 200, 40 having radius 20, fill "orange"
when ball is clicked {
  move ball to home in 1 second
}
draw text label at home.x, home.y + 50 having content "home"
  • home = 60, 100 and home = (60, 100) are the same.
  • home.x and home.y are its two numbers.
  • A place can be used wherever a place goes: at home, move ball to home, draw line from home to ball.center.
  • A variable keeps what kind of value it started with, so home can't be given a number afterwards.
  • spot = ball.center keeps where the ball is now. It does not follow the ball when it moves.

Learn it step by step: Remembering Things


Making a variable

size = 40
mood = "happy"
lit = true
draw circle at 100, 100 having radius size, fill "orange"
if lit {
  draw text at 40, 200 having content mood, size 30
}

name = value makes a variable, the first time a name is given a value.

  • The first value decides its kind: a number, text, or true/false. It keeps that kind. After size = 40, size = "big" is a mistake, because size holds a number.
  • The old way still works: number size = 40 and text mood = "happy". There's no word like that for true/false.
  • A name that is already a shape can't hold a value: after draw circle ball ..., ball = 5 is a mistake.
  • A variable that is made but never used gets a warning, with a guess at the name you may have meant. A misspelt name, like sped = speed + 1, makes a new variable, so the warning helps you find it.

Learn it step by step: Remembering Things

Changing a variable

size = 20
draw circle at 100, 150 having radius size, fill "orange"
size = size + 20
draw circle at 250, 150 having radius size, fill "orange"

Give it a new value the same way: size = size + 20.

  • The new value can use the old one: size + 20 is read first, then kept.
  • Each line sees the value the variable has when that line is reached, so the two circles above are different sizes.
  • A loop's counter (like count) can't be changed. See Choices and Repeating.

Learn it step by step: Remembering Things

Where a variable can be used

A variable can go anywhere a value of its kind goes:

Kind Where
number positions, sizes, any number property, maths, repeat size times, checks
text content, colors, font, checks
true or false if, not, and, or, checks
gap = 60
color = "teal"
repeat 4 times {
  draw circle at gap * count, 100 having radius gap / 3, fill color
}
  • A variable must be made above the line that uses it.
  • A variable can be used inside a shape's { } body.
  • A variable made inside a repeat lasts only one time round. See Choices and Repeating.

Words you can't use as names

true, false, not, and and or are VeeLang's own words, so they can't be names of variables or shapes. This goes for them in any capitals too (True, NOT, And).

true = 5

named and called are VeeLang's words for giving a name (circle named sun, circle called sun), so they can't be a name for a shape, a variable, an animation, a bunch or a recipe either.

draw circle named at 10, 10

on is a word for layers (Layer sky on paper), so it can't be a variable's name either. Use a word like lit instead.


Variables in the animation

A variable changed in a click, in an animation, in a forever or together, or in a loop that takes time is read each time a line that uses it runs. So a change made by one click is still there for the next click, and a forever sees what the clicks did.

draw rectangle fan at 150, 140 having width 100, length 20, fill "skyblue"
speed = 0
forever {
  turn fan by 90 * speed in 1 second
}
when fan is clicked {
  speed = speed + 1
}
  • A variable changed in the animation must be made at the top of the program first, like speed = 0 above. Making a new variable in a click is a mistake.
  • A variable made inside a repeat can't be changed in a click: it lasted only one time round.
  • The animation starts with the value each variable has at the end of the picture.
  • A line after the start of the animation (after the first line that takes time) changes a variable when that line runs, in order with the moves around it.

Learn it step by step: Remembering Things