Today, I found a floppy disk with 5 programs that I wrote a very, very long time ago. Four of them can be run once just for fun. The two best ones, with textures and lighting, didn't run due to the video card, but here are the other two. (I combined them into one.) I wrote them in C, but later I also rewrote them in Pascal. If you look at them, be sure to press F7 during the process.
#include
#include
#include
#include
#include
float f, k, d;
int page, t;
struct Y
{
private:
float zindex ( int a )
{
int i;
float r=0;
switch(a)
{
case 12: for(i=0;i<12;i++) r+=z[i]; r/=12; break;
case 13: for(i=0;i<12;i++) r+=z[i+12]; r/=12; break;
case 11: r=(z[11]+z[0]+z[23]+z[12])/4; break;
default: r=(z[a]+z[a+1]+z[a+12]+z[a+13])/4; break;
}
return r;
}
void DrawFlatness( int a )
{
int i, z[24];
switch(a)
{
case 12:
if((x[11]-x[0])*(y[1]-y[0])-(x[1]-x[0])*(y[11]-y[0])>=0)
{
for(i=0;i<12;i++) { z[2*i]=x[i]+320; z[2*i+1]=150-y[i]; }
fillpoly(12, z);
} break;
case 13:
if((x[12]-x[23])*(y[13]-y[12])-(x[13]-x[12])*(y[12]-y[23])>=0)
{
for(i=0;i<12;i++) { z[2*i]=x[i+12]+320; z[2*i+1]=150-y[i+12]; }
fillpoly(12, z);
} break;
case 11:
if((x[0]-x[11])*(y[12]-y[0])-(x[12]-x[0])*(y[0]-y[11])>=0)
{
z[0]=x[11]+320;
z[1]=150-y[11];
z[2]=x[0]+320;
z[3]=150-y[0];
z[4]=x[12]+320;
z[5]=150-y[12];
z[6]=x[23]+320;
z[7]=150-y[23];
fillpoly(4, z);
} break;
default:
if((x[a+1]-x[a])*(y[a+13]-y[a+1])-(x[a+13]-x[a+1])*(y[a+1]-y[a])>=0)
{
z[0]=x[a]+320;
z[1]=150-y[a];
z[2]=x[a+12]+320;
z[3]=150-y[a+12];
z[4]=x[a+13]+320;
z[5]=150-y[a+13];
z[6]=x[a+1]+320;
z[7]=150-y[a+1];
fillpoly(4, z);
}
}
}
public:
float x[24], y[24], z[24];
Y ( void )
{
int i;
x[0]=-50; y[0]=70;
x[1]=-30; y[1]=70;
x[2]=-1; y[2]=20;
x[3]=17; y[3]=70;
x[4]=37; y[4]=70;
x[5]=-10; y[5]=-50;
x[6]=-12; y[6]=-53;
x[7]=-18; y[7]=-54;
x[8]=-25; y[8]=-53;
x[9]=-28; y[9]=-52;
x[10]=-29; y[10]=-50;
x[11]=-10; y[11]=0;
for(i=0;i<12;i++) z[i]=10;
for(i=12;i<24;i++)
{
x[i]=x[i-12];
y[i]=y[i-12];
z[i]=-z[i-12];
}
}
void draw (int T)
{
int i, j, k, m[14];
float p;
setvisualpage(page);
delay(d);
page=(page==0)?1:0;
setactivepage(page);
cleardevice();
if(T==1)
{
for(i=0;i<11;i++)
line(x[i]+320, 150-y[i], x[i+1]+320, 150-y[i+1]);
line(x[0]+320, 150-y[0], x[11]+320, 150-y[11]);
for(i=12;i<23;i++)
line(x[i]+320, 150-y[i], x[i+1]+320, 150-y[i+1]);
line(x[12]+320, 150-y[12], x[23]+320, 150-y[23]);
for(i=0;i<12;i++)
line(x[i]+320, 150-y[i], x[i+12]+320, 150-y[i+12]);
}
else
{
if(zindex(0)<zindex(1)) { m[0]=0; m[1]=1; } else { m[0]=1; m[1]=0; } for(i=2;i<14;i++) { for(j=0;jzindex(i)&&i<12&&i!=4) { for(k=i; k>j; k--) m[k]=m[k-1]; break; }
m[j]=i;
}
for(i=0;i<14;i++)
DrawFlatness(m[i]);
}
}
void increase ( void )
{
int i;
for(i=0;i<24;i++) { x[i]*=k; y[i]*=k; z[i]*=k; }
}
void rotate_z( void )
{
int i;
float xn[24], yn[24];
for(i=0;i<24;i++)
{
xn[i]=x[i]*cos(f)-y[i]*sin(f);
yn[i]=x[i]*sin(f)+y[i]*cos(f);
}
for(i=0;i<24;i++) { x[i]=xn[i]; y[i]=yn[i]; }
}
void rotate_y( void )
{
int i;
float xn[24], zn[24];
for(i=0;i<24;i++)
{
xn[i]=x[i]*cos(f)-z[i]*sin(f);
zn[i]=x[i]*sin(f)+z[i]*cos(f);
}
for(i=0;i<24;i++) { x[i]=xn[i]; z[i]=zn[i]; }
}
void rotate_x( void )
{
int i;
float yn[24], zn[24];
for(i=0;i<24;i++)
{
yn[i]=y[i]*cos(f)-z[i]*sin(f);
zn[i]=y[i]*sin(f)+z[i]*cos(f);
}
for(i=0;i<24;i++) { y[i]=yn[i]; z[i]=zn[i]; }
}
void MoveAlongAxisX(void)
{
int i;
for(i=0;i<24;i++)
x[i]+=f;
}
void MoveAlongAxisY(void)
{
int i;
for(i=0;i<24;i++)
y[i]+=f;
}
void MoveAlongAxisZ(void)
{
int i;
for(i=0;i<24;i++)
z[i]+=f;
}
};
void main (void)
{
Y y;
int key, K, gd=VGA, gm=1;
page=0; d=10; t=1;
l:
closegraph;
printf("Just press F1 to show this help any time\n");
printf("Press F5 to see the framework\n");
printf("Press F6 for deleting invisible lines\n");
printf("Press F7 for color facets\n");
printf("Press w to rotate the letter around axis z clockwise\n");
printf("Press q to rotate the letter around axis z anticlockwise\n");
printf("Press s to rotate the letter around axis x clockwise\n");
printf("Press a to rotate the letter around axis x anticlockwise\n");
printf("Press x to rotate the letter around axis y clockwise\n");
printf("Press z to rotate the letter around axis y anticlockwise\n");
printf("Press 1 to increase the letter\n");
printf("Press 2 to decrease the letter\n");
printf("Press e or r to move the letter along axis x\n");
printf("Press d or f to move the letter along axis y\n");
printf("Press c or v to move the letter along axis z\n");
printf("Press up or down to accelerate or decelerate moving and rotating\n");
printf("Press Enter to stop any moving\n");
printf("Press any key to begin to work with the letter imidiately\n");
getch(); key=-1;
initgraph(&gd, &gm, "");
for(;;)
{
if(kbhit()!=0) key=getch();
switch(key)
{
case '1': k=1.001; K=key; break;
case '2': k=0.999; K=key; break;
case 'q': f=0.005; K=key; break;
case 'w': f=-0.005; K=key; break;
case 'a': f=0.005; K=key; break;
case 's': f=-0.005;K=key; break;
case 'z': f=0.005; K=key; break;
case 'x': f=-0.005; K=key; break;
case 'e': f=0.5; K=key; break;
case 'r': f=-0.5; K=key; break;
case 'd': f=0.5; K=key; break;
case 'f': f=-0.5; K=key; break;
case 'c': f=0.5; K=key; break;
case 'v': f=-0.5; K=key; break;
case 27: closegraph(); return;
case 72: f+=0.005; k+=0.001; d=d>5?d-0.01:d; key=0; break;
case 80: f-=0.005; k-=0.001; d=d<15?d+0.01:d; key=0; break;
case 13: K=key; break;
case 63: t=1; key=0; break;
case 64: t=2; setfillstyle(1, 0); key=0; break;
case 65: t=2; setfillstyle(1, 2); key=0; break;
case 59: goto l;
}
switch(K)
{
case '1': y.increase(); break;
case '2': y.increase(); break;
case 'q': y.rotate_z(); break;
case 'w': y.rotate_z(); break;
case 'a': y.rotate_x(); break;
case 's': y.rotate_x(); break;
case 'z': y.rotate_y(); break;
case 'x': y.rotate_y(); break;
case 'e': y.MoveAlongAxisX(); break;
case 'r': y.MoveAlongAxisX(); break;
case 'd': y.MoveAlongAxisY(); break;
case 'f': y.MoveAlongAxisY(); break;
case 'c': y.MoveAlongAxisZ(); break;
case 'v': y.MoveAlongAxisZ(); break;
case 27: closegraph(); return;
}
y.draw(t);
}
}