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 2 · posted by vaibhav bhawsar Sep 21, 05:28
Problem 2. Create a function called drawCircle that takes as arguments a radius (float), a number of points (int) and a center point (Vec2d) and draws a circle as specified. Demonstrate that this function works by using it in the following ways:
a. Draw 5 circles in a row, each with increasing radii (10, 20, 30…), just touching each other, each composed of 30 points.
b. Draw 5 regular polygons in a row, each with an increasing number of points (3, 4, 5…), each with a radius of 50 pixels.
void drawCircle ( Vec2d c, int r, int numberOfPoints) {
glBegin(GL_POLYGON);
glColor3f(0,0,0);
for(int i=0;i < numberOfPoints;i++){
float angle = 2*PI / numberOfPoints * i;
float x = sin(angle) * r;
float y = cos(angle) * r;
Vec2d p(x,y);
p = p+c;
glVertex2f(p.x,p.y);
}
glEnd();
}
//also draws the regular polygons
void drawTouchingCircles()
{
int numberOfCircles = 5;
int nPoints = 29;
Vec2d origin(100,100);
for(int i=0; i<=numberOfCircles; i++)
{
float r = i*20;//radius
float dx = (r*2)-20;//offset
Vec2d shift(dx,0);
origin = origin+shift;
origin.print();
//draw circles touching each other
drawCircle(origin,r,nPoints);
//draw polygons with varying points
drawCircle(Vec2d(i*100,300),50,i+2);
}
}
Commenting is closed for this article.
Compform Assignment 2 - Problem 1 CompForm Assignment 2 - Problem 3




