{{ message }}

Instantly share code, notes, and snippets.

# msimpson/cfire

Created Jul 21, 2011
Curses based ASCII art fire animation.
 #!/usr/bin/python import curses, random screen = curses.initscr() width = screen.getmaxyx() height = screen.getmaxyx() size = width*height char = [" ", ".", ":", "^", "*", "x", "s", "S", "#", "\$"] b = [] curses.curs_set(0) curses.start_color() curses.init_pair(1,0,0) curses.init_pair(2,1,0) curses.init_pair(3,3,0) curses.init_pair(4,4,0) screen.clear for i in range(size+width+1): b.append(0) while 1: for i in range(int(width/9)): b[int((random.random()*width)+width*(height-1))]=65 for i in range(size): b[i]=int((b[i]+b[i+1]+b[i+width]+b[i+width+1])/4) color=(4 if b[i]>15 else (3 if b[i]>9 else (2 if b[i]>4 else 1))) if(i9 else b[i])], curses.color_pair(color) | curses.A_BOLD ) screen.refresh() screen.timeout(30) if (screen.getch()!=-1): break curses.endwin()

### j4cobgarby commented Jan 16, 2018

 how does this work?

### msimpson commented Aug 16, 2018

 @j4cobgarby how does this work? A board (integer array) is created to reflect the size (width * height) of the screen. Then, each frame the board is translated upward (top row removed) and decayed (each integer is decremented) before a new, randomly seeded row is inserted at the bottom. The visual result is simply each integer value being interpreted as a character (from the char array) and color.