def main(stdscr): global frame_no, speed, position, score c = Canvas() bar_width = 16 bars = [Bar(bar_width)] stdscr.refresh() while True: frame_no += 1 for bar in bars: if check_collision(position, bar): return while not keys.empty(): if keys.get() == 113: return speed = 32.0 c.set(0,0) c.set(width, height) if frame_no % 50 == 0: bars.append(Bar(bar_width)) for x,y in bird: c.set(x,y+position) for bar_index, bar in enumerate(bars): if bar.x < 1: bars.pop(bar_index) score += 1 else: bars[bar_index].x -= 1 for x,y in bar.draw(): c.set(x,y) f = c.frame()+'\n' stdscr.addstr(0, 0, f) stdscr.addstr(height/4+1, 0, 'score: {0}'.format(score)) stdscr.refresh() c.clear() speed -= 2 position -= speed/10 if position < 0: position = 0 speed = 0.0 elif position > height-13: position = height-13 speed = 0.0 sleep(1.0/fps)
import sys import os sys.path.append(os.path.abspath("..")) from termux2d import Canvas from timeit import timeit c = Canvas() frames = 1000 * 10 sizes = ((0, 0), (10, 10), (20, 20), (20, 40), (40, 20), (40, 40), (100, 100)) for x, y in sizes: c.set(0, 0) for i in range(y): c.set(x, i) r = timeit(c.frame, number=frames) print('{0}x{1}\t{2}'.format(x, y, r)) c.clear()
import sys import os sys.path.append(os.path.abspath("..")) from termux2d import Canvas import math s = Canvas() for x in range(1800): s.set(x/10, math.sin(math.radians(x)) * 10) print(s.frame()) s.clear() for x in range(0, 1800, 10): s.set(x/10, 10 + math.sin(math.radians(x)) * 10) s.set(x/10, 10 + math.cos(math.radians(x)) * 10) print(s.frame()) s.clear() for x in range(0, 3600, 20): s.set(x/20, 4 + math.sin(math.radians(x)) * 4) print(s.frame()) s.clear()