unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    Image1: TImage;
    Timer1: TTimer;
    Label1: TLabel;
    Button2: TButton;
    Button3: TButton;
    Edit_R1: TEdit;
    Label2: TLabel;
    Button4: TButton;
    Button5: TButton;
    Edit_T1: TEdit;
    Label3: TLabel;
    Button6: TButton;
    Button7: TButton;
    Edit_T2: TEdit;
    Label4: TLabel;
    Button8: TButton;
    Button9: TButton;
    Edit_R2: TEdit;
    Button10: TButton;
    Button11: TButton;
    Button12: TButton;
    Button13: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Button1: TButton;
    Timer2: TTimer;
    Button14: TButton;
    Timer3: TTimer;
    procedure Timer1Timer(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button8Click(Sender: TObject);
    procedure Button9Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure Button7Click(Sender: TObject);
    procedure Button10Click(Sender: TObject);
    procedure Button12Click(Sender: TObject);
    procedure Button11Click(Sender: TObject);
    procedure Button13Click(Sender: TObject);
    procedure Timer2Timer(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button14Click(Sender: TObject);
    procedure Timer3Timer(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  t1,t2:real;
  a1,a2:integer;
 i,x1,y1,x2,y2,x0,y0:integer;
 r:byte;
step,xstep:integer;
 r1: byte;
 r2: byte;
  dottbl_x1: array[0..256*8] of integer;
  dottbl_y1: array[0..256*8] of integer;
  dottbl_x2: array[0..256*8] of integer;
  dottbl_y2: array[0..256*8] of integer;
  suxarray: array[0..256*8*4] of byte;
  multbl:array [0..256*40] of byte;
implementation

{$R *.dfm}


procedure TForm1.Timer1Timer(Sender: TObject);
var a1p:integer;
begin
step:=8;

  Form1.Image1.Canvas.Brush.Color:=clWhite;
  Form1.Image1.Canvas.FillRect(Rect(0,0,255,255));
a1p:=0;
for i:=0 to 199 do
  begin
  x1:=trunc(r1*cos((a1+a1p)*t1*pi/128));
  y1:=trunc(r1*sin((a1+a1p)*t1*pi/128));
  x2:=trunc(r2*cos((a1+a1p)*pi/128));
  y2:=trunc(r2*sin((a1+a1p)*t2*pi/128));

  a1p:=a1p+step;

  x0:=128+y1+y2;
  y0:=96+x1+x2;

  Form1.Image1.Canvas.Brush.Color:=clBlack;
  Form1.Image1.Canvas.FillRect(Rect(x0,y0,x0+2,y0+2));
  end;

a1:=a1+1;
a2:=a2+1;
xstep:=xstep+1;
if xstep=step then
  begin
  a1:=a1-step;
  a2:=a2-step;
  xstep:=0;
  end;


//------------- Show vars
Form1.Edit_R1.Text:=IntToStr(r1);
Form1.Edit_T1.Text:=CurrToStr(t1);
Form1.Edit_R2.Text:=IntToStr(r2);
Form1.Edit_T2.Text:=CurrToStr(t2);

end;


procedure TForm1.FormCreate(Sender: TObject);
begin
t1:=2.7; t2:=1.7; 
a1:=2; a2:=3;
r1:=54; r2:=StrToInt(Form1.Edit1.Text);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
Inc(R1);
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
Dec(r1);
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
t1:=t1+0.05;
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
t1:=t1-0.05;
end;

procedure TForm1.Button8Click(Sender: TObject);
begin
Inc(r2);
end;

procedure TForm1.Button9Click(Sender: TObject);
begin
Dec(r2);
end;

procedure TForm1.Button6Click(Sender: TObject);
begin
t2:=t2+0.05;
end;

procedure TForm1.Button7Click(Sender: TObject);
begin
t2:=t2-0.05;
end;

procedure TForm1.Button10Click(Sender: TObject);
begin
r1:=r1+10;
end;

procedure TForm1.Button12Click(Sender: TObject);
begin
r2:=r2+10;
end;

procedure TForm1.Button11Click(Sender: TObject);
begin
r1:=r1-10;
end;

procedure TForm1.Button13Click(Sender: TObject);
begin
r2:=r2-10;
end;

procedure TForm1.Timer2Timer(Sender: TObject);
begin
if r2<StrToInt(Form1.Edit2.Text) then r2:=r2+1 else Timer2.Enabled:=false;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Timer2.Enabled:=true;
end;

procedure TForm1.Button14Click(Sender: TObject);
var a1p:integer;
  F: file of byte;
  b:byte;
  j, dotindex,bi:integer;
begin
a1:=2; a2:=3;
r2:=1;

Form1.Timer1.Enabled:=false;
Form1.Timer2.Enabled:=false;

  Form1.Image1.Canvas.Brush.Color:=clWhite;
  Form1.Image1.Canvas.FillRect(Rect(0,0,255,255));
  dotindex:=0;
a1p:=0;
AssignFile (F,'dottbl.tbl');
ReWrite (F);

for i:=0 to 199 do
  begin
  for j:=0 to 7 do
    begin
    x1:=trunc(r1*cos((a1+a1p++j)*t1*pi/128));
    y1:=trunc(r1*sin((a1+a1p+j)*t1*pi/128));
    x2:=trunc(127*cos((a2+a1p+j)*pi/128));
    y2:=trunc(127*sin((a2+a1p+j)*t2*pi/128));
    dottbl_x1[i*8+j]:=x1;
    dottbl_y1[i*8+j]:=y1;
    dottbl_x2[i*8+j]:=x2;
    dottbl_y2[i*8+j]:=y2;
    b:=y2; Write (F,b);
    b:=y1; Write (F,b);
    b:=x2; Write (F,b);
    b:=x1; Write (F,b);
    end;
a1p:=a1p+8;
end;
//AssignFile (F,'dottbl.tbl');
//ReWrite (F);
for i:=0 to 200*8-1 do
  begin
  if (dottbl_y2[i]>=0) then b:=dottbl_y2[i] else b:=256+dottbl_y2[i];
  //Write (F,b);
   suxarray[i*4]:=b;
  if (dottbl_y1[i]>=0) then b:=dottbl_y1[i] else b:=256+dottbl_y1[i];
  // (F,b);
   suxarray[i*4+1]:=b;
  if (dottbl_x2[i]>=0) then b:=dottbl_x2[i] else b:=256+dottbl_x2[i];
  //Write (F,b);
   suxarray[i*4+2]:=b;
  if (dottbl_x1[i]>=0) then b:=dottbl_x1[i] else b:=256+dottbl_x1[i];
  //Write (F,b);
  suxarray[i*4+3]:=b;
  end;
CloseFile(F);

AssignFile (F,'multbl.tbl');
ReWrite(f);
for j:=1 to 48 do
for i:=0 to 255 do
  begin
  if i<=127 then b:=trunc(j*i/127) else b:=trunc(j*(i-256)/127);
  multbl[i+j*256]:=b;
  Write (f,b);
  end;
CloseFile(f);

r2:=38;
Form1.Edit_R2.Text:='38';
Timer3.Enabled:=true;
end;

procedure TForm1.Timer3Timer(Sender: TObject);
var b:byte;
begin
Form1.Image1.Canvas.Brush.Color:=clWhite;
Form1.Image1.Canvas.FillRect(Rect(0,0,255,255));
Form1.Image1.Canvas.Brush.Color:=clBlack;
for i:=0 to 199 do
  begin
  y2:=suxarray[i*32+xstep*4+0];// if b<=127 then y2:=b else y2:=b-256;
  b:=suxarray[i*32+xstep*4+1]; if b<=127 then y1:=b else y1:=b-256;
  x2:=suxarray[i*32+xstep*4+2]; //if b<=127 then x2:=b else x2:=b-256;
  b:=suxarray[i*32+xstep*4+3]; if b<=127 then x1:=b else x1:=b-256;

  y2:=trunc(multbl[y2+StrToInt(Edit_r2.Text)*256]);
  x2:=trunc(multbl[x2+StrToInt(Edit_r2.Text)*256]);

  if y2>127 then y2:=y2-256;
  if x2>127 then x2:=x2-256;

//  x1:=dottbl_x1[i*8+xstep];
//  y1:=dottbl_y1[i*8+xstep];
//  x2:=trunc(32*dottbl_x2[i*8+xstep]/127);
//  y2:=trunc(32*dottbl_y2[i*8+xstep]/127);
  x0:=128+y1+y2;
  y0:=96+x1+x2;
  Form1.Image1.Canvas.Brush.Color:=clBlack;
  Form1.Image1.Canvas.FillRect(Rect(x0,y0,x0+1,y0+1));
  end;
xstep:=xstep+1;
if xstep=8 then xstep:=0;
//------------- Show vars
Form1.Edit_R1.Text:=IntToStr(r1);
Form1.Edit_T1.Text:=CurrToStr(t1);
Form1.Edit_R2.Text:=IntToStr(r2);
Form1.Edit_T2.Text:=CurrToStr(t2);

end;

end.
