This code snippet bounces a few circles around the screen. All of the information needed for each circle is stored in an array called ‘circ’. Each circle has an x & y position, an x & y direction, radius, colour and transparency (alpha) setting. The main loop then goes through each one, adds the x & y directions to the x & y position. It then checks if it has reached the edge of the screen and if so reverses the x & y direction and carries on. The PROC SETUP statement sets up all the initial variables. |

// Alpha demo with circles

PROC setup

LOOP

CLS2

FOR count = 0 TO maxCircles LOOP

COLOUR = circ(count, 5)

CIRCLE (circ(count, 0), circ(count, 1), circ(count, 4), circ(count, 4))

circ(count, 0) = circ(count, 0) + circ(count, 2)

circ(count, 1) = circ(count, 1) + circ(count, 3)

IF (circ(count, 0) - circ(count, 4)) <= 0 OR (circ(count, 0) + circ(count, 4)) >= gWidth THEN circ(count, 2) = - circ(count, 2)

IF (circ(count, 1) - circ(count, 4)) <= 0 OR (circ(count, 1) + circ(count, 4)) >= gHeight THEN circ(count, 3) = - circ(count, 3)

REPEAT

UPDATE

REPEAT

END

DEF PROC setup

maxCircles = 20

// Create a multi-dimensional array

// remember we start counting from 0

// in this case we create 21 (maxCircles=20) sets

// with seven (0 to 6) variable slots for each one

DIM circ(maxCircles, 6)

// now store the relevant data we need for each circle

FOR count = 0 TO maxCircles LOOP

circ(count, 0) = gWidth / 2 // x is in the middle

circ(count, 1) = gHeight / 2 // y is in the middle

circ(count, 2) = RND (1) * 2 // x direction

circ(count, 3) = RND (1) * 2 // y direction

circ(count, 4) = RND (120) + 40 // random radius

circ(count, 5) = RND (30) + 1 // random colour

circ(count, 6) = RND (255) + 1 // random transparency value

REPEAT

ENDPROC

PROC setup

LOOP

CLS2

FOR count = 0 TO maxCircles LOOP

COLOUR = circ(count, 5)

CIRCLE (circ(count, 0), circ(count, 1), circ(count, 4), circ(count, 4))

circ(count, 0) = circ(count, 0) + circ(count, 2)

circ(count, 1) = circ(count, 1) + circ(count, 3)

IF (circ(count, 0) - circ(count, 4)) <= 0 OR (circ(count, 0) + circ(count, 4)) >= gWidth THEN circ(count, 2) = - circ(count, 2)

IF (circ(count, 1) - circ(count, 4)) <= 0 OR (circ(count, 1) + circ(count, 4)) >= gHeight THEN circ(count, 3) = - circ(count, 3)

REPEAT

UPDATE

REPEAT

END

DEF PROC setup

maxCircles = 20

// Create a multi-dimensional array

// remember we start counting from 0

// in this case we create 21 (maxCircles=20) sets

// with seven (0 to 6) variable slots for each one

DIM circ(maxCircles, 6)

// now store the relevant data we need for each circle

FOR count = 0 TO maxCircles LOOP

circ(count, 0) = gWidth / 2 // x is in the middle

circ(count, 1) = gHeight / 2 // y is in the middle

circ(count, 2) = RND (1) * 2 // x direction

circ(count, 3) = RND (1) * 2 // y direction

circ(count, 4) = RND (120) + 40 // random radius

circ(count, 5) = RND (30) + 1 // random colour

circ(count, 6) = RND (255) + 1 // random transparency value

REPEAT

ENDPROC