In addition to the VGA donut , I submitted two other entries in the Tiny Tapeout 8 demo competition , where you submit a 'tiny' ASIC design (room for about 4000 logic gates) that outputs 2-bit RGB to a VGA port and 1-bit audio to a speaker. One was a an old school C64/Amiga intro type of thing, and the other was a nyan cat. 'TT08' intro video unavailable Click to play -- video loops imperfectly…
[ Update 12/19/2025 : I got the chip, and it works! Here is a writeup of my other designs on this chip, as well as a picture of it in action] For many years after coming up with donut.c , I wondered in the back of my mind if it could be simplified somehow, like maybe there was a way to raytrace a donut with a small chunk of code. In October 2023, I tweeted a dumb random epiphany where I figured…
My DIYRobocars autonomous RC car has come a long way since my last post on the subject. I want to highlight a localization algorithm I came up with which works really well, at least in this specific setting. I've been using it in races for a while and it really stepped up the speeds I was able to achieve without the car getting 'lost' -- about 22mph on the front straight of this small track. It…
My little donut.c has been making the rounds again, after being featured in a couple YouTube videos (e.g., Lex Fridman and Joma Tech ). If I had known how much attention this code would get over the years, I would have spent more time on it. One thing that's always been sort of unfortunate is the heavy use of sin and cos -- both because it necessitates linking the math library ( -lm ), but also…
Since February 2016, I have been participating in DIYRobocars meetups here in the SF Bay Area, wherein a bunch of amateur roboticists compete in autonomous time trials with RC cars. I had been doing very well in the competition with essentially just a glorified line-following robot, but have lately upgraded to a full SLAM-like approach with a planned trajectory. In this series of posts I will try…
The Arduboy is a cute little credit-card sized Arduino-compatible with a 128x64 black and white OLED screen. It has 32kb of flash for program memory and 2560 bytes of RAM. (N.B.: this is 'reblogged' from my post on community.arduboy.com ) Over the Christmas break I put together a little demo which renders the Utah teapot (240 faces) at >30fps on the Arduboy, with 4x4 ordered dithering. Source code…
Play Load What is this thing? Hit the play button above and it will play music; specifically, music composed with (or at least, compatible with) a program released in 1994 called FastTracker 2; this is a Javascript homage I wrote in a fit of nostalgia. The source code is on GitHub if you'd like to check it out. Hit 'Load' to load a few other .XMs I have handy on my web host, or drag and drop an…
[ Update 1/13/2021 : I wrote a follow-up with some optimizations . ] There has been a sudden resurgence of interest in my 'donut' code from 2006 , and I've had a couple requests to explain this one. It's been five years now, so it's not exactly fresh in my memory, so I will reconstruct it from scratch, in great detail, and hopefully get approximately the same result. This is the code: k ; double…
[ Update 10/21/2015: Changed the title from 'six lines of C' to '462 bytes of C' to avoid endless arguments about what constitutes a line of C code.] [ Update 6/28/2011: added Javascript version; press button below to see the output without compiling the code.] [ Update 7/9/2011: if you're using a compiler other than gcc, you might need to put a #include <math.h> at the top for it to work…
[ Update 8/2/2011 : you can play against a dumbed-down Javascript version of the bot here .] I can't believe I won . I can't believe I won decisively at all. I've never won any programming contest before (although I did place in 3rd in the Mario AI contest but there were only about 10 entrants). Whenever I badly lose at an ICFP contest I'm always anxious to see the post mortems of the people who…
_ , x , y , o , N ; char b [ 1840 ] ; p ( n , c ) { for ( ; n - - ; x + + ) c = = 10 ? y + = 80 , x = o - 1 : x > = 0 ? 80 > x ? c ! = ' ~ ' ? b [ y + x ] = c : 0 : 0 : 0 ; } c ( q , l , r , o , v ) char * l , * r ; { for ( ; q > = 0 ; ) q = ( ' A ' ' YLrZ^ ' ' w^?EX ' ' novne ' ' bYV ' ' dO}LE ' ' {yWlw ' ' Jl_Ja|[ur]zovpu ' ' ' ' i]e|y ' ' ao_Be ' ' osmIg}r]]r]m|wkZU}{O} ' ' xys]] \ x|ya|y ' '…
(compile with gcc -o donut donut.c -lm , and it needs ANSI- or VT100-like emulation) How it works k ; double sin ( ) , cos ( ) ; main ( ) { float A = 0 , B = 0 , i , j , z [ 1760 ] ; char b [ 1760 ] ; printf ( ' \x1b [2J ' ) ; for ( ; ; ) { memset ( b , 32 , 1760 ) ; memset ( z , 0 , 7040 ) ; for ( j = 0 ; 6.28 > j ; j + = 0.07 ) for ( i = 0 ; 6.28 > i ; i + = 0.02 ) { float c = sin ( i ) , d =…