Comp Form: Week 3
Waves, gears, nature. . .
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 drawWaves(float wavelength, float amplitude, float phase){
glColor3f(1, 0, 0);
glBegin(GL_LINE_STRIP);
for (float i=0; i<2*PI*wavelength; i=i+.1) {
float x=i;
float y=sin(x*PI*2/wavelength)*amplitude + phase;
glVertex2f(10+x,y+windowH/2);
}
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 drawHeartbeat(float wavelength, float amplitude, float phase,float frequency){
glColor3f(1, 0, 0);
glBegin(GL_LINE_STRIP);
for (float i=0; i<2*PI*wavelength*frequency; i=i+.1) {
float x=i;
float y=sin(x*PI*2/wavelength)*amplitude + phase;
y=y+sin(x*PI*2/wavelength*.7)*amplitude + phase;
glVertex2f(10+x,y+windowH/2);
}
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(float r, float amplitude, float frequency, float phase){
glColor3f(1, 0, 0);
glBegin(GL_LINE_LOOP);
for(float i=0; i<PI*2; i=i+.01){
float A= i;
float rad=r+ amplitude*cos(A*frequency +phase);
float x= cos(A)*rad;
float y= sin(A)*rad;
glVertex2f(windowW/2+x,windowH/2+y);
}
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(float r1, float r2, float frequency, float phase){
glColor3f(1, 0, 0);
glBegin(GL_LINE_LOOP);
for(float i=0; i<PI*2; i=i+.01){
float A= i;
int step=int(i/3*frequency)%2;
float rad=r1+(r2-r1)*step;
float x= cos(A)*rad;
float y= sin(A)*rad;
glVertex2f(windowW/2+x,windowH/2+y);
}
glEnd();
}
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 drawBlob(float r, float amplitude, float frequency, float phase){
glColor3f(1, 0, 0);
glBegin(GL_LINE_LOOP);
for(int i=0; i<360; i++){
float A= radians(i);
float rad=r+ amplitude*cos(A*frequency +phase);
float x= cos(A)*rad+ amplitude*sin(A*frequency +phase);
float y= sin(A)*rad+amplitude* cos(A*2*frequency +phase);
glVertex2f(windowW/2+x,windowH/2+y);
}
glEnd();
}
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 inyour assignment postings
void drawNautilus(){
float x=0;
float y=0;
Vec2d arcPt[1200];
glColor3f(1,0,0);
glBegin(GL_LINE_STRIP);
for (int i=0;i<3.2*360;i++){
x=cos(radians(-i))*i*i*.00028;
y=sin(radians(-i))*i*i*.00028;
glVertex2f(windowW/2+x,windowH/2+y);
arcPt[i]=Vec2d(windowW/2+x,windowH/2+y);
}
glEnd();
glBegin(GL_LINES);
for (int i=0;i<3.2*360-360;i=i+20){
//drawArc(arcPt[i],arcPt[i+330], 100, 30);
glVertex2f(arcPt[i].x,arcPt[i].y);
glVertex2f(arcPt[i+330].x,arcPt[i+330].y);
}
glEnd();
}
//weave
void drawWeave(){
for (int i=0;i<windowW;i++){
for (int j=0;j<windowH;j++){
int x=i;
int y=j;
glBegin(GL_POINTS);
float mDist=dist(i,mouseX,j,mouseY);
float gradient=fabs(sin(radians(i*10+sin(radians(j/5+i+mDist))*80)))*.3+cos((radians(i*12+j/2)))*.2;
glColor3f(gradient, gradient, gradient);
glVertex2f(x,y);
}
}
glEnd();
}
//phylo
void drawPetal (int centerX,int centerY,float radX, float radY, float rot){
int numPoints=(radX+radY)/2;
if (numPoints<10){
numPoints=10;
}
Vec2d P;
Vec2d center(centerX,centerY);
glBegin(GL_TRIANGLE_FAN);
for (int i=0;i<numPoints;i++){
float A=2*PI/numPoints*i;
P.x=cos(A)*radX;
P.y=sin(A)*radY;
P=P+center;
glVertex2f(P.x,P.y);
}
glEnd();
}
float gm = 137.5077640500378; // golden
float spacer = 0.6176470588235294/2; // the incremental distance
float iNodeX = 1; // initial radius
float iNodeY = 1;
int iNode = 0;
int maxNodes=1000;
float currAngle = 0;
void drawPhylo(){
currAngle=0;
for (int i=-50;i<maxnodes;i++){></maxnodes;i++){>
spacer=.5;
currAngle += gm; // increase the angle by the gm
iNodeX = (spacer * i*.5) * sin(radians(currAngle))+ windowW/2; //radius * sin(angle) + the offset distance
iNodeY = (spacer * i*.5) * cos(radians(currAngle))+ windowH/2;
float scaleDot = currAngle / (gm*maxNodes); // value 0-1 based on distance from origin
float rad=sin(scaleDot*1.5)*10.5;
glColor3f(scaleDot,1-scaleDot,0);
drawPetal(iNodeX, iNodeY, rad ,rad, radians(currAngle)); // draws rectangle
}
}
Problem 7. Generate either a line form or solid form that reflects your personality, and changes with the mouse position.
- Published:
- 09.27.07 / 8pm
- Category:
- C, Comp Form, ITP, Work in Progress













No comments
Jump to comment form | comments rss [?] | trackback uri [?]