this slowpoke moves

Draw Canvas Bezier

uses Math, ComCtrls

type
  Point = record
  X, Y, Z: real;
end;

var
  Form1: TForm1;
  P1, P2, Vv1, Vv2: Point;
  Drag: integer;

//

procedure TForm1.StopFlicker(var Msg: TWMEraseBkgnd);
begin
   Msg.Result := 0;
end;

procedure TForm1.DrawBeizer(A, D, V1, V2: Point);
Var B, C, P: Point;
    aa, bb, T: real;
    I: integer;
begin
  B.x := (A.x+ V1.x);
  B.y := (A.y+ V1.y);
  //B.z := (A.z+ V1.z);
  C.x := (D.x+ V2.x);
  C.y := (D.y+ V2.y);
  //C.z := (D.z+ V2.z);
  canvas.Ellipse(round(A.x-5),round(A.y-5),round(A.x+5),round(A.y+5));
  canvas.Ellipse(round(B.x-5),round(B.y-5),round(B.x+5),round(B.y+5));
  canvas.Ellipse(round(C.x-5),round(C.y-5),round(C.x+5),round(C.y+5));
  canvas.Ellipse(round(D.x-5),round(D.y-5),round(D.x+5),round(D.y+5));

  canvas.moveto(round(A.x), round(A.y));
  canvas.lineto(round(b.x), round(b.y));
  canvas.moveto(round(D.x), round(D.y));
  canvas.lineto(round(C.x), round(C.y));
  canvas.moveto(round(A.x), round(A.y));
  for I := 0 to TrackBra1.position do
  begin
     T := I / TrackBra1.position ;
     aa := T;
     bb := 1- T;
     P.x := a.X*power(bb,3) + 3*B.X*sqr(bb)*aa + 3*C.X*bb*sqr(aa) + D.x*Power(aa, 3);
     P.y := a.y*power(bb,3) + 3*B.y*sqr(bb)*aa + 3*C.y*bb*sqr(aa) + D.y*Power(aa, 3);
    // canvas.Ellipse(round(P.x-2),round(P.y-2),round(P.x+2),round(P.y+2));
     canvas.LineTo(round(P.X), round(P.y));
end;

end;
{$R *.DFM}

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var Pp1, Pp2, VVv1, Vvv2: point;
begin
 if Drag = 1 then
 begin
 P1.x := X;
 P1.Y := Y;
 end;
 if Drag = 2 then
 begin
 P2.X := X;
 P2.Y := Y;
 end;
 if Drag = 3 then
 begin
 Vv1.X := X - P1.x;
 Vv1.Y := Y - P1.y;
 end;
 if Drag = 4 then
 begin
 Vv2.X := X - P2.x;
 Vv2.Y := Y - P2.y;
 end;
 PatBlt(Canvas.Handle, 0, 0, Width, Height, WHITENESS);
 DrawBeizer(P1, P2, Vv1, Vv2);
 pp2.X := p1.x;
 pp2.Y := p1.Y;
 pp1.X := p2.x;
 pp1.Y := p2.Y;
 Vvv1.x := -Vv2.x;
 Vvv1.Y := -Vv2.y;
 Vvv2.x := -Vv1.x;
 Vvv2.Y := -Vv1.y;

 //DrawBeizer(Pp1, Pp2, Vvv1, Vvv2);
end;

function Col(P: Point; X, Y, R: integer): boolean;
begin
  Col := false;
  if (X >= P.x - R) and (X <= P.x + R) then
  if (Y >= P.y - R) and (Y <= P.y + R) then
  Col := true;
end;

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var T1, T2: point;
begin
  Drag := 0;
  if Col(P1, X, Y, 5) then Drag := 1;
  if Col(P2, X, Y, 5) then Drag := 2;

  T1.x := P1.x + Vv1.x;
  T1.y := P1.y + Vv1.y;
  if Col(T1, X, Y, 5) then Drag := 3;

  T2.x := P2.x + Vv2.x;
  T2.y := P2.y + Vv2.y;
  if Col(T2, X, Y, 5) then Drag := 4;
end;

procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  Drag := 0;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
 P1.x := 100;
 P1.Y := 100;
 P2.X := 200;
 P2.Y := 200;
 Vv1.X := 0;
 Vv1.Y := -100;
 vv2.X := 0;
 vv2.Y := 100;
end;

procedure TForm1.TrackBra1Change(Sender: TObject);
var S: TShiftState;
begin
 Mousemove(s, 0, 0);
end;

Keine Kommentare:

Kommentar veröffentlichen

Beliebte Posts

Translate