Преглед изворни кода

Improve drawing

Isolate configurable parameters.
master
TheoryOfNekomata пре 3 година
родитељ
комит
78f1471cc6
1 измењених фајлова са 16 додато и 10 уклоњено
  1. +16
    -10
      GameOfLife/MainForm.cs

+ 16
- 10
GameOfLife/MainForm.cs Прегледај датотеку

@@ -1,11 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace GameOfLife
@@ -20,11 +15,13 @@ namespace GameOfLife
private Random random;
private int gridSize = 4;
private int gridSize = 8;
private int magicCells = 0;
private double density = 0.45;
private double density = 0.35;
private int interval = 500;
public MainForm(Rectangle bounds)
{
@@ -49,7 +46,7 @@ namespace GameOfLife
Cursor.Hide();
TopMost = true;
timer.Interval = 50;
timer.Interval = interval;
timer.Tick += new EventHandler(timer_Tick);
timer.Start();
}
@@ -159,20 +156,29 @@ namespace GameOfLife
}
private void Redraw(Graphics graphics) {
graphics.FillRectangle(Brushes.Black, Bounds);
List<Rectangle> liveCells = new List<Rectangle>();
List<Rectangle> deadCells = new List<Rectangle>();
for (var x = 0; x < newCells.GetLength(0); x++)
{
for (var y = 0; y < newCells.GetLength(1); y++)
{
if (newCells[x, y])
{
graphics.FillRectangle(Brushes.White, x * gridSize, y * gridSize, gridSize, gridSize);
liveCells.Add(new Rectangle(x * gridSize, y * gridSize, gridSize, gridSize));
}
else {
deadCells.Add(new Rectangle(x * gridSize, y * gridSize, gridSize, gridSize));
}
//else if (!newCells[x, y]) {
// graphics.FillRectangle(Brushes.Black, x * gridSize, y * gridSize, gridSize, gridSize);
//}
}
}
graphics.FillRectangle(Brushes.Black, Bounds);
//graphics.FillRectangles(Brushes.Black, deadCells.ToArray());
graphics.FillRectangles(Brushes.White, liveCells.ToArray());
}
private void MainForm_Paint(object sender, PaintEventArgs e)


Loading…
Откажи
Сачувај