1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
// (c) 1999 Sebastian Guenther
{$MODE objfpc}
{$H-}
program GGI1;
uses GGI;
const
WhiteColor: TGGIColor = (r: $ffff; g: $ffff; b: $ffff; a: 0);
StarCount = 500;
Frame: Integer = 0;
type
TStar = record
x, y, z: Integer;
end;
var
Visual: TGGIVisual;
mode: TGGIMode;
ScreenW, ScreenH: Integer;
i, rx, ry: Integer;
angle: Single;
White: TGGIPixel;
Stars: array[1..StarCount] of TStar;
begin
if ggiInit <> 0 then
begin
WriteLn(StdErr, 'Initialization of GGI failed');
Halt(2);
end;
Visual := ggiOpen(nil, []); // Open default visual
if not Assigned(Visual) then
begin
WriteLn(StdErr, 'Could not get default visual');
Halt(3);
end;
ggiSetFlags(Visual, GGIFLAG_ASYNC);
ggiParseMode({'S640x480[GT_8BIT]'}'', mode);
ggiSetMode(Visual, mode);
ggiGetMode(Visual, mode);
ScreenW := mode.Virt.x;
ScreenH := mode.Virt.y;
WriteLn('Screen size: ', ScreenW, ' x ', ScreenH);
White := ggiMapColor(Visual, WhiteColor);
for i := 1 to StarCount do
begin
Stars[i].x := Random(ScreenW) - ScreenW div 2;
Stars[i].y := Random(ScreenH) - ScreenH div 2;
Stars[i].z := Random(99) + 1;
end;
angle := 0.0;
while ggiKbhit(Visual) = 0 do
begin
ggiSetWriteFrame(Visual, Frame);
ggiFillscreen(Visual);
for i := 1 to StarCount do
begin
// the following is not as optimized as it could be...
rx := Trunc(Sin(angle) * Stars[i].x + Cos(angle) * Stars[i].y) * 50 div Stars[i].z + (ScreenW div 2);
ry := Trunc(Cos(angle) * Stars[i].x - Sin(angle) * Stars[i].y) * 50 div Stars[i].z + (ScreenH div 2);
ggiPutPixel(Visual, rx, ry, White);
if Stars[i].z = 1 then
Stars[i].z := Random(99) + 1
else
Dec(Stars[i].z);
end;
angle := angle + 0.01;
ggiFlush(Visual);
Frame := (Frame + 1) mod mode.Frames;
ggiSetDisplayFrame(Visual, Frame);
end;
ggiClose(Visual);
ggiExit;
end.
|