Let's look again back to our simple graphical application:
program Workspace;
uses FTGraphics;
procedure Initialize;
begin
end;
procedure OnEnterFrame;
begin
FillRect(-14,10,14,-10,clBlue);
FillRect(-14,-7,14,-10,clBrown);
FillEllipse(-11.5-1.5, 7.5-1.5,
-11.5+1.5, 7.5+1.5, clYellow);
SetFont('Arial',clRed,56);
TextOut(0,1.5,'Hello');
TextOut(0,-1.5,'World');
end;
begin
RunGraphicalApp(@Initialize,@OnEnterFrame);
end.
A number of variables are defined in FTGraphics that can modify the behavior of or inspect the properties of the graphical environment. For example, FTGraphics defines the Boolean variable GridVisible to determine if the grid is on or off (without the need to press Ctrl+G). Try setting GridVisible to True inside of Initialize:
procedure Initialize;
begin
GridVisible := True;
end;
Another useful variable is FrameRateVisible which will display the frame rate meter. Try setting this to True. You will notice that on the left-hand side of the screen just above the x-axis is a frame rate meter that should stay near 30fps. Later, when we write more computationally intensive graphical apps (certain special effects for example), the frame rate meter will be useful to judge the performance of our apps.
Another variable, BkColor, will set the background color of the window. Instead of the line FillRect(-14,10,14,-10,clBlue), try replacing it with something like BkColor := clBlue or BkColor := clAqua.
FrameCount is the number of frames that have elapsed since the program started. We can use FrameCount to create our first animation:
Excercise 2-9. Make the sun set by decreasing it's Y coordinate using FrameCount. Keep in mind that the call to FillEllipse is the following so there are two Y coordinates to change.
FillEllipse(Left,Top,Right,Bottom,Color)
Also, FrameCount increases by 1 every 1/30 of a second (assuming the frame rate is 30fps). This means that unless you want the sun to fly off the screen, you should divide FrameCount by some factor to slow the sun down.
Subtracting FrameCount/10 works reasonably well. You will also notice that the sun sets in front of the ground instead of behind it. This is because we drew the ellipse after the rectangle for the ground. To correct this, simply reverse the position of FillEllipse and FillRect.
procedure OnEnterFrame;
begin
BkColor := clAqua;
FillEllipse(-11.5-1.5, 7.5-1.5-FrameCount/10,
-11.5+1.5, 7.5+1.5-FrameCount/10, clYellow);
FillRect(-14,-7,14,-10,clBrown);
SetFont('Arial',clRed,56);
TextOut(0,1.5,'Hello');
TextOut(0,-1.5,'World');
end;