Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program new;
- {$I SRL/OSR.simba}
- {$R-}
- var
- bmp: TMufasaBitmap;
- function SmoothLine(A,B:Vector2; z: Int32; curvyness:Double=1): TPointArray;
- var
- t,d,r,rx,ry: Double;
- i,j,k: Int32;
- vec,prev: Vector2;
- v,tmp: array of Vector2;
- begin
- d := Hypot(A.x-B.x, A.y-B.y) / z * curvyness;
- r := d/2;
- SetLength(v, z);
- v[0] := A;
- for i:=1 to z-1 do
- begin
- t := srl.SkewedRand(0,-0.5,1.5);
- v[i].x := ((1-t)*v[i-1].x + t*B.x) + Random()*d-r;
- v[i].y := ((1-t)*v[i-1].y + t*B.y) + Random()*d-r;
- end;
- v[z-1] := B;
- t := 0;
- prev := A;
- while t <= 1 do
- begin
- tmp := Copy(v);
- for i:=High(tmp) downto 1 do
- for k:=0 to i do
- begin
- tmp[k].x := tmp[k].x + (tmp[k+1].x - tmp[k].x) * t;
- tmp[k].y := tmp[k].y + (tmp[k+1].y - tmp[k].y) * t;
- end;
- vec := tmp[0];
- Result += TPAFromLine(Round(prev.x),Round(prev.y), Round(vec.x),Round(vec.y));
- prev := vec;
- t += 0.01;
- end;
- Result += TPAFromLine(Round(prev.x),Round(prev.y), Round(B.x),Round(B.y));
- end;
- var
- p: TPoint;
- a: TPoint=[50,50];
- b: TPoint=[430,380];
- i,c: Int32;
- begin
- bmp := GetMufasaBitmap(CreateBitmap(500,500));
- bmp.Debug();
- while True do
- begin
- bmp.Clear();
- bmp.DrawTPA(TPAFromLine(a.x,a.y,b.x,b.y), $FFFFFF);
- for p in SmoothLine([a.x,a.y], [b.x,b.y], 25, 1.3) do
- try
- bmp.SetPixel(p.x,p.y, $FF00FF);
- Inc(i);
- if i mod 3 = 0 then bmp.Debug();
- except end;
- bmp.Debug();
- Wait(500);
- end;
- bmp.Debug();
- end.
Add Comment
Please, Sign In to add comment