# distance

distance( shape1, shape2 )

Calculates straight-line distance between the centre of the two shapes.

Arguments

Shape one and shape two.

These shapes will not bite you.

They want to have fun.

Then out of the function

came the distance how vast

of shape two and shape one

It returned really fast!

Now what would you do?

If you had the distance between

shape one and shape two?

Returns

A number which represents the absolute (not a percentage) distance between the centres of the two shapes.

Example

Prints the distance between the centre of two circles that are positioned randomly on the screen:

// Define a circle type that we’ll use to create two circles

define type of circle CircleType

IsVisible = true

end circle

// Create the first circle and move it randomly on the screen

define firstCircle = create CircleType

firstCircle.Colour = #000000

moveShape( firstCircle, random(0%,100%), random(0%,100%) )

// Create the second circle and also move it randomly on the screen

define secondCircle = create CircleType

secondCircle.Colour = #FF0000

moveShape( secondCircle, random(0%,100%), random(0%,100%) )

// Calculate the distance between the centre of the first and second circles

define result = distance(firstCircle, secondCircle)

print(“The distance between the two shapes is: “ + result )

// Let the user see  the circles on the screen

wait for 5sec