Skip to content

Instantly share code, notes, and snippets.

@Measter
Last active August 29, 2015 13:56
Show Gist options
  • Save Measter/8997014 to your computer and use it in GitHub Desktop.
Save Measter/8997014 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
namespace ConsoleTestApp
{
class Program
{
private static readonly Font TxtFont = new Font( FontFamily.GenericMonospace, 10 );
private static readonly SolidBrush TxtBrush = new SolidBrush( Color.Black );
private static readonly SolidBrush BorderBrush = new SolidBrush( Color.FromArgb( 255, 230, 230, 230 ) );
private static readonly SolidBrush[] Brushes = new[]
{
new SolidBrush( Color.FromArgb( 50, 255, 0, 0 ) ) ,
new SolidBrush( Color.FromArgb( 50, 0, 0, 255 ) )
};
private const int VERT_RUNS = 10;
private const int HOR_RUNS = 5;
private const int MULT = 15;
private const int SPACING = 10;
private const int CELLS = 10;
private const int ROWS = 2;
static void Main( string[] args )
{
Random rand = new Random();
Bitmap bmp = new Bitmap( ( CELLS * MULT * HOR_RUNS ) + ( ( HOR_RUNS - 1 ) * SPACING ),
( ROWS * VERT_RUNS * MULT ) + ( ( VERT_RUNS - 1 ) * SPACING ) );
Graphics g = Graphics.FromImage( bmp );
g.FillRectangle( new SolidBrush( Color.White ), 0, 0, bmp.Width, bmp.Height );
// Borders
for( int i = 1; i < HOR_RUNS; i++ )
{
int x = ( i * MULT * CELLS ) + ( i * SPACING ) - SPACING;
g.FillRectangle( BorderBrush, x, 0, SPACING, bmp.Height );
}
for( int i = 1; i < VERT_RUNS; i++ )
{
int y = ( i * MULT * ROWS ) + ( i * SPACING ) - SPACING;
g.FillRectangle( BorderBrush, 0, y, bmp.Width, SPACING );
}
for( int x = 0; x < HOR_RUNS; x++ )
{
for( int y = 0; y < VERT_RUNS; y++ )
{
GenerateRolls( rand, g, y, x );
}
}
g.Dispose();
bmp.Save( "rand.png", ImageFormat.Png );
bmp.Dispose();
}
private static void GenerateRolls( Random rand, Graphics g, int vertOffset, int horOffset )
{
int startY = ( vertOffset * ROWS * MULT ) + ( vertOffset * SPACING );
int startX = ( horOffset * MULT * CELLS ) + ( horOffset * SPACING );
for( int row = 0; row < ROWS; row++ )
{
int[] vals = new int[CELLS];
for( int i = 0; i < CELLS; i++ )
{
int x = rand.Next( CELLS );
g.FillRectangle( Brushes[row], startX + ( x * MULT ), startY + ( row * MULT ), MULT, MULT );
vals[x]++;
}
for( int i = 0; i < CELLS; i++ )
{
g.DrawString( vals[i].ToString(), TxtFont, TxtBrush, startX + ( i * MULT ), startY + ( row * MULT ) );
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment