Janilabo Posted December 17, 2012 Share Posted December 17, 2012 (edited) Made these 2 useful little commands. Play around with the constants, to see how these work.. Constants can be negative aswell. Well, only TEST_SIZE has to be higher than 0 for these to work. const TEST_START_X = 0; TEST_START_Y = 0; TEST_SIZE = 10; TEST_SPACE = 1; function TPARow(rowStart: TPoint; rowSize, rowSpace: Integer): TPointArray; var i: Integer; begin if (rowSize > 0) then begin SetLength(Result, rowSize); for i := 0 to (rowSize - 1) do begin Result[i].X := rowStart.X; Result[i].Y := (rowStart.Y + (i * rowSpace)); end; end; end; function TPAColumn(columnStart: TPoint; columnSize, columnSpace: Integer): TPointArray; var i: Integer; begin if (columnSize > 0) then begin SetLength(Result, columnSize); for i := 0 to (columnSize - 1) do begin Result[i].X := (columnStart.X + (i * columnSpace)); Result[i].Y := columnStart.Y; end; end; end; var startPt: TPoint; TPA: TPointArray; begin startPt := Point(TEST_START_X, TEST_START_Y); TPA := TPARow(startPt, TEST_SIZE, TEST_SPACE); WriteLn('TPARow(' + PointToStr(startPt) + ', ' + IntToStr(TEST_SIZE) + ', ' + IntToStr(TEST_SPACE) + '): ' + #13#10 + TPAToStr(TPA)); SetLength(TPA, 0); WriteLn(''); TPA := TPAColumn(startPt, TEST_SIZE, TEST_SPACE); WriteLn('TPAColumn(' + PointToStr(startPt) + ', ' + IntToStr(TEST_SIZE) + ', ' + IntToStr(TEST_SPACE) + '): ' + #13#10 + TPAToStr(TPA)); SetLength(TPA, 0); end. Anyone have any better name suggestions for em? Also, TPAGrid(): const GRID_START_X = 0; GRID_START_Y = 0; GRID_ROWS = 3; GRID_COLUMNS = 3; GRID_ROW_SPACE = 1; GRID_COLUMN_SPACE = 1; function TPAGrid(start: TPoint; rows, columns, rowSpace, columnSpace: Integer): TPointArray; var i, s, r, c: Integer; begin if ((rows < 0) or (columns < 0)) then Exit; s := (rows * columns); if (s > 0) then begin SetLength(Result, s); for r := 0 to (rows - 1) do for c := 0 to (columns - 1) do begin i := ((r * columns) + c); Result[i].X := (start.X + (c * columnSpace)); Result[i].Y := (start.Y + (r * rowSpace)); end; end; end; var TPA: TPointArray; begin ClearDebug; TPA := TPAGrid(Point(GRID_START_X, GRID_START_Y), GRID_ROWS, GRID_COLUMNS, GRID_ROW_SPACE, GRID_COLUMN_SPACE); WriteLn('TPAGrid((' + IntToStr(GRID_START_X) + ',' + IntToStr(GRID_START_Y) + '), ' + IntToStr(GRID_ROWS) + ', ' + IntToStr(GRID_COLUMNS) + ', ' + IntToStr(GRID_ROW_SPACE) + ', ' + IntToStr(GRID_COLUMN_SPACE) + '):'); WriteLn(TPAToStr(TPA)); SetLength(TPA, 0); end. ..aaaaand TBAGrid(): function TBAGrid(start: TPoint; boxWidth, boxHeight, rows, columns, rowSpace, columnSpace: Integer): TBoxArray; var i, s, r, c: Integer; begin if ((rows < 0) or (columns < 0) or (boxWidth < 1) or (boxHeight < 1)) then Exit; s := (rows * columns); if (s > 0) then begin SetLength(Result, s); for r := 0 to (rows - 1) do for c := 0 to (columns - 1) do begin i := ((r * columns) + c); Result[i].X1 := (start.X + (c * columnSpace)); Result[i].Y1 := (start.Y + (r * rowSpace)); Result[i].X2 := (Result[i].X1 + (boxWidth - 1)); Result[i].Y2 := (Result[i].Y1 + (boxHeight - 1)); end; end; end; TBARow() & TBAColumn(): function TBARow(start: TPoint; boxWidth, boxHeight, rowSize, rowSpace: Integer): TBoxArray; var i: Integer; begin if ((rowSize > 0) and (boxWidth > 0) and (boxHeight > 0)) then begin SetLength(Result, rowSize); for i := 0 to (rowSize - 1) do begin Result[i].X1 := start.X; Result[i].Y1 := (start.Y + (i * rowSpace)); Result[i].X2 := (Result[i].X1 + (boxWidth - 1)); Result[i].Y2 := (Result[i].Y1 + (boxHeight - 1)); end; end; end; function TBAColumn(start: TPoint; boxWidth, boxHeight, columnSize, columnSpace: Integer): TBoxArray; var i: Integer; begin if ((columnSize > 0) and (boxWidth > 0) and (boxHeight > 0)) then begin SetLength(Result, columnSize); for i := 0 to (columnSize - 1) do begin Result[i].X1 := (start.X + (i * columnSpace)); Result[i].Y1 := start.Y; Result[i].X2 := (Result[i].X1 + (boxWidth - 1)); Result[i].Y2 := (Result[i].Y1 + (boxHeight - 1)); end; end; end; http://uppit.com/1azcxakq7tuc/Grid_stuff.zip (some examples for most of these functions) -Jani Edited January 9, 2013 by Janilabo Added TBAColumn / TBARow and corrected TPAGrid/TBAGrid. Quote Link to comment Share on other sites More sharing options...