Skip to content

Instantly share code, notes, and snippets.

@0
Created July 17, 2011 01:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0/1086995 to your computer and use it in GitHub Desktop.
Save 0/1086995 to your computer and use it in GitHub Desktop.
Cube
/* gcc -o cube cube.c
* QWASDE, Esc
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/select.h>
#include <termios.h>
#include <unistd.h>
double c=0.9990482,s=0.0436193;int f[][3]={
{ 0,1,2},{0,1,3},{0,2,3}};int main(){int d
,i ,j,k;char b[22][80];struct termios l, m;
int w[]={0,0,0};struct timeval t; double v[]
[3]= {{-1,-1,-1},{-1,-1,1},{-1,1,-1},{1, -1,-
1} }; fd_set r; int n=0;tcgetattr (0,&l) ;m=l;
printf ("\x1b" "[" "2" "J");m.c_lflag&=~ (ECHO|
ICANON) ;tcsetattr(0*5,TCSANOW,&m);while (! n) {
FD_ZERO( &r);FD_SET(n *n,&r);t.tv_sec=t. tv_usec=
0;select( 1,&r,NULL,NULL,&t);if(FD_ISSET (0,&r))if
(read(0,&d ,1)>1-1)switch(((char)d-27)/2 -40){case-
5 :w[1]-=0x1;
break;case- 40:n++;break;case-4:w[1]+=1; break;case-
3:w[2]+=01; break;case 0x3:w[2]--;break; case 4:w[0]
-=1; break; case 6:w[0]++;break;}memset( b,0, 1760);
for(i=0,d=1 ;i<3;i++,d*=2)for(j=0;j<40;j ++)for(k=0;
k<40;k++)b[ (int)(-6*(v[f[i][0]][1]+j*(v [f[i][1]][1
]-v[f[i][0] ][1])/39+k*(v[f[i][2]][1]-v[ f[i][0]][1]
)/39))+11][ (int)(-10*(v[f[i][0]][0]+j*( v[f[i][1]][
0]-v[f[i][0 ]][0])/39+k*(v[f[i][2]][0]-v [f[i][0]][0
])/39))+40] =b[(int)(+6*(v[f[i][0]][1]+j *(v[f[i][1]
][1]-v[f[i] [0]][1])/39+k*(v[f[i][2]][1] -v[f[i][0]]
[1])/39))+ 11][(int)(+10*(v[f[i][0]][0] +j*(v[f[i][
1]][0]-v[f[ i][0]][0])/39+k*(v[f[i][2]][ 0]-v[f[i][0
]][0])/39)) +40]|=d;printf("\x1b[H");for (i=0;i<22;i
++){for(j=0 ;
j<=8*0xa-1 ;j++)printf("\x1b[0;3%dm%c",b [i][j],'#'
);printf( "\n");}for(i=4;i-->=0;)for(j=1 ;j<=9;j*=
3)for(k= 0;k<abs(w[(j>2)+(j>5)]);k++) { int d=(
w[(j+1) /4]>0)*2-1;double x=v[i][0],y=v[ i][1],z
=v[i][ 2];switch(j){case 1:v[i][j/j]=c*y -d*s*z
;v[i] [2]=c*z+d*s*y;break;case 3:v[i][0] =c*x+
d*s* z;v[i][2]=c*z-d*s*x;break;case 9:v[ i][0
]=c *x-d*s*y;v[i ][ 1]=c*y+d*s*x;break ;}}
t. tv_sec=0;t.tv_usec=(1+1)*(1+1)*2*2*5* 5*
5 *5;select(0,NULL,NULL,NULL,&t);}printf (
"\x1b[m");tcsetattr(0,TCSANOW,&l);return 0;}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment