//LED.cs
//Class to return an image that looks like LED display of a number
//Written 17/10/01 By J O'Donnell - csharpconsulting@hotmail.com

using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
using System.IO;

namespace LEDCounter
{
	/// <summary>
	/// Summary description for LED.
	/// </summary>
	public class LED
	{
		public LED()
		{
			//
			// TODO: Add constructor logic here
			//
		}

		public Image CreateLEDDisplay(string number)
		{
			int start=0;
			int i=number.Length;
			Image j = new Bitmap(i*31,31);
			Graphics gt = Graphics.FromImage(j);

			for(int k=0;k<i;k++)
			{
				Image temp=new Bitmap(31,31);
				temp=CreateLEDDigit(Convert.ToInt32(number.Substring(k,1)));
				gt.DrawImage(temp,start,0);
				start=start+31;
			}		
			gt.Save();
			return(j);
		}

		public Image CreateLEDDigit(int val)
		{
			Image i = new Bitmap(31,31);
			Graphics g=Graphics.FromImage(i);
			
			if (val==0)
			{
				//TOP
				g.DrawLine(new Pen(Color.SeaGreen),5,2,27,2);
				g.DrawLine(new Pen(Color.Green),4,3,28,3);
				g.DrawLine(new Pen(Color.SeaGreen),5,4,27,4);

				//BOTTOM
				g.DrawLine(new Pen(Color.SeaGreen),5,28,27,28);
				g.DrawLine(new Pen(Color.Green),4,29,28,29);
				g.DrawLine(new Pen(Color.SeaGreen),5,30,27,30); 

				//TOP LEFT
				g.DrawLine(new Pen(Color.SeaGreen),2,5,2,14);	
				g.DrawLine(new Pen(Color.Green),3,4,3,15);
				g.DrawLine(new Pen(Color.SeaGreen),4,5,4,14);
				
				//TOP RIGHT
				g.DrawLine(new Pen(Color.SeaGreen),28,5,28,14);
				g.DrawLine(new Pen(Color.Green),29,4,29,15);
				g.DrawLine(new Pen(Color.SeaGreen),30,5,30,14);

				//BOTTOM RIGHT
				g.DrawLine(new Pen(Color.SeaGreen),30,18,30,27);
				g.DrawLine(new Pen(Color.Green),29,17,29,28);
				g.DrawLine(new Pen(Color.SeaGreen),28,18,28,27);
				
				//BOTTOM LEFT
				g.DrawLine(new Pen(Color.SeaGreen),2,18,2,27);
				g.DrawLine(new Pen(Color.Green),3,17,3,28);
				g.DrawLine(new Pen(Color.SeaGreen),4,18,4,27);
			}					
			
			if (val==1)
			{
				//TOP RIGHT
				g.DrawLine(new Pen(Color.SeaGreen),28,5,28,14);
				g.DrawLine(new Pen(Color.Green),29,4,29,15);
				g.DrawLine(new Pen(Color.SeaGreen),30,5,30,14);

				//BOTTOM RIGHT
				g.DrawLine(new Pen(Color.SeaGreen),30,18,30,27);
				g.DrawLine(new Pen(Color.Green),29,17,29,28);
				g.DrawLine(new Pen(Color.SeaGreen),28,18,28,27);
			}
			
			if (val==2)
			{
				//TOP
				g.DrawLine(new Pen(Color.SeaGreen),5,2,27,2);
				g.DrawLine(new Pen(Color.Green),4,3,28,3);
				g.DrawLine(new Pen(Color.SeaGreen),5,4,27,4);

				//MIDDLE
				g.DrawLine(new Pen(Color.SeaGreen),5,15,27,15);
				g.DrawLine(new Pen(Color.Green),4,16,28,16);
				g.DrawLine(new Pen(Color.SeaGreen),5,17,27,17);

				//BOTTOM
				g.DrawLine(new Pen(Color.SeaGreen),5,28,27,28);
				g.DrawLine(new Pen(Color.Green),4,29,28,29);
				g.DrawLine(new Pen(Color.SeaGreen),5,30,27,30); 

			
				//TOP RIGHT
				g.DrawLine(new Pen(Color.SeaGreen),28,5,28,14);
				g.DrawLine(new Pen(Color.Green),29,4,29,15);
				g.DrawLine(new Pen(Color.SeaGreen),30,5,30,14);
				
				//BOTTOM LEFT
				g.DrawLine(new Pen(Color.SeaGreen),2,18,2,27);
				g.DrawLine(new Pen(Color.Green),3,17,3,28);
				g.DrawLine(new Pen(Color.SeaGreen),4,18,4,27);
			}		
		
			if (val==3)
			{
				//TOP
				g.DrawLine(new Pen(Color.SeaGreen),5,2,27,2);
				g.DrawLine(new Pen(Color.Green),4,3,28,3);
				g.DrawLine(new Pen(Color.SeaGreen),5,4,27,4);

				//MIDDLE
				g.DrawLine(new Pen(Color.SeaGreen),5,15,27,15);
				g.DrawLine(new Pen(Color.Green),4,16,28,16);
				g.DrawLine(new Pen(Color.SeaGreen),5,17,27,17);

				//BOTTOM
				g.DrawLine(new Pen(Color.SeaGreen),5,28,27,28);
				g.DrawLine(new Pen(Color.Green),4,29,28,29);
				g.DrawLine(new Pen(Color.SeaGreen),5,30,27,30); 
				
				//TOP RIGHT
				g.DrawLine(new Pen(Color.SeaGreen),28,5,28,14);
				g.DrawLine(new Pen(Color.Green),29,4,29,15);
				g.DrawLine(new Pen(Color.SeaGreen),30,5,30,14);

				//BOTTOM RIGHT
				g.DrawLine(new Pen(Color.SeaGreen),30,18,30,27);
				g.DrawLine(new Pen(Color.Green),29,17,29,28);
				g.DrawLine(new Pen(Color.SeaGreen),28,18,28,27);			
			}
			
			if (val==4)
			{
				//MIDDLE
				g.DrawLine(new Pen(Color.SeaGreen),5,15,27,15);
				g.DrawLine(new Pen(Color.Green),4,16,28,16);
				g.DrawLine(new Pen(Color.SeaGreen),5,17,27,17);

				//TOP LEFT
				g.DrawLine(new Pen(Color.SeaGreen),2,5,2,14);	
				g.DrawLine(new Pen(Color.Green),3,4,3,15);
				g.DrawLine(new Pen(Color.SeaGreen),4,5,4,14);
				
				//TOP RIGHT
				g.DrawLine(new Pen(Color.SeaGreen),28,5,28,14);
				g.DrawLine(new Pen(Color.Green),29,4,29,15);
				g.DrawLine(new Pen(Color.SeaGreen),30,5,30,14);

				//BOTTOM RIGHT
				g.DrawLine(new Pen(Color.SeaGreen),30,18,30,27);
				g.DrawLine(new Pen(Color.Green),29,17,29,28);
				g.DrawLine(new Pen(Color.SeaGreen),28,18,28,27);
			}
			
			if (val==5)
			{
				//TOP
				g.DrawLine(new Pen(Color.SeaGreen),5,2,27,2);
				g.DrawLine(new Pen(Color.Green),4,3,28,3);
				g.DrawLine(new Pen(Color.SeaGreen),5,4,27,4);

				//MIDDLE
				g.DrawLine(new Pen(Color.SeaGreen),5,15,27,15);
				g.DrawLine(new Pen(Color.Green),4,16,28,16);
				g.DrawLine(new Pen(Color.SeaGreen),5,17,27,17);

				//BOTTOM
				g.DrawLine(new Pen(Color.SeaGreen),5,28,27,28);
				g.DrawLine(new Pen(Color.Green),4,29,28,29);
				g.DrawLine(new Pen(Color.SeaGreen),5,30,27,30); 

				//TOP LEFT
				g.DrawLine(new Pen(Color.SeaGreen),2,5,2,14);	
				g.DrawLine(new Pen(Color.Green),3,4,3,15);
				g.DrawLine(new Pen(Color.SeaGreen),4,5,4,14);

				//BOTTOM RIGHT
				g.DrawLine(new Pen(Color.SeaGreen),30,18,30,27);
				g.DrawLine(new Pen(Color.Green),29,17,29,28);
				g.DrawLine(new Pen(Color.SeaGreen),28,18,28,27);			
			}	

			if (val==6)
			{
				//TOP
				g.DrawLine(new Pen(Color.SeaGreen),5,2,27,2);
				g.DrawLine(new Pen(Color.Green),4,3,28,3);
				g.DrawLine(new Pen(Color.SeaGreen),5,4,27,4);

				//MIDDLE
				g.DrawLine(new Pen(Color.SeaGreen),5,15,27,15);
				g.DrawLine(new Pen(Color.Green),4,16,28,16);
				g.DrawLine(new Pen(Color.SeaGreen),5,17,27,17);

				//BOTTOM
				g.DrawLine(new Pen(Color.SeaGreen),5,28,27,28);
				g.DrawLine(new Pen(Color.Green),4,29,28,29);
				g.DrawLine(new Pen(Color.SeaGreen),5,30,27,30); 

				//TOP LEFT
				g.DrawLine(new Pen(Color.SeaGreen),2,5,2,14);	
				g.DrawLine(new Pen(Color.Green),3,4,3,15);
				g.DrawLine(new Pen(Color.SeaGreen),4,5,4,14);

				//BOTTOM RIGHT
				g.DrawLine(new Pen(Color.SeaGreen),30,18,30,27);
				g.DrawLine(new Pen(Color.Green),29,17,29,28);
				g.DrawLine(new Pen(Color.SeaGreen),28,18,28,27);
				
				//BOTTOM LEFT
				g.DrawLine(new Pen(Color.SeaGreen),2,18,2,27);
				g.DrawLine(new Pen(Color.Green),3,17,3,28);
				g.DrawLine(new Pen(Color.SeaGreen),4,18,4,27);
			}
			
			if (val==7)
			{
				//TOP
				g.DrawLine(new Pen(Color.SeaGreen),5,2,27,2);
				g.DrawLine(new Pen(Color.Green),4,3,28,3);
				g.DrawLine(new Pen(Color.SeaGreen),5,4,27,4);
				
				//TOP RIGHT
				g.DrawLine(new Pen(Color.SeaGreen),28,5,28,14);
				g.DrawLine(new Pen(Color.Green),29,4,29,15);
				g.DrawLine(new Pen(Color.SeaGreen),30,5,30,14);

				//BOTTOM RIGHT
				g.DrawLine(new Pen(Color.SeaGreen),30,18,30,27);
				g.DrawLine(new Pen(Color.Green),29,17,29,28);
				g.DrawLine(new Pen(Color.SeaGreen),28,18,28,27);
			}
			
			if (val==8)
			{
				//TOP
				g.DrawLine(new Pen(Color.SeaGreen),5,2,27,2);
				g.DrawLine(new Pen(Color.Green),4,3,28,3);
				g.DrawLine(new Pen(Color.SeaGreen),5,4,27,4);

				//MIDDLE
				g.DrawLine(new Pen(Color.SeaGreen),5,15,27,15);
				g.DrawLine(new Pen(Color.Green),4,16,28,16);
				g.DrawLine(new Pen(Color.SeaGreen),5,17,27,17);

				//BOTTOM
				g.DrawLine(new Pen(Color.SeaGreen),5,28,27,28);
				g.DrawLine(new Pen(Color.Green),4,29,28,29);
				g.DrawLine(new Pen(Color.SeaGreen),5,30,27,30); 

				//TOP LEFT
				g.DrawLine(new Pen(Color.SeaGreen),2,5,2,14);	
				g.DrawLine(new Pen(Color.Green),3,4,3,15);
				g.DrawLine(new Pen(Color.SeaGreen),4,5,4,14);
				
				//TOP RIGHT
				g.DrawLine(new Pen(Color.SeaGreen),28,5,28,14);
				g.DrawLine(new Pen(Color.Green),29,4,29,15);
				g.DrawLine(new Pen(Color.SeaGreen),30,5,30,14);

				//BOTTOM RIGHT
				g.DrawLine(new Pen(Color.SeaGreen),30,18,30,27);
				g.DrawLine(new Pen(Color.Green),29,17,29,28);
				g.DrawLine(new Pen(Color.SeaGreen),28,18,28,27);
				
				//BOTTOM LEFT
				g.DrawLine(new Pen(Color.SeaGreen),2,18,2,27);
				g.DrawLine(new Pen(Color.Green),3,17,3,28);
				g.DrawLine(new Pen(Color.SeaGreen),4,18,4,27);
			}
			
			if (val==9)
			{
				//TOP
				g.DrawLine(new Pen(Color.SeaGreen),5,2,27,2);
				g.DrawLine(new Pen(Color.Green),4,3,28,3);
				g.DrawLine(new Pen(Color.SeaGreen),5,4,27,4);

				//MIDDLE
				g.DrawLine(new Pen(Color.SeaGreen),5,15,27,15);
				g.DrawLine(new Pen(Color.Green),4,16,28,16);
				g.DrawLine(new Pen(Color.SeaGreen),5,17,27,17);

				//BOTTOM
				g.DrawLine(new Pen(Color.SeaGreen),5,28,27,28);
				g.DrawLine(new Pen(Color.Green),4,29,28,29);
				g.DrawLine(new Pen(Color.SeaGreen),5,30,27,30); 

				//TOP LEFT
				g.DrawLine(new Pen(Color.SeaGreen),2,5,2,14);	
				g.DrawLine(new Pen(Color.Green),3,4,3,15);
				g.DrawLine(new Pen(Color.SeaGreen),4,5,4,14);
				
				//TOP RIGHT
				g.DrawLine(new Pen(Color.SeaGreen),28,5,28,14);
				g.DrawLine(new Pen(Color.Green),29,4,29,15);
				g.DrawLine(new Pen(Color.SeaGreen),30,5,30,14);

				//BOTTOM RIGHT
				g.DrawLine(new Pen(Color.SeaGreen),30,18,30,27);
				g.DrawLine(new Pen(Color.Green),29,17,29,28);
				g.DrawLine(new Pen(Color.SeaGreen),28,18,28,27);
			}

			g.Save();
			return(i);
		}
	}
}
