#include <GL/glut.h>
#include <stdlib.h>
double vertex[][3] = {
// first pentagon
{-1.00000000, -1.00000000, 1.00000000}, { 0.00000000, -0.61803399, 1.61803399},
{ 0.00000000, 0.61803399, 1.61803399}, {-1.00000000, 1.00000000, 1.00000000},
{-1.61803399, 0.00000000, 0.61803399},
// second pentagon
{ 0.00000000, -0.61803399, 1.61803399}, { 1.00000000, -1.00000000, 1.00000000},
{ 1.61803399, 0.00000000, 0.61803399}, { 1.00000000, 1.00000000, 1.00000000},
{ 0.00000000, 0.61803399, 1.61803399},
// third pentagon
{ 0.00000000, 0.61803399, 1.61803399}, { 1.00000000, 1.00000000, 1.00000000},
{ 0.61803399, 1.61803399, 0.00000000}, {-0.61803399, 1.61803399, 0.00000000},
{-1.00000000, 1.00000000, 1.00000000},
// forth pentagon
{-1.61803399, 0.00000000, 0.61803399}, {-1.00000000, 1.00000000, 1.00000000},
{-0.61803399, 1.61803399, 0.00000000}, {-1.00000000, 1.00000000, -1.00000000},
{-1.61803399, 0.00000000, -0.61803399},
// fifth pentagon
{ 1.00000000, 1.00000000, 1.00000000}, { 1.61803399, 0.00000000, 0.61803399},
{ 1.61803399, 0.00000000, -0.61803399}, { 1.00000000, 1.00000000, -1.00000000},
{ 0.61803399, 1.61803399, 0.00000000},
// sixth pentagon
{-0.61803399, 1.61803399, 0.00000000}, { 0.61803399, 1.61803399, 0.00000000},
{ 1.00000000, 1.00000000, -1.00000000}, { 0.00000000, 0.61803399, -1.61803399},
{-1.00000000, 1.00000000, -1.00000000},
// seventh pentagon
{-1.61803399, 0.00000000, -0.61803399}, {-1.00000000, 1.00000000, -1.00000000},
{ 0.00000000, 0.61803399, -1.61803399}, { 0.00000000, -0.61803399, -1.61803399},
{-1.00000000, -1.00000000, -1.00000000},
// eighth pentagon
{ 0.00000000, 0.61803399, -1.61803399}, { 1.00000000, 1.00000000, -1.00000000},
{ 1.61803399, 0.00000000, -0.61803399}, { 1.00000000, -1.00000000, -1.00000000},
{ 0.00000000, -0.61803399, -1.61803399},
// ninth pentagon
{-1.00000000, -1.00000000, 1.00000000}, { 0.00000000, -0.61803399, 1.61803399},
{ 1.00000000, -1.00000000, 1.00000000}, { 0.61803399, -1.61803399, 0.00000000},
{-0.61803399, -1.61803399, 0.00000000},
// tenth pentagon
{-1.00000000, -1.00000000, 1.00000000}, {-0.61803399, -1.61803399, 0.00000000},
{-1.00000000, -1.00000000, -1.00000000}, {-1.61803399, 0.00000000, -0.61803399},
{-1.61803399, 0.00000000, 0.61803399},
// eleventh pentagon
{ 0.61803399, -1.61803399, 0.00000000}, { 1.00000000, -1.00000000, 1.00000000},
{ 1.61803399, 0.00000000, 0.61803399}, { 1.61803399, 0.00000000, -0.61803399},
{ 1.00000000, -1.00000000, -1.00000000},
// twelveth pentagon
{-0.61803399, -1.61803399, 0.00000000}, { 0.61803399, -1.61803399, 0.00000000},
{ 1.00000000, -1.00000000, -1.00000000}, { 0.00000000, -0.61803399, -1.61803399},
{-1.00000000, -1.00000000, -1.00000000}};
double r = 0;
short cxWidth, nStarWidth;
unsigned char cStar[64 * 64 * 3]; // star buffer
bool bstop = false;
void resize(int width, int height)
{
double rate = (double)nStarWidth;
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-1 * rate, rate, -1 * rate, rate, -1 * rate, rate);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glutPostRedisplay();
}
void display(void)
{
short i, j, k;
double dx = -7.9225, dy = 7.6775, dcw = 0.2475; // proper charactor location
double center[3];
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(1, 1, 1, 1);
glColor3d(0, 0, 0);
glPushMatrix();
glRotated(r, 3, 2, 1);
glScaled(1 / 2.75, 1 / 2.75, 1 / 2.75); // proper scaling
for(i = 0; i < 12; i++) {
center[0] = 0; center[1] = 0; center[2] = 0;
for(j = 0; j < 5; j++) {
center[0] += vertex[i * 5 + j][0];
center[1] += vertex[i * 5 + j][1];
center[2] += vertex[i * 5 + j][2];
}
center[0] = center[0] / 5 * 2;
center[1] = center[1] / 5 * 2;
center[2] = center[2] / 5 * 2;
for(j = 0; j < 5; j++) {
glBegin(GL_TRIANGLES);
glVertex3d(center[0], center[1], center[2]);
glVertex3d(vertex[i * 5 + j][0], vertex[i * 5 + j][1], vertex[i * 5 + j][2]);
glVertex3d(vertex[i * 5 + (j + 1) % 5][0], vertex[i * 5 + (j + 1) % 5][1], vertex[i * 5 + (j + 1) % 5][2]);
glEnd();
}
}
glPopMatrix();
glReadPixels((cxWidth / 2) - 32, (cxWidth / 2) - 32, 64, 64, GL_RGB, GL_UNSIGNED_BYTE, cStar);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(1, 1, 1, 1);
for(i = 0; i < 64; i++) {
for(j = 0; j < 64; j++) {
if(!cStar[(i * 64 + j) * 3]) {
glRasterPos2d(dx + dcw * j, dy - dcw * i);
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, '*');
}
}
}
glutSwapBuffers();
if(!bstop) r++;
}
void key(unsigned char key, int x, int y)
{
switch (key)
{
case 27 :
case 'q':
exit(0);
break;
case ' ':
bstop = !bstop;
break;
}
glutPostRedisplay();
}
void idle(void)
{
glutPostRedisplay();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
nStarWidth = glutBitmapWidth(GLUT_BITMAP_8_BY_13, '*');
cxWidth = 64 * nStarWidth;
glutInitWindowSize(cxWidth, cxWidth);
glutInitWindowPosition(10, 10);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("active star printer");
glutReshapeFunc(resize);
glutDisplayFunc(display);
glutKeyboardFunc(key);
glutIdleFunc(idle);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glutMainLoop();
return EXIT_SUCCESS;
}