Results 1 to 8 of 8

Thread: Draw Spline

  1. #1
    Join Date
    Dec 2006
    Location
    utah
    Posts
    1,427
    Mentioned
    2 Post(s)
    Quoted
    7 Post(s)

    Default Draw Spline

    i love Splines....
    Drag the spline Points around...


    SCAR Code:
    program New;
    // By Sky Scripter

    // Use The White Sqrs to move the line ect...

    var
       MainForm : TForm;
       S, E, c1, c2, c3 : TPoint;
       c : Integer;

    { Created By Sky Scripter }
    // Draw a Spline Path
    function DrawSplinePath(sx, sy, ex, ey : Integer; Controls : TPointArray) : TPointArray;
    var
      theta, inc, b1, b2, b3, b4 : Extended;
      Tempx, Tempy, Lastx, Lasty : Integer;
      Cntrls : array [1..4] of TPoint;
    begin
      inc := 1.0 / Distance(sx, sy, ex, ey);
      if (InRange(Length(Controls), 1, 3)) then
      begin
      Cntrls[1] := Controls[0];
      Cntrls[2] := Controls[1];
      Cntrls[3] := Controls[2];
      Cntrls[4] := Point(ex - sx, ey - sy);
       repeat
          theta := theta + inc;
          b1:= Pow(theta, 3);
          b2:= 3 * b1 * (1 - theta);
          b3:= 5 * (b1 / theta) * Sqr(1 - theta);
          b4:= 3 * (b1 / Pow(theta, 2)) * Pow(1 - theta, 2);
          Tempx := Trunc(Cntrls[1].x * b2 + Cntrls[2].x * b3 + Cntrls[3].x * b4 + Cntrls[4].x * b1 + sx);
          Tempy := Trunc(Cntrls[1].y * b2 + Cntrls[2].y * b3 + Cntrls[3].y * b4 + Cntrls[4].y * b1 + sy);
           if (Tempx <> Lastx) and (Tempy <> Lasty) then
           begin

                   if (Lastx <> 0) and (Lasty <> 0) then
            if (Distance(Tempx, Tempy, Lastx, Lasty) > 5) then
            begin
               Tempx := (Tempx + Lastx) / 2;
               Tempy := (Tempy + Lasty) / 2;
               theta := theta - Inc;
             end;

             SetArrayLength(Result, Length(Result) + 1);
             Result[length(Result)-1] := Point(Tempx, Tempy);
             Lastx := Tempx;
             Lasty := Tempy;
           end;
       until (theta >= 1);
      end;
    end;

    function InDist(p1, p2 : TPoint; maxdist : Integer) : Boolean;
    begin
     Result := (Distance(p1.x, p1.y, p2.x, p2.y) <= MaxDist)
    end;

    procedure OnMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    begin
         if (ssLeft in Shift) then
         begin
         c := c + 1;
          if (c < 5) then exit;
          if (InDist(S, Point(x, y), 20)) then
          begin
            S := Point(x, y);
            c := 0;
            MainForm.RePaint;
            exit;
          end;
          if (InDist(E, Point(x, y), 20)) then
          begin
            E := Point(x, y);
            c := 0;
            MainForm.RePaint;
            exit;
          end;
             if (InDist(c1, Point(x, y), 20)) then
          begin
            c1 := Point(x, y);
            c := 0;
            MainForm.RePaint;
            exit;
          end;
          if (InDist(c2, Point(x, y), 20)) then
          begin
            c2 := Point(x, y);
            c := 0;
            MainForm.RePaint;
            exit;
          end;
            if (InDist(c3, Point(x, y), 20)) then
          begin
            c3 := Point(x, y);
            c := 0;
            MainForm.RePaint;
            exit;
          end;
        end;
    end;

    procedure OnPaint(Sender : TObject);
    var
      P, Controls : TPointArray;
      i : Integer;

    begin
       SetArrayLength(Controls, 3);
       Controls[0] := c1;
       Controls[1] := c2;
       Controls[2] := c3;
       for i := 0 to 2 do
       MainForm.Canvas.Rectangle(Controls[i].x - 2, Controls[i].y - 2, Controls[i].x + 2, Controls[i].y + 2);
      P := DrawSplinePath(s.x, s.y, e.x, e.y, Controls);
       for i := 0 to GetArrayLength(P)-1 do
         MainForm.Canvas.Pixels[P[i].x, P[i].y] := 255 * i;
         MainForm.Canvas.Rectangle(s.x - 2, s.y - 2, s.x + 2, s.y + 2);
         MainForm.Canvas.Rectangle(e.x - 2, e.y - 2, e.x + 2, e.y + 2);
    end;


    procedure OnTimer(Sender : TObject);
    begin
      MainForm.Repaint;
    end;


    procedure InitForm;
    begin
      s := Point(10, 10);
      e := Point(200, 300);
      C1 := Point(100, 100);
      C2 := Point(200, 50);
      C3 := Point(100, 50);

      MainForm := CreateForm;
      MainForm.SetBounds(0, 0, 500, 500);
      MainForm.POSITION:= poDesktopCenter;
      MainForm.BORDERICONS:= [biMinimize, biSystemMenu];
      MainForm.BORDERSTYLE:= bsSingle;
      MainForm.Color := 0;
      MainForm.Caption := 'Sky Spline';
      MainForm.Canvas.Brush.Style := bsSolid;
      MainForm.Canvas.Brush.Color := clWhite;
      MainForm.OnPaint := @OnPaint;
      MainForm.OnMouseMove := @OnMouseMove;

      MainForm.ShowModal;
    end;

    procedure SafeInitForm;
    var
      v: TVariantArray;
    begin
      setarraylength(V, 0);
      ThreadSafeCall('InitForm', v);
    end;




    {var
      P, Controls : TPointArray;
      i : Integer;}

    begin
    try
    SafeInitForm;
    {
    SetArrayLength(Controls, 3);
    Controls[0] := Point(900, 400);
    Controls[1] := Point(5, 500);
    Controls[2] := Point(5, 500);

    P := DrawSplinePath(10, 10, 600, 600, Controls);
    for i := 0 to GetArrayLength(P)-1 do
    begin
     MoveMouse(P[i].x, P[i].y);
     Wait(10);
    end;  }

    finally
    FreeForm(MainForm);

    except
    Writeln('ERROR');
    end;

    end.

  2. #2
    Join Date
    Feb 2007
    Posts
    53
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Its beautiful

  3. #3
    Join Date
    May 2007
    Location
    baltimore, md
    Posts
    836
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    sky i have a question about the onmousemove procedure because when i used it in a seperate script it gave me a type mysmatch where the begin was.

  4. #4
    Join Date
    Feb 2006
    Location
    L.A, USA
    Posts
    1,632
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    I never learned splines before. Your making me frown like ' '.

    ;D

  5. #5
    Join Date
    Dec 2006
    Location
    utah
    Posts
    1,427
    Mentioned
    2 Post(s)
    Quoted
    7 Post(s)

    Default

    Quote Originally Posted by jhildy View Post
    sky i have a question about the onmousemove procedure because when i used it in a seperate script it gave me a type mysmatch where the begin was.
    procedure might be typed wrong..
    has to be...

    procedure OnMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);

    other then that i would have to look at it

  6. #6
    Join Date
    Dec 2006
    Location
    utah
    Posts
    1,427
    Mentioned
    2 Post(s)
    Quoted
    7 Post(s)

    Default

    hey, Check this out

    sorry for the double post....

    SCAR Code:
    program new;


    const
       RibbonWidth = 10;
       RibbonHeight = 100;
       DegreeTurn = 360;





    type
       TRibbon = record
       Control : TPoint;
       Width, Height : Integer;
    end;

    var
      MainForm : TForm;
      Ribbon : TRibbon;
      Timer : TTIMER;
      Degree : Integer;



    function DrawSplinePath(sx, sy, ex, ey, MinStep : Integer; Controls : TPointArray) : TPointArray;
    var
      theta, inc, b1, b2, b3, b4 : Extended;
      Tempx, Tempy, Lastx, Lasty : Integer;
      Cntrls : array [1..4] of TPoint;
    begin
      inc := (1.0 / (Distance(sx, sy, ex, ey) / 0.5));
      if (InRange(Length(Controls), 1, 3)) then
      begin
      Cntrls[1] := Controls[0];
      Cntrls[2] := Controls[1];
      Cntrls[3] := Controls[2];
      Cntrls[4] := Point(ex - sx, ey - sy);
       repeat
          theta := theta + inc;
          b1:= Pow(theta, 3);
          b2:= 3 * b1 * (1 - theta);
          b3:= 5 * (b1 / theta) * Sqr(1 - theta);
          b4:= 3 * (b1 / Pow(theta, 2)) * Pow(1 - theta, 2);
          Tempx := Trunc(Cntrls[1].x * b4 + Cntrls[2].x * b3 + Cntrls[3].x * b2 + Cntrls[4].x * b1 + sx);
          Tempy := Trunc(Cntrls[1].y * b4 + Cntrls[2].y * b3 + Cntrls[3].y * b2 + Cntrls[4].y * b1 + sy);
           if (iAbs(Lastx - Tempx) >= MinStep) and
              (iAbs(Lasty - Tempy) >= MinStep) then
           begin
             SetArrayLength(Result, Length(Result) + 1);
             Result[length(Result)-1] := Point(Tempx, Tempy);
             Lastx := Tempx;
             Lasty := Tempy;
           end;
       until (theta >= 1);
      end;
    end;

    procedure DrawRibbon(Ribbon : TRibbon);
    var
       i : Integer;
       P : TPointArray;
    begin
    try
       P := DrawSplinePath(255, 100, 255, 100 + Ribbon.Height, 0, [Ribbon.Control, Ribbon.Control, Ribbon.Control]);

     for i := 0 to GetArrayLength(P)-1 do
     begin
       MainForm.Canvas.MoveTo(P[i].x, P[i].y);
       MainForm.Canvas.LineTo(P[i].x + Ribbon.Width, P[i].y);
       if (i mod 2 = 0) then
       MainForm.Canvas.Pen.Color := 255 * i;
     end;
    except
    end;
    end;




    procedure OnPaint(Sender : TObject);
    begin
     DrawRibbon(Ribbon);
    end;


    procedure OnTimer(Sender : TObject);
    var
      x, y : Integer;
    begin
        Degree := Degree + 30;
        x := trunc(100 * Sin((Pi/DegreeTurn) * Degree));
        y := trunc(120 * Cos((Pi/DegreeTurn) * Degree));
        Ribbon.Control := Point(x, y);
        MainForm.Repaint;
    end;


    procedure InitForm;
    begin
      MainForm := CreateForm;
      MainForm.SetBounds(0, 0, 500, 400);
      MainForm.POSITION:= poDesktopCenter;
      MainForm.BORDERICONS:= [biMinimize, biSystemMenu];
      MainForm.BORDERSTYLE:= bsSingle;
      MainForm.Caption := 'Splines!';
      MainForm.Canvas.Pen.Color := 255;
      MainForm.Canvas.Pen.Width := 4;
      MainForm.Canvas.Brush.Style := bsClear;
      MainForm.OnPaint := @OnPaint;

      Timer := TTIMER.Create(MainForm);
      Timer.INTERVAL := 100;
      Timer.ONTIMER := @OnTimer;

      MainForm.ShowModal;
    end;

    procedure SafeInitForm;
    var
      v: TVariantArray;
    begin
      setarraylength(V, 0);
      ThreadSafeCall('InitForm', v);
    end;


    begin
      try
       Ribbon.Height := RibbonHeight;
       Ribbon.Width := RibbonWidth;

      SafeInitForm;

      finally
         FreeForm(MainForm)

      except
        Writeln('ERROR: With Loading');

      end;

    end.

  7. #7
    Join Date
    Dec 2006
    Location
    Copy pastin to my C#
    Posts
    3,788
    Mentioned
    8 Post(s)
    Quoted
    29 Post(s)

    Default

    Nice... Are you better scripting non-rs than rs?

  8. #8
    Join Date
    Dec 2006
    Location
    utah
    Posts
    1,427
    Mentioned
    2 Post(s)
    Quoted
    7 Post(s)

    Default

    Quote Originally Posted by n3ss3s View Post
    Nice... Are you better scripting non-rs than rs?
    Thats for you to decide but Id say i enjoy non-rs scripts more...
    but i like making like object finders and ect... in RS... too.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Creating your own MMouse... Bezier Spline
    By pwnaz0r in forum OSR Advanced Scripting Tutorials
    Replies: 29
    Last Post: 06-07-2009, 09:20 PM
  2. calculate the values and draw chart
    By Laimonas171 in forum C#/Visual Basic Help and Tutorials
    Replies: 2
    Last Post: 12-26-2008, 09:12 AM
  3. How to Draw Stuff In RS
    By Naum in forum RuneScape Guides
    Replies: 79
    Last Post: 10-13-2008, 11:05 AM
  4. Draw Pizza/ Cartwheel
    By n3ss3s in forum Research & Development Lounge
    Replies: 4
    Last Post: 03-01-2008, 08:02 PM
  5. Fast Draw Help!
    By dialeyj2 in forum OSR Help
    Replies: 3
    Last Post: 07-27-2007, 01:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •