Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
666 bw 1
 
2
{-$codepage cp866}
3
4
 
5
{$apptype gui}
6
{$r-}
7
8
 
9
10
 
11
  MSG_PRESSKEY = 'Нажми на кнопку...';
12
  MSG_USAGE    = 'Для перемешения и врашения используй стрелки';
13
14
 
15
  HEIGHT = 200;
16
  COLORS = 128;
17
18
 
19
    0,10,20,48,48,48,1,0,43,1,3,43,2,5,44,2,7,44,3,9,45,4,11,46,5,13,47,6,15,48,
20
    7,17,49,8,19,50,9,21,51,10,22,52,11,24,52,12,26,54,13,28,54,14,30,56,15,32,
21
    56,16,34,58,17,34,58,17,36,58,18,38,60,19,40,60,20,42,62,21,44,62,10,31,0,
22
    11,31,0,11,31,1,11,32,1,12,32,1,12,32,2,12,33,2,13,33,2,14,33,3,15,33,3,15,
23
    34,3,15,34,4,15,35,4,16,35,4,16,35,5,16,36,5,17,36,5,17,36,6,18,37,6,18,38,
24
    7,19,38,8,20,39,8,20,40,9,21,40,10,22,41,10,22,42,11,23,42,12,24,43,12,24,
25
    44,13,25,44,14,25,45,14,26,46,15,27,46,16,27,47,17,28,47,18,28,48,19,29,49,
26
    19,30,49,20,30,50,21,31,51,21,32,51,22,32,52,23,33,53,23,34,53,24,34,54,25,
27
    35,55,25,36,55,26,36,56,27,37,57,27,38,57,27,39,57,27,41,57,27,42,57,27,43,
28
    57,27,44,57,27,45,57,27,46,57,27,47,57,27,49,57,27,50,57,27,51,57,27,52,57,
29
    27,53,57,27,55,57,27,56,57,27,57,57,27,58,57,27,58,57,26,58,57,25,58,57,24,
30
    58,56,23,58,55,22,58,54,20,58,53,19,58,51,18,58,50,17,58,50,16,58,49,15,58,
31
    48,14,58,47,13,58,46,12,58,45,11,58,44,11,58,44,10,58,43,10,58,42,9,57,41,
32
    8,57,40,8,56,39,7,56,38,6,55,37,5,55,35,4,54,33,4,54,31,2,32,32,32,63,63,63,
33
    63,63,63,63,63,63,63,63,63,48,48,48,63,63,63,63,63,63);
34
35
 
36
  TRGBColor = packed record
37
    R, G, B: Byte;
38
  end;
39
40
 
41
  TRGBPalette = array[0..COLORS - 1] of TRGBColor;
42
43
 
44
  TRGBBuffer = array[0..HEIGHT - 1, 0..WIDTH - 1] of TRGBColor;
45
46
 
47
  sq     = array[0..254, 0..255] of Byte;
48
49
 
50
 
51
  mp: ^lrgarr;
52
  rng: array[0..320] of Byte;
53
  fcos, fsin: array[0..359] of Integer;
54
55
 
56
  RGBPalette: TRGBPalette absolute FlatPalette;
57
58
 
59
60
 
61
 
62
var
63
  loc: Byte;
64
begin
65
  loc := Byte((mc + n - Random(2 * n)) div dvd);
66
  if loc > 100 then Result := 100 else
67
  if loc < 5   then Result := 5   else
68
                    Result := loc;
69
end;
70
71
 
72
 
73
var
74
  xn, yn, dxy   : Word;
75
  p1, p2, p3, p4: Word;
76
begin
77
  if (x2 - x1 > 1) or (y2 - y1 > 1) then
78
  begin
79
    p1 := mp^[Word(y1 shl 8 + x1)];
80
    p2 := mp^[Word(y2 shl 8 + x1)];
81
    p3 := mp^[Word(y1 shl 8 + x2)];
82
    p4 := mp^[Word(y2 shl 8 + x2)];
83
    xn := (x2 + x1) shr 1;
84
    yn := (y2 + y1) shr 1;
85
    dxy:= 5 * (x2 - x1 + y2 - y1) div 3;
86
87
 
88
    if mp^[yn shl 8 + x1] = 0 then mp^[Word(yn shl 8 + x1)] := NCol(p1 + p2, dxy, 2);
89
    if mp^[yn shl 8 + x2] = 0 then mp^[Word(yn shl 8 + x2)] := NCol(p3 + p4, dxy, 2);
90
    if mp^[y2 shl 8 + xn] = 0 then mp^[Word(y2 shl 8 + xn)] := NCol(p2 + p4, dxy, 2);
91
    mp^[Word(yn shl 8 + xn)] := NCol(p1 + p2 + p3 + p4, dxy, 4);
92
93
 
94
    Plasma(xn, y1, x2, yn);
95
    Plasma(x1, yn, xn, y2);
96
    Plasma(xn, yn, x2, y2);
97
  end;
98
end;
99
100
 
101
 
102
var
103
  z, zobs               : Integer;
104
  ix, iy, iy1, iyp, ixp : Integer;
105
  x, y                  : Integer;
106
  s, csf, snf, mpc, i, j: Integer;
107
begin
108
  while dir <  0            do Inc(dir, SizeOf(fcos));
109
  while dir >= SizeOf(fcos) do Dec(dir, SizeOf(fcos));
110
111
 
112
  FillChar(RGBBuffer^, SizeOf(RGBBuffer^), 0);
113
114
 
115
116
 
117
  snf := fsin[dir];
118
119
 
120
  begin
121
    iy1 := 1 + 2 * (iy - yp);
122
    s   := 4 + 300 div iy1;
123
124
 
125
    begin
126
      ixp := xp + ((ix - xp) * csf + (iy - yp) * snf) shr 8;
127
      iyp := yp + ((iy - yp) * csf - (ix - xp) * snf) shr 8;
128
      x := 160 + 360 * (ix - xp) div iy1;
129
130
 
131
      begin
132
        z   := mp^[Word(iyp shl 8 + ixp)];
133
        mpc := z shr 1;
134
135
 
136
        y := 100 + (zobs - z) * 30 div iy1;
137
138
 
139
        for j := x to x + s do
140
        if y < rng[j] then
141
        begin
142
          for i := y to rng[j] do
143
            RGBBuffer^[i - 1, j] := RGBPalette[mpc];
144
          rng[j] := y;
145
        end;
146
      end;
147
    end;
148
  end;
149
end;
150
151
 
152
 
153
begin
154
  kos_begindraw();
155
  kos_definewindow(100, 100, WIDTH - 1, HEIGHT - 1, $01000000);
156
  kos_drawimage24(0, 0, WIDTH, HEIGHT, RGBBuffer);
157
  if Message <> '' then
158
    kos_drawtext(12, HEIGHT - 12 - 9, Message, $00FF00, $FF000000);
159
  kos_enddraw();
160
end;
161
162
 
163
 
164
var
165
  Event: Word;
166
begin
167
  kos_maskevents(ME_PAINT or ME_KEYBOARD);
168
  repeat
169
    Event := kos_getevent();
170
    if Event = SE_PAINT then Paint;
171
  until Event = SE_KEYBOARD;
172
  Result := Chr(kos_getkey() shr 8);
173
end;
174
175
 
176
 
177
begin
178
  kos_maskevents(ME_PAINT or ME_KEYBOARD);
179
  Message := MSG_PRESSKEY;
180
  Paint;
181
  ReadKey;
182
end;
183
184
 
185
 
186
  dir, i, j, x, y: Longint;
187
  C: Char;
188
  B: Byte;
189
  Terminate: Boolean;
190
191
 
192
  { таблицы значений синуса и косинуса }
193
  for i := 0 to 359 do
194
  begin
195
    fcos[i] := Trunc(256 * Cos(i / 180 * Pi));
196
    fsin[i] := Trunc(256 * Sin(i / 180 * Pi));
197
  end;
198
199
 
200
  New(mp);
201
  FillChar(mp^, SizeOf(mp^), 0);
202
  mp^[$0000] := 128;
203
  Plasma(0, 0, 256, 256);
204
205
 
206
  New(RGBBuffer);
207
  FillChar(RGBBuffer^, SizeOf(RGBBuffer^), 0);
208
209
 
210
211
 
212
  begin
213
    B := Round(RGBPalette[i].R / 63 * 255);
214
    RGBPalette[i].R := Round(RGBPalette[i].B / 63 * 255);
215
    RGBPalette[i].G := Round(RGBPalette[i].G / 63 * 255);
216
    RGBPalette[i].B := B;
217
  end;
218
219
 
220
    for i := 0 to 255 do
221
      RGBBuffer^[j, i + (WIDTH - 256) shr 1] := RGBPalette[sq(Pointer(mp)^)[j, i]];
222
223
 
224
225
 
226
  y   := 0;
227
  dir := 0;
228
229
 
230
231
 
232
  while not Terminate do
233
  begin
234
    dir := dir mod 360;
235
    if dir < 0 then dir := 360 + dir;
236
237
 
238
    Paint;
239
240
 
241
    if C = #$B0 then Dec(dir, 13) else
242
    if C = #$B3 then Inc(dir, 13) else
243
    if C = #$B2 then
244
    begin
245
      y := y + fcos[dir] shr 6;
246
      x := x + fsin[dir] shr 6;
247
    end else
248
    if C = #$B1 then
249
    begin
250
      y := y - fcos[dir] shr 6;
251
      x := x - fsin[dir] shr 6;
252
    end;
253
    if C = #27 then Terminate := True;
254
  end;
255
end.
256