Sierpinski triangle/Graphical: Difference between revisions

Content added Content deleted
No edit summary
(small changes)
Line 474: Line 474:
private:
private:
void drawTri( HDC dc, float l, float t, float r, float b, int i ) {
void drawTri( HDC dc, float l, float t, float r, float b, int i ) {
float w = r - l, h = b - t;
float w = r - l, h = b - t, hh = h / 2.f, ww = w / 4.f;
if( i ) {
if( i ) {
drawTri( dc, l + w / 4.f, t, l + w / 4.f * 3.f, t + h / 2.f, i - 1 );
drawTri( dc, l + ww, t, l + ww * 3.f, t + hh, i - 1 );
drawTri( dc, l, t + h / 2.f, l + w / 2.f, t + h, i - 1 );
drawTri( dc, l, t + hh, l + w / 2.f, t + h, i - 1 );
drawTri( dc, l + w / 2.f, t + h / 2.f, l + w, t + h, i - 1 );
drawTri( dc, l + w / 2.f, t + hh, l + w, t + h, i - 1 );
}
}
float hh = h / 2.f, ww = w / 4.f; bmp.setPenColor( colors[i % 6] );
bmp.setPenColor( colors[i % 6] );
MoveToEx( dc, ( int )( l + ww ), ( int )( t + hh ), NULL );
MoveToEx( dc, ( int )( l + ww ), ( int )( t + hh ), NULL );
LineTo ( dc, ( int )( l + ww * 3.f ), ( int )( t + hh ) );
LineTo ( dc, ( int )( l + ww * 3.f ), ( int )( t + hh ) );
Line 494: Line 494:
}
}
</lang>
</lang>



=={{header|D}}==
=={{header|D}}==