Created
January 19, 2009 18:40
-
-
Save mariusz/49097 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void GenerateGrid(int quantityX, int quantityY) | |
| { | |
| this.divX = quantityX + 1; | |
| this.divY = quantityY + 1; | |
| int nodesQuantity = this.divX * this.divY; | |
| float maxWidth = GetStringWidth(nodesQuantity.ToString()) * 1.7f; | |
| this.offsetY = maxWidth; | |
| float width = (this.divX * maxWidth) + 20.0f; | |
| float height = (this.divY * maxWidth); | |
| Bitmap bmp = new Bitmap((int)(width + 1.0f), (int)(height + 1.0f)); | |
| Graphics gr = Graphics.FromImage(bmp); | |
| Pen pen = new Pen(Color.Coral); | |
| for (int i = 0; i < this.divY; i++) | |
| { | |
| for (int j = 0; j < this.divX; j++) | |
| { | |
| gr.DrawLine(pen, j * maxWidth + r / 2, height - (i * maxWidth) - maxWidth + r / 2, j * maxWidth + r / 2, height - ((i + 1) * maxWidth) - maxWidth + r / 2); | |
| if (j < this.divX - 1) | |
| { | |
| gr.DrawLine(pen, j * maxWidth + r / 2, height - (i * maxWidth) - maxWidth + r / 2, (j + 1) * maxWidth + r / 2, height - (i * maxWidth) - maxWidth + r / 2); | |
| } | |
| if (j < (this.divX - 1) && i < (this.divY - 1)) | |
| { | |
| gr.DrawLine(pen, j * maxWidth + r / 2, height - ((i + 1) * maxWidth) - maxWidth + r / 2, (j + 1) * maxWidth + r / 2, height - (i * maxWidth) - maxWidth + r / 2); | |
| } | |
| } | |
| } | |
| for (int i = 0; i < this.divY; i++) | |
| { | |
| for (int j = 0; j < this.divX; j++) | |
| { | |
| gr.FillEllipse(Brushes.DarkOrange, j * maxWidth, height - (i * maxWidth) - maxWidth, r, r); | |
| gr.DrawString((j * (this.divY ) + i).ToString(), font, Brushes.Black, r + j * maxWidth, height - (i * maxWidth) - maxWidth); | |
| } | |
| } | |
| this.picture.Height = bmp.Height; | |
| this.picture.Width = bmp.Width; | |
| this.picture.Image = bmp; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment