#include “stdlib.h"
void CMyView::OnDraw(CDC* pDC)
{
CMyDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CRect rc;
GetClientRect(&rc);
for(int i=0;i<1000;i++)
{
int cx=MapRand(rc.Width());
int cy=MapRand(rc.Height());
pDC->SetPixel(cx,cy,GetRandomColor(cx,cy));
}
SetTimer(1,100,NULL);
// TODO: add draw code for native data here
}
COLORREF CMyView::GetRandomColor(int x, int y)
{
long red,blue,green;
int cx,cy;
CRect rc;
GetClientRect(&rc);
cx=rc.Width();
cy=rc.Height();
red=y*255/cy;
blue=((cy-y)*255/cy+x*255/cx)/2;
green=((cx-x)*255/cx+(cy-y)*255/cy)/2;
return RGB(red+MapRand(2),blue+MapRand(2),green+MapRand(2));
}
void CMyView::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CClientDC dc(this);
OnDraw(&dc);
//
CView::OnTimer(nIDEvent);
}
int CMyView::MapRand(int nMax)
{
int t=rand()%nMax;
return t;
}