▲ ▲ ▲ Steemit logo in 3D [128 lines of code]

in #steemit7 years ago (edited)

Hello, Steemians!
And today I want to share with you my art work devoted to Steemit.
As you know I had animation hobby in my childhood. And I want to remember that old nice days :-)
Besides, now I know some graphic programming libraries and that should really help.
I can teach you Open GL if you want. Write in comments if you want tutorials!

Introduce to you animated wireframe logo:

yes.gif

Isn't it nice? But the post would be boring if I didn't leave the code. Here it is:

#include <glut.h>
#include <math.h>

float SecretSteemArray[] = {
 -0.0300,  0.7067, 0.0000,
 -0.1067,  0.6600, 0.0000,
 -0.0444,  0.5778, 0.0000,
 -0.1844,  0.5756, 0.0000,
 -0.0411,  0.4811, 0.0000,
 -0.2411,  0.5044, 0.0000,
 -0.0333,  0.4178, 0.0000,
 -0.2744,  0.4178, 0.0000,
 -0.0111,  0.3522, 0.0000,
 -0.2722,  0.3400, 0.0000,
  0.0589,  0.1989, 0.0000,
 -0.2267,  0.1867, 0.0000,
  0.1289,  0.0544, 0.0000,
 -0.1644,  0.0411, 0.0000,
  0.1967, -0.0933, 0.0000,
 -0.1022, -0.0867, 0.0000,
  0.2456, -0.2144, 0.0000,
 -0.0378, -0.2144, 0.0000,
  0.2733, -0.3056, 0.0000,
  0.0122, -0.3300, 0.0000,
  0.2778, -0.3722, 0.0000,
  0.0400, -0.4200, 0.0000,
  0.2667, -0.4200, 0.0000,
  0.0411, -0.5178, 0.0000,
  0.2256, -0.4889, 0.0000,
  0.0156, -0.6167, 0.0000,
  0.1544, -0.5789, 0.0000,
 -0.0056, -0.7156, 0.0000,
  0.0744, -0.6600, 0.0000,  //28
 -0.0300,  0.7067, 0.2000,
 -0.1067,  0.6600, 0.2000,
 -0.0444,  0.5778, 0.2000,
 -0.1844,  0.5756, 0.2000,
 -0.0411,  0.4811, 0.2000,
 -0.2411,  0.5044, 0.2000,
 -0.0333,  0.4178, 0.2000,
 -0.2744,  0.4178, 0.2000,
 -0.0111,  0.3522, 0.2000,
 -0.2722,  0.3400, 0.2000,
  0.0589,  0.1989, 0.2000,
 -0.2267,  0.1867, 0.2000,
  0.1289,  0.0544, 0.2000,
 -0.1644,  0.0411, 0.2000,
  0.1967, -0.0933, 0.2000,
 -0.1022, -0.0867, 0.2000,
  0.2456, -0.2144, 0.2000,
 -0.0378, -0.2144, 0.2000,
  0.2733, -0.3056, 0.2000,
  0.0122, -0.3300, 0.2000,
  0.2778, -0.3722, 0.2000,
  0.0400, -0.4200, 0.2000,
  0.2667, -0.4200, 0.2000,
  0.0411, -0.5178, 0.2000,
  0.2256, -0.4889, 0.2000,
  0.0156, -0.6167, 0.2000,
  0.1544, -0.5789, 0.2000,
 -0.0056, -0.7156, 0.2000,
  0.0744, -0.6600, 0.2000, //57
};

void resize(int width, int height) {
    glutReshapeWindow( 1000, 1000 );
}

void DrawTriangle(float xc, float yc, float zc, float xs, float ys, float zs, int i, int j, int k)
{
    glBegin(GL_TRIANGLES);
    glVertex3f( xc + xs * SecretSteemArray[3*i], yc + ys * SecretSteemArray[3*i+1], zc + zs * SecretSteemArray[3*i+2]  );  
    glVertex3f( xc + xs * SecretSteemArray[3*j], yc + ys * SecretSteemArray[3*j+1], zc + zs * SecretSteemArray[3*j+2]  );  
    glVertex3f( xc + xs * SecretSteemArray[3*k], yc + ys * SecretSteemArray[3*k+1], zc + zs * SecretSteemArray[3*k+2]  );  
    glEnd();
}

void DrawPart(float xc, float yc, float zc, float xs, float ys, float zs)
{
    for(int i = 0; i <= 26; ++i)
        DrawTriangle(xc, yc, zc, xs, ys, zs, i, i+1, i+2);
    for(int i = 29; i <= 55; ++i)
        DrawTriangle(xc, yc, zc, xs, ys, zs, i, i+1, i+2);
    for(int i = 0; i <= 26; ++i){
        DrawTriangle(xc, yc, zc, xs, ys, zs, i, i+2, i+29);
        DrawTriangle(xc, yc, zc, xs, ys, zs, i+2, i+29, i+31); }

    DrawTriangle(xc, yc, zc, xs, ys, zs, 0, 1, 29);
    DrawTriangle(xc, yc, zc, xs, ys, zs, 27, 28, 57);
    DrawTriangle(xc, yc, zc, xs, ys, zs, 29, 30, 1);
    DrawTriangle(xc, yc, zc, xs, ys, zs, 56, 57, 27);
}
void Draw()
{
    glPolygonMode(GL_FRONT, GL_LINE);
    glPolygonMode(GL_BACK, GL_LINE);
    glColor3f(75/255.0 , 162/255.0 , 242/255.0 );
    DrawPart(0, 0, 0, 1, 1, 1);
    glColor3f(26/255.0 , 80/255.0 , 153/255.0 );
    DrawPart(-0.4, 0, 0, 0.75, 0.75, 0.75);
    DrawPart( 0.4, 0, 0, 0.75, 0.75, 0.75);
}
void renderScene(void) {

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glEnable(GL_DEPTH_TEST);
    Draw();
    glutPostRedisplay();
    glutSwapBuffers();
}
void keyPressed (unsigned char key, int x, int y) {  
    glRotatef(10.0f, 0.0f, 1.0f, 0.0f);
    glutPostRedisplay();
}  

int main(int argc, char **argv) {
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
    glutInitWindowPosition(50, 50);
    glutInitWindowSize(1000, 1000);
    glutCreateWindow("Steemit 11/9/17");
    glClearColor( 0, 0, 0, 1);
    glutDisplayFunc(renderScene);
    glutReshapeFunc(resize);
    glutKeyboardFunc(keyPressed);
    glutMainLoop();
    return 1;
}

Write in comments if you want a full tutorial!

Thank you for your attention :-)
Follow @ideamaker for more!

Sort:  

This is a really interesting work. I hope that I will see more inspiring thinks like that in the fewture!!! Have a great day fellow coder

Thank you :-)

Coin Marketplace

STEEM 0.21
TRX 0.20
JST 0.034
BTC 91841.68
ETH 3134.29
USDT 1.00
SBD 3.07