Last active
March 13, 2021 15:28
-
-
Save daschr/5b33234997071284c35c127fec3868f1 to your computer and use it in GitHub Desktop.
DS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <math.h> | |
#include <unistd.h> | |
#include <string.h> | |
void rotate(float *l, double deg, float *n); | |
int main(void) | |
{ | |
float d[] = {-6.,-17.,0.,-5.,-17.,0.,-4.,-17.,0.,-3.,-17.,0.,-2.,-17.,0.,-1.,-17.,0.,0.,-17.,0.,1.,-17.,0.,2.,-17.,0.,3.,-17.,0.,4.,-17.,0.,5.,-17.,0.,6.,-17.,0.,-6.,-18.,0.,-5.,-18.,0.,-4.,-18.,0.,-3.,-18.,0.,-2.,-18.,0.,-1.,-18.,0.,0.,-18.,0.,1.,-18.,0.,2.,-18.,0.,3.,-18.,0.,4.,-18.,0.,5.,-18.,0.,6.,-18.,0.,-2.,-7.,0.,-2.,-6.,0.,-1.,-6.,0.,0.,-6.,0.,1.,-6.,0.,2.,-6.,0.,2.,-7.,0.,-1.,-5.,0.,0.,-5.,0.,1.,-5.,0.,-6.,-16.,0.,-6.,-15.,0.,-6.,-14.,0.,-6.,-13.,0.,-5.,-12.,0.,-5.,-11.,0.,-4.,-11.,0.,-4.,-11.,0.,-4.,-10.,0.,-4.,-9.,0.,-3.,-9.,0.,-3.,-8.,0.,-3.,-7.,0.,6.,-16.,0.,6.,-15.,0.,6.,-14.,0.,6.,-13.,0.,5.,-12.,0.,5.,-11.,0.,5.,-11.,0.,4.,-11.,0.,4.,-10.,0.,4.,-9.,0.,3.,-9.,0.,3.,-8.,0.,3.,-7.,0.,-4.,-1.,0.,-3.,-1.,0.,-2.,-1.,0.,-4.,0.,0.,-3.,0.,0.,-2.,0.,0.,-6.,5.,0.,-6.,6.,0.,-6.,7.,0.,-6.,8.,0.,-6.,9.,0.,-6.,10.,0.,-6.,11.,0.,-6.,12.,0.,-5.,1.,0.,-5.,2.,0.,-5.,3.,0.,-5.,4.,0.,-5.,5.,0.,-5.,6.,0.,-5.,11.,0.,-5.,12.,0.,-5.,13.,0.,-5.,14.,0.,-5.,15.,0.,-5.,16.,0.,0.,5.,0.,0.,6.,0.,0.,7.,0.,0.,8.,0.,0.,9.,0.,0.,10.,0.,0.,11.,0.,0.,12.,0.,-1.,1.,0.,-1.,2.,0.,-1.,3.,0.,-1.,4.,0.,-1.,5.,0.,-1.,6.,0.,6.,5.,0.,6.,6.,0.,6.,7.,0.,6.,8.,0.,6.,9.,0.,6.,10.,0.,6.,11.,0.,6.,12.,0.,5.,1.,0.,5.,2.,0.,5.,3.,0.,5.,4.,0.,5.,5.,0.,5.,6.,0.,5.,11.,0.,5.,12.,0.,5.,13.,0.,5.,14.,0.,5.,15.,0.,5.,16.,0.,1.,11.,0.,1.,12.,0.,1.,13.,0.,1.,14.,0.,1.,15.,0.,1.,16.,0.,4.,17.,0.,3.,17.,0.,2.,17.,0.,4.,18.,0.,3.,18.,0.,2.,18.,0.}; | |
int n = sizeof(d) / sizeof(float); | |
float ax[]= {1.f, 0.f, 0.f, 0.f, 1.f, 0.f, 1.f/sqrt(3.), 1.f/sqrt(3.), 1.f/sqrt(3.)}; | |
for (;;) { | |
for(float *a=ax; a<ax+9; a+=3) { | |
for(int i=0; i<360; ++i) { | |
printf("\x1b[2J\x1b[36m"); | |
for (float *v = d; v < d+n; v += 3) { | |
rotate(v, (1.0 / 180.0) * M_PI, a); | |
printf("\x1b[%d;%df#", (int)(*v + 21.5f), (int)(v[1] + 30.5f)); | |
} | |
fflush(stdout); | |
usleep(3500); | |
} | |
} | |
} | |
return 0; | |
} | |
void rotate(float *l, double deg, float *n) | |
{ | |
float R[3][3] = { { | |
n[0] * n[0] + (1 - n[0] * n[0]) * cos(deg), | |
n[0] * n[1] * (1 - cos(deg)) - n[2] * sin(deg), | |
n[0] * n[2] * (1 - cos(deg)) + n[1] * sin(deg) | |
},{ | |
n[0] * n[1] * (1 - cos(deg)) + n[2] * sin(deg), | |
n[1] * n[1] + (1 - n[1] * n[1]) * cos(deg), | |
n[1] * n[2] * (1 - cos(deg)) - n[0] * sin(deg) | |
},{ | |
n[0] * n[2] * (1 - cos(deg)) - n[1] * sin(deg), | |
n[1] * n[2] * (1 - cos(deg)) + n[0] * sin(deg), | |
n[2] * n[2] + (1 - n[2] * n[2]) * cos(deg) | |
} | |
}; | |
float res[3] = { 0.0f }; | |
for (int i = 0; i < 3; ++i) | |
for (int j = 0; j < 3; ++j) | |
res[i] += R[j][i] * l[j]; | |
memcpy(l, res, sizeof(float)*3); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment