I always say “A picture is worth a thousand words” and so I sometimes use ascii art in comments. For example when writing code for a 2D-game, I have written a funtion, which returns an id for the next edge of a rectangle, and also a function which returns the sector, when the rectangle is divided into 4 triangles. The C-code looks like this:
/* o-------> x | | (left, top) _____ | | | v | | |_____| y (right, bottom) */ struct rect { double left, top, right bottom; }; enum face { TOP, RIGHT, BOTTOM, LEFT }; /* ___________ |', ,'| | ',___,' | | ,' ', | |,'_______',| */ enum face getNextEdge(double x, double y, struct rect* r) { enum face f = TOP; double dist = y - r->top; double dist2 = r->right - x; if(dist2 < dist) { dist = dist2; f = RIGHT; }; dist2 = r->bottom - y; if(dist2 < dist) { dist = dist2; f = DOWN; }; dist2 = x - r->left; if(dist2 < dist) { dist = dist2; f = LEFT; }; return f; }, /* ___________ |'-_ _-'| | '-_-' | | _-' '-_ | |-'_______'-| */ enum face getSector(double x, double y, struct rect* r) { // ... };
What do you think of ascii art in comments? And where did you use ascii art?