Положите два и два вместе:
#include <GL/glut.h>
#include <cmath>
void glSpiral(float a, float b, float thetaStart, float thetaEnd, unsigned int samples = 200 )
{
glBegin( GL_QUADS );
const float sz = 1.0f;
float dt = (thetaEnd - thetaStart) / (float)samples;
for( unsigned int i = 0; i <= samples; ++i )
{
// archimedean spiral
float theta = thetaStart + (i * dt);
float r = a + b * theta;
// polar to cartesian
float x = r * cos( theta );
float y = r * sin( theta );
glVertex2f( x - sz, y - sz );
glVertex2f( x + sz, y - sz );
glVertex2f( x + sz, y + sz );
glVertex2f( x - sz, y + sz );
}
glEnd();
}
size_t win_w = 0;
size_t win_h = 0;
double aspect_ratio = 0;
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-100*aspect_ratio, 100*aspect_ratio, -100, 100, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
const float PI = 3.14159;
for( unsigned int i = 0; i < 6; i++ )
{
switch( i )
{
case 0: glColor3ub(255,0,0); break;
case 1: glColor3ub(0,255,0); break;
case 2: glColor3ub(0,0,255); break;
case 3: glColor3ub(255,255,0); break;
case 4: glColor3ub(0,255,255); break;
case 5: glColor3ub(255,255,255); break;
default: glColor3ub(128,128,128); break;
}
float beg = (i+0)*2*PI;
float end = (i+1)*2*PI;
glSpiral( 0, 3, beg, end, 80 );
}
glFlush();
glutSwapBuffers();
}
void reshape(int w, int h)
{
win_w = w;
win_h = h;
aspect_ratio = (double)win_w / (double)win_h;
glViewport(0, 0, w, h);
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);
glutInitWindowSize(800,600);
glutCreateWindow("Spiral");
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}
Это в C ++ и GLUT, но переносит основную логикуЯва должна быть легкой.