// kl1View.cpp : implementation of the CKl1View class
//

#include "stdafx.h"
#include "kl1.h"

#include "kl1Doc.h"
#include "kl1View.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CKl1View

IMPLEMENT_DYNCREATE(CKl1View, CView)

BEGIN_MESSAGE_MAP(CKl1View, CView)
	//{{AFX_MSG_MAP(CKl1View)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CKl1View construction/destruction

CKl1View::CKl1View()
{
	// TODO: add construction code here

}

CKl1View::~CKl1View()
{
}

BOOL CKl1View::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CKl1View drawing

void CKl1View::OnDraw(CDC* pDC)
{
	int iW,iH,ix1,iy1;

	int Gd, Gm ;
    int J1[10000];
    int J2[10000];
    int Kode[7];
    int i,j,n,m,Mn,L,Sum,Lmax ;



	CKl1Doc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	static int Sum_0_Color = { RGB(127,127,127) };
	static int Sum_1_Color = { RGB(233,13,1) };
	static int Sum_2_Color = { RGB(19,3,240) };

	CBrush  Sum_0_brush;
	CBrush  Sum_1_brush;
	CBrush  Sum_2_brush;
	CBrush* oldbrush;

	POINT pnt;

	CPen    Sum_0_pen;
	CPen    Sum_1_pen;
	CPen    Sum_2_pen;
	CPen*   oldpen;

	Sum_0_brush.CreateHatchBrush(HS_CROSS, Sum_0_Color);
	Sum_0_pen.CreatePen(PS_SOLID,1,Sum_0_Color);

	Sum_1_brush.CreateHatchBrush(HS_CROSS, Sum_1_Color);
	Sum_1_pen.CreatePen(PS_SOLID,1,Sum_1_Color);

	Sum_2_brush.CreateHatchBrush(HS_CROSS, Sum_2_Color);
	Sum_2_pen.CreatePen(PS_SOLID,1,Sum_2_Color);

	iW = pDC->GetDeviceCaps(HORZRES);
	iH = pDC->GetDeviceCaps(VERTRES);

	Lmax=iW;

	  Kode[0]=0;
	  Kode[1]=1;
	  Kode[2]=2;
	  Kode[3]=0;
	  Kode[4]=2;
	  Kode[5]=1;
	  Kode[6]=0;

		for (i=0; i<Lmax; i++)
		{
			J1[i]=0;
			J2[i]=0;
		}

	  J1[Lmax / 2] =1;

	for (i=1; i<iH-1; i++)
	{
		for (j=1; j<Lmax-1; j++)
		{
            Sum = J1[j] + J1[j-1] + J1[j+1];

			if (Sum==6) { J2[j]=Kode[0]; }
			if (Sum==5) { J2[j]=Kode[1]; }
			if (Sum==4) { J2[j]=Kode[2]; }
			if (Sum==3) { J2[j]=Kode[3]; }
			if (Sum==2) { J2[j]=Kode[4]; }
			if (Sum==1) { J2[j]=Kode[5]; }
			if (Sum==0) { J2[j]=Kode[6]; }

            if (J2[j]==0) { 
						//		oldpen = pDC->SelectObject(&Sum_0_pen);
						//		oldbrush =  pDC->SelectObject(&Sum_0_brush);
						//		pDC->Ellipse(j,i,j+1,i+1); 
							}
		    if (J2[j]==1) { 
								oldpen = pDC->SelectObject(&Sum_1_pen);
								oldbrush =  pDC->SelectObject(&Sum_1_brush);
//								pDC->Ellipse(j,i,j+1,i+1); 
								pnt.x=j;
								pnt.y=i;
								pDC->SetPixel(pnt,Sum_1_Color);
							}
            if (J2[j]==2) { 
								oldpen = pDC->SelectObject(&Sum_2_pen);
								oldbrush =  pDC->SelectObject(&Sum_2_brush);
//								pDC->Ellipse(j,i,j+1,i+1); 
								pnt.x=j;
								pnt.y=i;
								pDC->SetPixel(pnt,Sum_2_Color);
						}

		}
		for (j=0; j<Lmax; j++)
		{
			J1[j]=J2[j];
			J2[j]=0;
		}
	}





	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CKl1View diagnostics

#ifdef _DEBUG
void CKl1View::AssertValid() const
{
	CView::AssertValid();
}

void CKl1View::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CKl1Doc* CKl1View::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CKl1Doc)));
	return (CKl1Doc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CKl1View message handlers
