Week 3 Assignment - Computational Forms
Lucas Longo
Problem 1. Create a function the takes as input a wavelength in pixels (float) and an amplitude (float) and draws a series of crested (upward pointing) waves.
|
void waveUpOnly(float wavelength, float amplitude){
glBegin(GL_LINE_STRIP);
for (int i= 0; i < 1000; i++){
float x = i;
float y = amplitude * d_sin(x / wavelength * frequency + phase);
y = fabs(y);
glVertex2f(x,y+shiftY);
}
glEnd();
} |
|
| Problem 2. Create a function that draws a repeating hearbeat pattern, as seen on an EKG. Do this by compositing a series of sin waves. |
void waveOnWave(float wavelength, float amplitude){
glBegin(GL_LINE_STRIP);
for (int i= 0; i < 1000; i++){
float x = i;
float y = amplitude * d_sin(x / wavelength * frequency + phase);
y += (amplitude*0.2) * d_sin(x / (wavelength*0.05) * frequency);
y += (amplitude*0.9) * d_sin(x / (wavelength*0.4) * frequency);
glVertex2f(x,y+shiftY);
}
glEnd();
} |
|
Problem 3. Create a function that takes as input a number of petals (int), an inner radius (float), and a petal length (float), and draws a daisy-like flower using a single continuous line loop. |
void drawPetals(int petals, float innerRadius, float petalLength){
glBegin(GL_LINE_LOOP);
for (int i= 0; i < numPoints; i++){
float A = 360 / numPoints * i;
float radius = petalLength + innerRadius * d_cos(A * petals);
x = d_cos(A)*radius;
y = d_sin(A)*radius;
glVertex2f(x+shiftX,y+shiftY);
}
glEnd();
} |
|
| Problem 4. Create a function that takes as input a number of teeth (int), an inner radius and an outer radius, and draws a flat-tooth gear as specified. |
void drawGear(int teeth, float innerRadius, float outterRadius){
glBegin(GL_LINE_LOOP);
for (int i= 0; i < numPoints; i++){
float A = 360 / numPoints * i;
int position = 360 / numPoints * i;
int repeat = 360/teeth;
if (position%repeat < repeat/2){
radius = innerRadius;
}
else {
radius = outterRadius;
}
x = d_cos(A)*radius;
y = d_sin(A)*radius;
glVertex2f(x+shiftX,y+shiftY);
}
glEnd();
} |
|
void drawGear(int teeth, float innerRadius, float outterRadius, Vec2d center, int direction){
GLfloat angle = direction;
glTranslatef(center.x,center.y,0);
glRotatef(angle,0,0,1);
glBegin(GL_LINE_LOOP);
for (int i= 0; i < numPoints; i++){
float A = 360 / numPoints * i;
int position = 360 / numPoints * i;
int repeat = 360/teeth;
if (position%repeat < repeat/2){
radius = innerRadius;
}
else {
radius = outterRadius;
}
x = d_cos(A)*radius;
y = d_sin(A)*radius;
glVertex2f(x,y);
}
glEnd();
glTranslatef(0,0,0);
}
void displayFunc ( void )
{
int teeth = 20;
float innerRadius = 200;
float outterRadius = innerRadius + 2*(innerRadius/teeth);
float shift;
Vec2d centerGear;
int direction; //1 for clockwise, 0 for couter-clockwise
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glLoadIdentity();
glColor3f( 1,1,1 );
innerRadius = 100;
outterRadius = innerRadius + 2*(innerRadius/teeth);
centerGear = Vec2d(outterRadius*d_cos(i)+windowW/2, outterRadius*d_sin(i)+windowH/2);
drawGear(teeth, innerRadius, outterRadius, centerGear, i);
glLoadIdentity();
glColor3f( 0,1,1 );
direction = 1;
shift = 180;
centerGear = Vec2d(outterRadius*d_cos(i2+shift)+windowW/2, outterRadius*d_sin(i2+shift)+windowH/2);
direction = 0;
drawGear(teeth, innerRadius, outterRadius, centerGear, i2);
i+=0.1;
i2+=0.1;
glutPostRedisplay();
glutSwapBuffers();
} |
Palying around with gears inspired by Tim's idea

|
Problem 5. Create a function that takes as input a seed number (int) and generates a random blobby form using a contouring function that combines three or more low-freqency sin waves. Be sure that the sin waves make complete cycles to ensure a smooth transition from the last point to the first. |
void blobby(int seed){
float noise = seed + rand()%seed;
float noise2 = noise/5;
float shift = 10;
shift += 0.0001;
printf("%f\n",noise);
glBegin(GL_LINE_LOOP);
for (int i= 0; i < 360; i++){
float A = i;
radius = 200 + 10*d_sin(A*noise2+noise+shift);
radius += 20*d_sin(A*noise2+noise);
radius += 20*d_sin(A*noise+noise2);
radius += 20*d_sin(A*noise+noise2);
x = radius * d_cos(A);
y = radius * d_sin(A);
glVertex2f(x+shiftX,y+shiftY);
}
glEnd();
} |
|
| Problem 6. Find a photographa of either natural phenomena or industrial products that involve repeating contours or surface profiles, and create a function to model it. Include the photograph in your assignment postings. |
void waveOnWave(float wavelength, float amplitude){
glBegin(GL_TRIANGLES);
for (int i= 0; i < 1000; i++){
float t = i;
float x = i;
float y = amplitude * d_sin(t / wavelength + phase);
y += (amplitude+i/4) * d_sin(t / wavelength*0.01);
y += (amplitude) * d_sin(t / wavelength*0.04 + t);
glColor3f(0,1,0);
glVertex2f(x,y+shiftY);
glColor3f(0,0, 1);
glVertex2f(x,0);
}
glEnd();
} |
Played first with rivers and mountain ranges:



|
| Problem 7. Generate either a line form or solid form that reflects your personality, and changes with the mouse position. |
void blobby(){
float noise = mouseX/windowW*100;
float noise2 = mouseY/windowH*100;
float shift = 10;
shift += 0.0001;
printf("%f\n",noise);
glBegin(GL_TRIANGLES);
for (int i= 0; i < 1000; i++){
float A = i;
radius = 200 + 10*d_sin(A*noise2+noise+shift);
radius += 20*d_sin(A*noise2+noise+shift*2);
radius += mouseX*d_sin(A*noise+noise2);
radius += mouseY*d_sin(A*noise+noise2);
x = radius * d_cos(A);
y = radius * d_sin(A);
glColor3f( 1,mouseX/windowW,0 );
glVertex2f(x+shiftX,y+shiftY);
glColor3f( 0,mouseY/windowH,1 );
glVertex2f(shiftX, shiftY);
}
glEnd();
} |
|
|