Brownian tree/C++ animated: Difference between revisions

m
no edit summary
mNo edit summary
Line 16:
 
//--------------------------------------------------------------------------------------------------
classstruct point
{
point() int: ax(0), inty(0) b ) { x = a; y = b; { }
public:
point() int a, int b ) : x(a), y(b) { x = y = 0; }
point( int a, int b ) { x = a; y = b; }
void set( int a, int b ) { x = a; y = b; }
int x, y;
Line 26 ⟶ 25:
 
//--------------------------------------------------------------------------------------------------
classstruct movers
{
public:
point pos;
bool moving;
Line 86 ⟶ 84:
BITMAPINFO infoheader;
BITMAP bitmap;
DWORD* dwpBits;
DWORD wb;
HANDLE file;
 
GetObject( bmp, sizeof( bitmap ), &bitmap );
 
DWORD* dwpBits = new DWORD[bitmap.bmWidth * bitmap.bmHeight];
ZeroMemory( dwpBits, bitmap.bmWidth * bitmap.bmHeight * sizeof( DWORD ) );
ZeroMemory( &infoheader, sizeof( BITMAPINFO ) );
Line 111 ⟶ 107:
GetDIBits( hdc, bmp, 0, height, ( LPVOID )dwpBits, &infoheader, DIB_RGB_COLORS );
 
HANDLE file = CreateFile( path.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
WriteFile( file, &fileheader, sizeof( BITMAPFILEHEADER ), &wb, NULL );
WriteFile( file, &infoheader.bmiHeader, sizeof( infoheader.bmiHeader ), &wb, NULL );
Line 120 ⟶ 116:
}
 
HDC getDC() const { return hdc; }
int getWidth() const { return width; }
int getHeight() const { return height; }
 
private:
Line 167 ⟶ 163:
void drawGrid()
{
DWORD clr;
BYTE g;
_bmp.clear();
 
Line 175 ⟶ 168:
for( int x = 0; x < MAX_SIDE; x++ )
{
BYTE g = _grid[x][y];
if( g != NONE )
{
DWORD clr = g > MOVER ? _color[g - 2] : RGB( 0, 255, 0 );
SetPixel( _bmp.getDC(), x, y, clr );
}
Line 200 ⟶ 193:
m->moving = true;
int x = MAX_SIDE - MAX_SIDE / 2, y = MAX_SIDE / 4, a, b;
do
while( true )
{
a = rand() % x + y; b = rand() % x + y;
} while if( _grid[a][b] =!= NONE ) break;
}
 
m->pos.set( a, b );
Line 212 ⟶ 204:
void startMovers()
{
movers* m;
for( int c = 0; c < MAX_MOVERS; c++ )
{
movers* m = &_movers[c];
addMover( m );
}
Line 263 ⟶ 254:
void moveMovers()
{
movers* mm;
bool found = false;
for( int m = 0; m < MAX_MOVERS; m++ )
{
movers* mm = &_movers[m];
if( !mm->moving ) continue;
found = true;
Anonymous user