Spiral matrix: Difference between revisions

Content added Content deleted
Line 1,607: Line 1,607:
{{works with|Delphi|6.0}}
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls, Windows}}
{{libheader|SysUtils,StdCtrls, Windows}}
This code actually creates the required matrix instead of simulating one. It can also create matrices of any size and the matrices don't have to be square. It works by creating a rectangle of the same size as the matrix, then entering the values along the lines of the rectangle. It then uses the Windows library routine "InflateRect" to decrease the size of the rectangle until the whole matrix is filled with spiraling values.
This code actually creates a matrix in memory and stores values in the matrix, instead of just simulating one drawing the pattern. It can also create matrices of any size and the matrices don't have to be square. It works by creating a rectangle of the same size as the matrix. It enters the values in the matrix along circumference of the matrix. It then uses the Windows library routine "InflateRect" to decrease the size of the rectangle until the whole matrix is filled with spiraling values. Since a rectangle can be any size and doesn't have to be square, it works with any size matrix, including non-square matrices.


<syntaxhighlight lang="Delphi">
<syntaxhighlight lang="Delphi">