Среда программирования:
Lazarus 0.9.30 (Free Pascal)
unit Unit1; {$mode objfpc}{$H+} interface uses Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls; type { TForm1 } TForm1 = class(TForm) Button1: TButton; PaintBox1: TPaintBox; Timer1: TTimer; procedure Button1Click(Sender: TObject); procedure Timer1Timer(Sender: TObject); private { private declarations } public { public declarations } procedure Rect(x, y, size, cnt: Integer); function Count(cnt : Integer):Integer; end; var Form1: TForm1; i, j, a, b, c, cnt, size, z, zcnt: Integer; implementation {$R *.lfm} { TForm1 } //функция пересчета переменной cnt, отвечающей за цвет квадратиков function TForm1.Count(cnt : Integer):Integer; begin if cnt=0 then begin Result:=1; end else Result:=0; end; //прорисовка прямоугольника procedure TForm1.Rect(x, y, size, cnt: Integer); begin if cnt=0 then begin PaintBox1.Canvas.Pen.Color := clBlack; PaintBox1.Canvas.Brush.Color := clBlack; end else begin PaintBox1.Canvas.Pen.Color := clWhite; PaintBox1.Canvas.Brush.Color := clWhite; end; PaintBox1.Canvas.Rectangle(x,y,x+size,y+size); end; procedure TForm1.Button1Click(Sender: TObject); begin size:=60; cnt:=1; i:=0; Timer1.Interval:=20; //фон while i<540 do begin j:=0; while j<540 do begin cnt:=Count(cnt); Rect(i, j, size, cnt); j:=j+60; end; i:=i+60; end; i:=0; while i<540 do begin j:=0; while j<540 do begin cnt:=Count(cnt); Rect(i+a, j+b, size div 2, cnt); j:=j+60; end; i:=i+60; end; a:=0; b:=0; Timer1.Enabled := true; end; //движение маленьких квадратов procedure TForm1.Timer1Timer(Sender: TObject); begin //зарисовываем i:=0; while i<540 do begin j:=0; while j<540 do begin cnt:=Count(cnt); Rect(i+a, j+b, size div 2, cnt); j:=j+60; end; i:=i+60; end; //поворот квадратов if ((a = size div 2)and(b = size div 2)) then c:=1; if ((a = 0)and(b = 0)) then c:=0; if ((a < size div 2)and(b < size div 2)and(c=0)) then a:=a+1; if ((a = size div 2)and(b < size div 2)and(c=0)) then b:=b+1; if ((a > 0)and(b = size div 2)and(c=1)) then a:=a-1; if ((a = 0 )and(b > 0)and(c=1)) then b:=b-1; //прорисовка на новом месте cnt:=0; i:=0; while i<540 do begin j:=0; while j<540 do begin cnt:=Count(cnt); Rect(i+a, j+b, size div 2, cnt); j:=j+60; end; i:=i+60; end; end; end.
Прикрепленный файл | Размер |
---|---|
Вращение шахматных клеток демо-пример | 1.06 Мб |