SRL Archive - Research & Development Lounge

Draw Pizza/ Cartwheel


n3ss3s

2008-03-01 13:34:53

Well JuKKa needed a proc that moves a point closer to another point and I was bored and made something small, I thought I'd post it if someone would happen to learn something from it.


Program New;

Function SetPointCloser(Point: TPoint; Origin: TPoint; tDist: Integer): TPoint;
Var
Angle, Dist: Integer;
Begin
Angle := Round(Degrees(ArcTan2(Point.y - Origin.y, Point.x - Origin.x))) - 90;
If Angle < 0 Then
Angle := Angle + 360;
Dist := Distance(Point.x, Point.y, Origin.x, Origin.y) - tDist;
Result.x := Origin.x + Round(Dist * Cos(Radians(Angle - 90)));
Result.y := Origin.y + Round(Dist * Sin(Radians(Angle - 90)));
End;


Function doArc(Origin: TPoint; Dist, SD, ED: Integer): TPointArray;
Var
I: Integer;
Begin
SetArrayLength(Result, ED - SD + 1);
For I := SD To ED Do
Begin
Result[ED - i].x := Origin.x + Round(Dist * Cos(Radians(SD + i - 90)));
Result[ED - i].y := Origin.y + Round(Dist * Sin(Radians(SD + i - 90)));
End;
End;


Function LetsMakePizza(Origin: TPoint; Dist, SD, ED: Integer): TPointArray;
Var
tmp: TPointArray;
C, I: Integer;
Begin
tmp := doArc(Origin, Dist, SD, ED);
SetArrayLength(Result, Dist * 2 + 1);
For C := 0 To 1 Do
Case C Of
0: For I := 1 To Dist Do
Result[i] := SetPointCloser(tmp[0], Origin, i);
1: For I := 1 To Dist Do
Result[Dist + i] := SetPointCloser(tmp[High(tmp)], Origin, i);
End;
End;


Var
Arc, Tmp, TPA: TPointArray;
Var
I, II, III: Integer;
Var
BitMap: Integer;

Begin
DisplayDebugImgWindow(500, 500);
Bitmap := BitmapFromString(500, 500, '');
For I := 0 To 5 Do
Begin
Arc := doArc(Point(250, 250), 100, I * 60, I * 60 + 120);
Tmp := LetsMakePizza(Point(250, 250), 100, I * 60, I * 60 + 60);
TPA := CombineTPA(Arc, Tmp);
III := High(TPA);
For II := 0 To III Do
FastSetPixel(Bitmap, TPA[ii].x, TPA[ii].y, 255);
End;
CopyCanvas(GetBitmapCanvas(bitmap), GetDebugCanvas, 0, 0, 500, 500, 0, 0, 500, 500);
End.

Pure1993

2008-03-01 13:50:27

[homer simpson's voice] ahhhhhhh… ppppiiiizzzzaaaa… [/homer simpson's voice] :D
Looks nice, and uhm… and… puh, really have no clue what more to say. :rolleyes:

Dumpin

2008-03-01 14:02:48

Lol cool, i need to learn something more about canvas drawing :)

mixster

2008-03-01 14:41:07

The traingular-based functions for making circles will always live on! So from what I can see, it works by making a circle then inputting all the points on it into a tpoint instead of a movemouse, then the exact same for all the little slice bits and it then puts all of the points up onto the canvas. Once again, an entirely useless but fun none the less function/procedure's hurrah!

n3ss3s

2008-03-01 15:02:50

No, drawing the slices isn't exactly the same as drawing the arc, you also need to draw the legs of the "triangles".