| 1 | // Copyright 2005 by Anthony Liekens [email protected] |
| 2 | |
| 3 | #include "coordinate.h" |
| 4 | #include "stars.h" |
| 5 | #include "canvas.h" |
| 6 | |
| 7 | // ##### STAR METHODS ##### |
| 8 | |
| 9 | Star::Star() { |
| 10 | c.setX( (double)rand() / RAND_MAX ); |
| 11 | c.setY( (double)rand() / RAND_MAX ); |
| 12 | brightness = rand() % ( 255 - 70 ); |
| 13 | } |
| 14 | |
| 15 | void |
| 16 | Star::render( ) const { |
| 17 | Canvas::drawStar(c.getXMapped(), c.getYMapped(), brightness); |
| 18 | } |
| 19 | |
| 20 | // ##### STARS METHODS ##### |
| 21 | |
| 22 | Stars::Stars() { |
| 23 | } |
| 24 | |
| 25 | Stars::Stars( int n ) { |
| 26 | addStars( n ); |
| 27 | } |
| 28 | |
| 29 | void |
| 30 | Stars::addStars( int n ) { |
| 31 | for( int i = 0; i < n; i++ ) |
| 32 | push_back( Star() ); |
| 33 | } |
| 34 | |
| 35 | void |
| 36 | Stars::render( ) const { |
| 37 | for( const_iterator i = begin(); i != end(); i++ ) |
| 38 | i->render( ); |
| 39 | } |
| 40 |