2022-04-18 21:34:18 +03:00
|
|
|
|
// "Собачка". Иллюстрация использования таймера.
|
|
|
|
|
|
uses GraphWPF, Timers;
|
2015-05-14 22:35:07 +03:00
|
|
|
|
|
|
|
|
|
|
var
|
2022-04-18 21:34:18 +03:00
|
|
|
|
xx,yy,px,py: real;
|
2015-05-14 22:35:07 +03:00
|
|
|
|
|
|
|
|
|
|
procedure Draw;
|
|
|
|
|
|
begin
|
|
|
|
|
|
FillCircle(xx,yy,11);
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
2022-04-18 21:34:18 +03:00
|
|
|
|
procedure TimerProc;
|
2015-05-14 22:35:07 +03:00
|
|
|
|
begin
|
|
|
|
|
|
if (xx<>px) or (yy<>py) then
|
|
|
|
|
|
begin
|
|
|
|
|
|
var t := 1/10;
|
|
|
|
|
|
var newx := round((1-t)*xx+t*px);
|
|
|
|
|
|
var newy := round((1-t)*yy+t*py);
|
2022-04-18 21:34:18 +03:00
|
|
|
|
(xx,yy) := (newx,newy);
|
2015-05-14 22:35:07 +03:00
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
begin
|
2022-04-18 21:34:18 +03:00
|
|
|
|
Window.Title := '"Собачка"';
|
|
|
|
|
|
Brush.Color := Colors.Black;
|
2015-05-14 22:35:07 +03:00
|
|
|
|
|
|
|
|
|
|
xx := 100; yy := 100;
|
2022-04-18 21:34:18 +03:00
|
|
|
|
|
|
|
|
|
|
OnMouseMove := procedure(x,y,mb) -> (px,py) := (x,y);
|
|
|
|
|
|
|
|
|
|
|
|
OnDrawFrame := dt -> begin
|
|
|
|
|
|
FillCircle(xx,yy,11);
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
var t := new Timer(20,TimerProc);
|
2015-05-14 22:35:07 +03:00
|
|
|
|
t.Start;
|
|
|
|
|
|
end.
|