Recent

Author Topic: canvas rectange  (Read 1488 times)

shs

  • Sr. Member
  • ****
  • Posts: 310
canvas rectange
« on: September 16, 2017, 02:57:53 pm »
hi i want to draw many rectangles (with same width and height value) all connected in same top value with all different colours.
how can i do that?

Handoko

  • Hero Member
  • *****
  • Posts: 5154
  • My goal: build my own game engine using Lazarus
Re: canvas rectange
« Reply #1 on: September 16, 2017, 03:42:55 pm »
Did you mean something like this?

Code: Pascal  [Select][+][-]
  1. procedure TForm1.DrawRectangles;
  2. var
  3.   X, Y, Size: Integer;
  4. begin
  5.   Y := 100;
  6.   Size := 15;
  7.  
  8.   X := 60
  9.   Canvas.Pen.Color := clYellow;
  10.   Canvas.Rectangle(X, Y, X+Size, Y+Size);
  11.  
  12.   X := 80
  13.   Canvas.Pen.Color := clGreen;
  14.   Canvas.Rectangle(X, Y, X+Size, Y+Size);
  15.  
  16.   X := 100
  17.   Canvas.Pen.Color := clRed;
  18.   Canvas.Rectangle(X, Y, X+Size, Y+Size);
  19.  
  20.   X := 120
  21.   Canvas.Pen.Color := clBlue;
  22.   Canvas.Rectangle(X, Y, X+Size, Y+Size);
  23. end;

Please provide more information? Or not much we can help.
« Last Edit: September 16, 2017, 03:44:40 pm by Handoko »

shs

  • Sr. Member
  • ****
  • Posts: 310
Re: canvas rectange
« Reply #2 on: September 16, 2017, 04:19:22 pm »

Did you mean something like this?

Code: Pascal  [Select][+][-]
  1. procedure TForm1.DrawRectangles;
  2. var
  3.   X, Y, Size: Integer;
  4. begin
  5.   Y := 100;
  6.   Size := 15;
  7.  
  8.   X := 60
  9.   Canvas.Pen.Color := clYellow;
  10.   Canvas.Rectangle(X, Y, X+Size, Y+Size);
  11.  
  12.   X := 80
  13.   Canvas.Pen.Color := clGreen;
  14.   Canvas.Rectangle(X, Y, X+Size, Y+Size);
  15.  
  16.   X := 100
  17.   Canvas.Pen.Color := clRed;
  18.   Canvas.Rectangle(X, Y, X+Size, Y+Size);
  19.  
  20.   X := 120
  21.   Canvas.Pen.Color := clBlue;
  22.   Canvas.Rectangle(X, Y, X+Size, Y+Size);
  23. end;

Please provide more information? Or not much we can help.

Umm instead of putting number like 60, 80, 100, 120, i want to put the first value + x. for example, let's say 60 is the first value, and the second value should be first value + x and the third value should be second value + x. Thank you

 

TinyPortal © 2005-2018