Solved

Draws in Paintbox

Posted on 2006-06-29
6
771 Views
Last Modified: 2010-04-05
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??
0
Comment
Question by:plinho
  • 3
  • 3
6 Comments
 
LVL 26

Accepted Solution

by:
Russell Libby earned 50 total points
ID: 17014985
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
 

Author Comment

by:plinho
ID: 17020809
=], thanks rllibby!!
0
 

Author Comment

by:plinho
ID: 17021901
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 26

Expert Comment

by:Russell Libby
ID: 17021967

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
 
LVL 26

Expert Comment

by:Russell Libby
ID: 17021995

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 Comment

by:plinho
ID: 17025528
thanks ;)
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
proper way to parse text with delphi 7 121
select query - oracle 16 100
Error E2158 compiling with Delphi XE10 Seattle 2 99
SUM 2 INTEGER ARRAYS INTO 1 10 100
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question