igorich1376

Mouse

Jul 23rd, 2024 (edited)
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.90 KB | None | 0 0
  1. program Mouse;
  2. uses GraphWPF;
  3. const
  4.   width = 720;
  5.   height = 720;
  6.   cx = width/2;
  7.   cy = height/2;
  8.   pen_width = 2.5;
  9. var
  10.   tx,ty: real;
  11. procedure Prepare();
  12. begin
  13.   Window.Title := 'Мышка WPF';
  14.   Window.SetSize(WIDTH, HEIGHT);
  15.   Window.CenterOnScreen;
  16.   Window.IsFixedSize := true;
  17.   FillRectangle(0,0,WIDTH+10, HEIGHT+10, Colors.SeaShell);
  18.   //Window.Clear(Colors.LightGreen);
  19. end;
  20. procedure MouseDown(mx,my: real; mousebutton: integer);
  21. begin
  22.   var dx := mx - tx;
  23.   var dy := my - ty;
  24.   var a := System.Math.Atan2(dy, dx);
  25.   var dist := Sqrt(dx**2 + dy**2);
  26.   var x := tx + dist*Cos(a);
  27.   var y := ty+dist*Sin(a);
  28.   // запоминаем новые координаты:
  29.   tx := x;
  30.   ty := y;
  31.   // вперёд!
  32.   LineTo(x,y);
  33. end;
  34.  
  35. begin
  36.   Prepare;
  37.   Pen.Width := 2;
  38.   Pen.Color := Colors.Green;
  39.   MoveTo(cx,cy);
  40.   tx := cx;
  41.   ty := cy;
  42.   OnMouseDown := MouseDown;
  43. end.
Advertisement
Add Comment
Please, Sign In to add comment