5 ms·
Donut math: how donut.c works (2011)
- kevinjohnson 13y agoDefinitely worth checking out! Some fascinating code and math to create animated ASCII art.
- deletes 13y agoReplace line printf("\x1b[H") with you system specific screen clearing function if you don't have POSIX.
- JoeAcchino 13y agoHow do I compile this? GCC complains: CFLAGS="-g -pipe" make -k donut cc -g -pipe donut.c -o donut donut.c:1:2: warning: data definition has no type or storage class [enabled by default] donut.c: In function ‘main’: donut.c:4:16: warning: incompatible implicit declaration of built-in function ‘printf’ [enabled by default] donut.c:5:12: warning: incompatible implicit declaration of built-in function ‘memset’ [enabled by default] donut.c:9:63: error: ‘s’ undeclared (first use in this function) donut.c:9:63: note: each undeclared identifier is reported only once for each function it appears in donut.c:10:18: error: expected ‘,’ or ‘;’ before ‘in’ donut.c:11:32: error: ‘t’ undeclared (first use in this function) make: *** [donut] Errore 1 Compilation exited abnormally with code 2 at Thu Jan 23 16:11:12
- dominicgs 13y agoI had no problems using: gcc -o donut donut.c -lm You may also have errors in your version of donut.c, try copying the version from http://www.a1k0n.net/2006/09/15/obfuscated-c-donut.html http://www.a1k0n.net/2006/09/15/obfuscated-c-donut.html
- johnrob 13y agoMerge lines 9 and 10, so that s\ in(... becomes sin(...
- gurtwo 13y agoI've ported it to Python: https://gist.github.com/reeesga/8580649 https://gist.github.com/reeesga/8580649
- cglace 13y agoWhen I run this with pypy it is far too fast to see what is going on.
- jheriko 13y agoslightly disappointing - the effect is interesting but the implementation and derivation are sloppy. using a z buffer is a little unexciting i was expecting something raytracy or voxely - maybe even scanliney... but thats too much to explain in this comment. also using the matrices for deriving the torus equation... its much simpler to create a rotating basis intuitively with cos and sin then apply them again to create a circle going around... then rotate the torus as a separate operation before applying the 3d projection e.g. start with x = R*cos(t); y = R*sin(t); to define the big circle - note that ( cos(t), sin(t), 0 ) is the normal to that circle and use that to create the circles winding around with a second parameter: x = r*cos(t)*cos(u) + R*cos(t) y = r*sin(t)*cos(u) + R*sin(t) z = r*sin(u) set u = n * t and then you get the torus shape with a single parameter where the spiral around the surface closes up on itself. the 3d rotation of the whole object can be kept separate and done on a per axis basis (since using only two angle this is actually less operations as well) you end up with the same result but no need to do any particularly challenging algebra.
- tptacek 13y agoIf learning more about 3D rendering means I'm going to end up being disappointed by donut.c, I think I'm going to put off learning more about 3D rendering.
- jheriko 13y agoi was hoping to find something clever or interesting. thats not a reason to not continue trying to learn
- NAFV_P 13y ago> If learning more about 3D rendering means I'm going to end up being disappointed by donut.c, I think I'm going to put off learning more about 3D rendering. A topologist: "You can easily screw yourself up in three dimensions, but you need at least five to unscrew yourself."
- pohl 13y agoThis sounds like your ticket to IOCCC 2014 fame & fortune.
- tptacek 13y agoAnd here's the beginning of a1k0n's MSP430 port: https://gist.github.com/a1k0n/8582230 https://gist.github.com/a1k0n/8582230 :)
- deleted 13y ago[deleted]
- dpham 13y agoI read that article awhile ago, used the character brightness representation idea to build a JavaScript image/webcam/video to ascii converter http://dph.am/jscii/ http://dph.am/jscii/ https://github.com/EnotionZ/jscii https://github.com/EnotionZ/jscii
- binji 13y agoI ported this to Lua as a PNaCl demo: https://gonativeclient.appspot.com/demo/lua https://gonativeclient.appspot.com/demo/lua Click the "Donut" button, and press enter.