View.Set ("title:Ron's Grid Thingy,graphics:610;560,nocursor,noecho,offscreenonly") % Set resolution, title and modes of the run window
type balls :
record
x : int % [y] coordinate
y : int % [x] coordinate
size : int % Size of the ball
dist : real % Distance from the mouse
clr : int % The colour of the ball
end record
var ball : array 1 .. 60, 1 .. 55 of balls % Build a two demensional array for a grid of balls
var mX, mY, mB : int % Holds mouse [x,y] coordinates and button status
var oldX, oldY : int := 0 % Holds the old mouse [x,y] coordinates
var invert : boolean := false % Invert colours true or false
var down : boolean := false % Stores whether the mouse button is down or not
% Draw the balls
for decreasing i : 55 .. 1
for j : 1 .. 60
ball (j, i).x := 10 * j % Store [x] coordinate
ball (j, i).y := 10 * i % Store [y] coordinate
ball (j, i).size := 1 % Set default ball size
Draw.FillOval (ball (j, i).x, ball (j, i).y, 2, 2, 2) % Draw the ball
end for
end for
loop
Mouse.Where (mX, mY, mB)
if oldX not= mX and oldY not= mY then % If the mouse has been moved then
Draw.Cls % Clear the screen
if invert = true then % If invert is activated
Draw.FillBox (0, 0, maxx, maxy, 0) % Draw White Background
else
Draw.FillBox (0, 0, maxx, maxy, 7) % Draw Black Background
end if
for decreasing i : 55 .. 1
for j : 1 .. 60
%Draw.FillOval (ball (j, i).x, ball (j, i).y, ball (j, i).size, ball (j, i).size, 7) % Erase the old ball
% Check the distance of the ball from the mouse and set the size of the ball depending on its distance from the mouse
if Math.Distance (ball (j, i).x, ball (j, i).y, mX, mY) > 80 then
ball (j, i).size := 1 % Change Size of ball
if invert = true then % If invert is activated
ball (j, i).clr := 30
else
ball (j, i).clr := 19 % Change colour of ball
end if
elsif Math.Distance (ball (j, i).x, ball (j, i).y, mX, mY) < 80 and Math.Distance (ball (j, i).x, ball (j, i).y, mX, mY) > 60 then
ball (j, i).size := 2 % Change Size of ball
if invert = true then % If invert is activated
ball (j, i).clr := 28 % Change colour of ball
else
ball (j, i).clr := 22 % Change colour of ball
end if
elsif Math.Distance (ball (j, i).x, ball (j, i).y, mX, mY) < 60 and Math.Distance (ball (j, i).x, ball (j, i).y, mX, mY) > 40 then
ball (j, i).size := 3 % Change Size of ball
ball (j, i).clr := 25 % Change colour of ball
elsif Math.Distance (ball (j, i).x, ball (j, i).y, mX, mY) < 40 and Math.Distance (ball (j, i).x, ball (j, i).y, mX, mY) > 20 then
ball (j, i).size := 4 % Change Size of ball
if invert = true then % If invert is activated
ball (j, i).clr := 22 % Change colour of ball
else
ball (j, i).clr := 28 % Change colour of ball
end if
elsif Math.Distance (ball (j, i).x, ball (j, i).y, mX, mY) < 20 and Math.Distance (ball (j, i).x, ball (j, i).y, mX, mY) > 0 then
ball (j, i).size := 5 % Change Size of ball
if invert = true then % If invert is activated
ball (j, i).clr := 19 % Change colour of ball
else
ball (j, i).clr := 30 % Change colour of ball
end if
end if
Draw.FillOval (ball (j, i).x, ball (j, i).y, ball (j, i).size, ball (j, i).size, ball (j, i).clr) % Draw the new ball
end for
end for
View.Update % Update all the balls
end if
if mB = 1 and down = false then % If mouse is pressed and down = false(prevents constant switching)
if invert = false then % If colours aren't inverted then invert them
invert := true % Enable inversion of colours
else % If colours are inverted then restore to original colours
invert := false % Disable inversion of colours
end if
down := true % Set down to true
elsif mB = 0 and down = true then % If mouse is pressed and down = true(prevents constant switching)
down := false % Reset down to false
end if
oldX := mX % Store mouse's [x] coordinate
oldY := mY % Store mouse's [y] coordinate
end loop |