# Draws in Paintbox

Hello,

I'm trying to do a buttin that when pressed, using a paintbox, draw a big triangle, and inside of this triangle another one but with half of the size and so on... until it makes just one point... When I tryed to do this PaintBox1.Canvas.MoveTo(x/2,0); it encountered an error "Incompatible types: 'Integer' and 'Extended'"...
Can anyone help me plz??
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You need to use  one of the following to return an integer result (you can't use floating point math on a canvas)

x div 2, 0
Round(x / 2)
Trunc(x / 2)

Regards,
Russell

0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Author Commented:
=], thanks rllibby!!
0
Author Commented:
by the way.... do you know how to make a triangle that has all the sides the same size, 60°, I don't know the name in english =/, using paintbox?
0

procedure TForm1.PaintBox1Paint(Sender: TObject);
var  ptTriangle:    Array [0..3] of TPoint;
dwSize:        Integer;
dwX:           Integer;
dwY:           Integer;
begin

// Need to form a square
if (PaintBox1.Width > PaintBox1.Height) then
dwSize:=PaintBox1.Height
else
dwSize:=PaintBox1.Width;

// Leave a small border of 5px each side
Dec(dwSize, 10);

// Calculate the remaining borders
dwX:=(PaintBox1.Width - dwSize) div 2;
dwY:=(PaintBox1.Height - dwSize) div 2;

// Triangle with equal angles
ptTriangle[0]:=Point(dwX, dwY + dwSize);
ptTriangle[1]:=Point(dwX + (dwSize div 2), dwY);
ptTriangle[2]:=Point(dwX + dwSize, dwY + dwSize);
ptTriangle[3]:=Point(dwX, dwY + dwSize);

// Use polygon function
PaintBox1.Canvas.Polygon(ptTriangle);

end;
0

Btw, its an "equilateral triangle", You will also find that by decrementing the size, you can draw triangles within the triangle (like your original question)

procedure TForm1.PaintBox1Paint(Sender: TObject);
var  ptTriangle:    Array [0..3] of TPoint;
dwSize:        Integer;
dwX:           Integer;
dwY:           Integer;
begin

// Fill canvas with white brush
PaintBox1.Canvas.Brush.Color:=clWhite;
PaintBox1.Canvas.FillRect(Rect(0, 0, PaintBox1.Width, PaintBox1.Height));

// Need to form a square
if (PaintBox1.Width > PaintBox1.Height) then
dwSize:=PaintBox1.Height
else
dwSize:=PaintBox1.Width;

// Leave a small border of 5px each side
Dec(dwSize, 10);

// While size > 0
while (dwSize > 20) do
begin
// Calculate the remaining borders
dwX:=(PaintBox1.Width - dwSize) div 2;
dwY:=(PaintBox1.Height - dwSize) div 2;
// Triangle with equal angles
ptTriangle[0]:=Point(dwX, dwY + dwSize);
ptTriangle[1]:=Point(dwX + (dwSize div 2), dwY);
ptTriangle[2]:=Point(dwX + dwSize, dwY + dwSize);
ptTriangle[3]:=Point(dwX, dwY + dwSize);
// Use polygon function
PaintBox1.Canvas.Polygon(ptTriangle);
// Cut size in half
dwSize:=dwSize div 2;
end;

end;

0
Author Commented:
thanks ;)
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.