Week 3 Assignment (desc)
Younghyun Chung
Problem 1.
Create a function that takes as input a wavelength in pixels (float) and an amplitude (float) and draws a series of crested (upward pointing) waves.
|
void drawCrestedWaves( float Wavelength, float Amplitude ) {
glBegin( GL_LINE_STRIP );
for( int i=0; i<1500; i++) {
int X = i;
int Y = Amplitude * fmod( X,Wavelength );
glColor3f( 1,0,0 );
glVertex2f( X, Y+500 );
}
glEnd();
glBegin( GL_LINE_STRIP );
for( int i=0; i<1500; i++) {
int X = i;
int Y = Amplitude * fmod( X,Wavelength );
glColor3f( 1,0,0 );
glVertex2f( 1500-X, Y+400 );
}
glEnd();
glBegin( GL_LINE_STRIP );
for( int i=0; i<1500; i++) {
int X = i;
int Y = Amplitude * fmod( X,Wavelength );
if ( Y < Amplitude*Wavelength/2 ) Y = Amplitude*Wavelength/2 - (Amplitude*Wavelength - Y);
glColor3f( 1,0,0 );
glVertex2f( X, Y+300 );
}
glEnd();
glBegin( GL_LINE_STRIP );
for( int i=0; i<1500; i++) {
int X = i;
int Y = Amplitude * fmod( X,Wavelength );
if ( Y < Amplitude*Wavelength/2 ) Y = Amplitude*Wavelength/2 + (Amplitude*Wavelength - Y);
glColor3f( 1,0,0 );
glVertex2f( X, Y+200 );
}
glEnd();
glBegin( GL_LINE_STRIP );
for( int i=0; i<1500; i++) {
int X = i;
float Y = Amplitude * fmod( X,Wavelength );
if ( Y < Amplitude*Wavelength/2 ) Y = Amplitude*Wavelength - Y;
glColor3f( 1,0,0 );
glVertex2f( X, Y+100 );
}
glEnd();
}
|
 several crested waves
|
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 drawHeartBeat( void ) {
float Amp1 = 150;
float Wavelength1 = 20; // the wave repeats at this many pixels
float Phase1 = 10; // shifting the wave left or right
float Amp2 = 100;
float Wavelength2 = 25;
float Phase2 = 5;
float Amp3 = 10;
float Wavelength3 = 360;
float Phase3 = 5;
float Amp4 = 10;
float Wavelength4 = 360;
float Phase4 = 15;
glBegin( GL_LINE_STRIP );
for( int i=0; i<1500; i++ ) {
float T = i;
float X = i;
float Y = Amp1 * sin_deg( X / Wavelength1 * 360.0 );
Y += Amp2 * sin_deg( X / Wavelength2 * 360.0 + Phase2 );
Y += Amp3 * sin_deg( X / Wavelength3 * 360.0 + Phase3 );
Y += Amp4 * sin_deg( X / Wavelength4 * 360.0 + Phase4 );
glVertex2f( X, Y+300 );
}
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 drawFlower ( int numPetals, float innerRadius, float petalLength ) {
int numPoints = 360;
glBegin( GL_LINE_LOOP );
for(int i=0; i<numPoints; i++ ) {
float A = i;
float Rad = innerRadius + petalLength * cos_deg( A * numPetals );
float X = cos_deg(A) * Rad;
float Y = sin_deg(A) * Rad;
glVertex2f( X+300, Y+300 );
}
glEnd();
}
|
 drawFlower(8,50,30)
 drawFlower(16,80,50)
|
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 drawFlatToothGear( int numTeeth, float innerRadius, float outerRadius ) {
int numPoints = 360;
glBegin( GL_LINE_LOOP );
float Radius;
for( int i=0; i<numPoints; i++ ) {
float A = 360.0 / numPoints * i; // angle from 0 to 360 degrees
int A_teeth = 360 / numTeeth; // angle for each tooth
if( fmod( A,A_teeth) < A_teeth/2) Radius = outerRadius;
else Radius = innerRadius;
float X = cos_deg(A) * Radius;
float Y = sin_deg(A) * Radius;
glColor3f( 1,0,0 );
glVertex2f( X+300, Y+300 );
}
glEnd();
}
|
 drawFlatToothGear(10,40,60)
 drawFlatToothGear(20,60,80)
|
Problem 6.
Find 3 photographs of either natural phenomena or industrial products that involve repeating contours or surface profiles, and create three functions to model each of them. Include the photographs in your assignment postings.
|
void drawAnnualRing() {
int numPoints = 360;
float Amp = 2;
float Frequency = 3;
glBegin( GL_LINE_LOOP );
for( int Radius=5; Radius<250; Radius+=6 ){
for( int i=0; i<numPoints; i++ ) {
float A = i;
float Rad = Radius + Amp * sin_deg( A * Frequency );
Rad += Amp * 2 * sin_deg (A * Frequency );
Rad += Amp * 2.5 * sin_deg (A * 2 );
Rad += Amp * 1.5 * sin_deg (A * 6 );
float X = cos_deg(A) * Rad;
float Y = sin_deg(A) * Rad;
if(Radius > 200) glColor3f( 0.7,0.5,0.3);
else glColor3f( 0.3,0.1,0 );
glVertex2f( X+300,Y+300 );
}
}
glEnd();
}
|
 annual ring. image from google image search
 annual ring of wood
|
Problem 7.
Generate either a line form or solid form that reflects your personality, and changes with the mouse position.
|
void drawNori ( float vibration ) {
int numPoints = 360;
if (mouseX < 100 || mouseX > windowW-100) vibration = 0;
float Radius = mouseY + vibration * 100;
float Amp = 2 * vibration;
float Frequency = rand()%4 * vibration +1;
glBegin( GL_LINE_LOOP );
for( int i=0; i<numPoints; i++ ) {
float A = i;
float Rad = Radius + Amp * sin_deg( A * Frequency * vibration);
Rad += Amp * 2 * sin_deg (A * Frequency * vibration);
Rad += Amp * 2.5 * sin_deg (A * Frequency *5* vibration);
Rad += Amp * 3.5 * sin_deg (A * Frequency *10 * vibration);
float X = cos_deg(A) * Rad;
float Y = sin_deg(A) * Rad;
glColor3f( 0.3,0.1,0 );
glVertex2f( X+windowW/2,Y+windowH/2 );
}
glEnd();
}
|
 start and end is circle, peace, etc.
called like below. five slightly different identity.
float vibration = mouseX/windowW;
if (mouseX < 100 || mouseX > windowW-100) vibration = 0;
drawNori( vibration * (rand()%3 + 1) );
drawNori( vibration * (rand()%3 + 1) );
drawNori( vibration * (rand()%3 + 1) );
drawNori( vibration * (rand()%3 + 1) );
drawNori( vibration * (rand()%3 + 1) );
 Moving mouseX, myself is vibrating, making a failure, learning, struggleing, etc
 Moving mouseY, getting bigger or smaller.
|
|