How to create ASCII animation in Windows Console application using C#? -
i display non-flickery animation awesome linux command; sl
http://www.youtube.com/watch?v=9gymzkwjcyu
i appreciate small & stupid example of ... fly.
thanks!
just use console.setcursorposition
moving cursor position, console.write
character. before each frame have delete previous 1 overwriting spaces. heres little example built:
class program { static void main(string[] args) { char[] chars = new char[] { '.', '-', '+', '^', '°', '*' }; (int = 0; ; i++) { if (i != 0) { // delete previous char setting space console.setcursorposition(6 - (i-1) % 6 - 1, console.cursortop); console.write(" "); } // write new char console.setcursorposition(6 - % 6 - 1, console.cursortop); console.write(chars[i % 6]); system.threading.thread.sleep(100); } } }
you instance take animated gif, extract single frames/images (see how here), apply ascii transformation (how described here example) , print these frame frame in above code example.
update
just fun, implemented described. try out replacing @"c:\some_animated_gif.gif"
path (not large) animated gif. example take ajax loader gif here.
class program { static void main(string[] args) { image image = image.fromfile(@"c:\some_animated_gif.gif"); framedimension dimension = new framedimension( image.framedimensionslist[0]); int framecount = image.getframecount(dimension); stringbuilder sb; // remember cursor position int left = console.windowleft, top = console.windowtop; char[] chars = { '#', '#', '@', '%', '=', '+', '*', ':', '-', '.', ' ' }; (int = 0; ; = (i + 1) % framecount) { sb = new stringbuilder(); image.selectactiveframe(dimension, i); (int h = 0; h < image.height; h++) { (int w = 0; w < image.width; w++) { color cl = ((bitmap)image).getpixel(w, h); int gray = (cl.r + cl.g + cl.b) / 3; int index = (gray * (chars.length - 1)) / 255; sb.append(chars[index]); } sb.append('\n'); } console.setcursorposition(left, top); console.write(sb.tostring()); system.threading.thread.sleep(100); } } }
Comments
Post a Comment