computational form (22),
everybityoumake (12),
play (12),
information (11),
atoz (10),
processingtext (10),
nime (9),
mobility (8),
thesis (8),
fabricatinginformation (7),
interactivesound (7),
mapping (6),
locative (5),
fall2007 (4),
ubicomp (4),
blah (3),
isco (3),
pcomp (3),
assistive technologies (1),
design thinking (1)
CompForm Assignment 2 - Problem 4 · posted by vaibhav bhawsar Sep 21, 05:30
Problem 4. Create a function called drawStar that takes as arguments an inner radius (float), an outer radius (float), a number of points (int), and a center point (Vec2d) and draws a star as specified. Demonstrate that this function works by drawing 100 stars with a varying number of points placed randomly about the screen. Feel free to change the background color for a more dramatic effect.
void drawStar(Vec2d c)
{
int innerRadius = 70;
int outerRadius = 90;
int numberOfPoints = 30;
Vec2d center(c.x,c.y);
Vec2d p;
glBegin(GL_TRIANGLE_FAN);
glVertex2f(center.x,center.y);
for(int i=0; i < numberOfPoints+1 ; i++)
{
float angle = 2 * PI / numberOfPoints * i;
if ( i % 2 ) {
p.x = cos(angle) * innerRadius;
p.y = sin(angle) * innerRadius;
} else {
p.x = cos(angle) * outerRadius;
p.y = sin(angle) * outerRadius;
}
p = center + p;
glVertex2f(p.x,p.y);
}
glEnd();
}
void drawStarField()
{
for( int i=0 ; i < 10 ; i++ )
{
int w = rand() % windowW; //printf("%d \n",w);
int h = rand() % windowH; //printf("%d \n",w);
drawStar(Vec2d(w,h));
}
}
Commenting is closed for this article.
CompForm Assignment 2 - Problem 3 CompForm Assignment 2 - Problem 5




