Last active
March 20, 2025 10:45
-
-
Save nst/ee47099f49816d20c07d3e286938fc96 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/Sleep {5000000 {} repeat } def | |
/P 50 def | |
/X 250 def | |
/Y 200 def | |
% rotation angles | |
/a 0 def | |
/b 0 def | |
/c 0 def | |
{ | |
% axis | |
100 Y moveto 400 Y lineto X 50 moveto X 350 lineto 0.5 setgray stroke | |
% vertices | |
/v[ | |
[P neg P neg P neg] | |
[P P neg P neg] | |
[P P P neg] | |
[P neg P P neg] | |
[P neg P neg P] | |
[P P neg P] | |
[P P P] | |
[P neg P P] | |
]def | |
/v2 8 array def | |
% sines/cosines | |
/c1 a cos def | |
/c2 b cos def | |
/c3 c cos def | |
/s1 a sin def | |
/s2 b sin def | |
/s3 c sin def | |
% projections | |
0 1 7 { | |
/i exch def | |
/p v i get def | |
/x p 0 get def | |
/y p 1 get def | |
/z p 2 get def | |
% rotations | |
/ty y c1 mul z s1 mul sub def | |
/tz y s1 mul z c1 mul add def | |
/tx x c2 mul tz s2 mul add def | |
/tz tz c2 mul x s2 mul sub def | |
/nx tx c3 mul ty s3 mul sub def | |
/ny tx s3 mul ty c3 mul add def | |
v2 i [ X nx add Y ny sub ] put | |
} for | |
% draw edges | |
[[0 1][1 2][2 3][3 0][4 5][5 6][6 7][7 4][0 4][1 5][2 6][3 7]] { | |
/e exch def | |
v2 e 0 get get 0 get v2 e 0 get get 1 get moveto | |
v2 e 1 get get 0 get v2 e 1 get get 1 get lineto | |
} forall | |
1 0 0 setrgbcolor stroke | |
flushpage | |
Sleep | |
1 setgray 0 0 400 400 rectfill % clear | |
/a a 0.2 add def | |
/b b 0.4 sub def | |
/c c 0.6 sub def | |
} loop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment