def test2(): a = seq.build(seq.track1, player.bitRate) screen.init() screen.draw(a, player.bitRate / seq.track1[0]["frequency"]) b = gen.sin(440, player.bitRate, 10, 0) player.play(a) player.play(b)
def test1(): # generate samples, note conversion to float32 array s1 = gen.squ(f1, fs, duration, 1 / 2) # s2 = gen.sin(f2, fs, duration) # s3 = gen.squ(f3, fs, duration) # samples = np.nan_to_num(s1*(s2))/2 # samples = s1 * gen.rah(s2) * gen.rah(s3) samples = s1 screen.init() screen.draw(samples, fs / f1) # for paFloat32 sample values must be in range [-1.0, 1.0] stream = p.open(format=pyaudio.paFloat32, channels=1, rate=fs, output=True) # play. May repeat with different volume values (if done interactively) stream.write(volume * samples) stream.stop_stream() stream.close() p.terminate()
return result return new_func def free(): import gc gc.collect() print(gc.mem_free()) del gc # init screen import screen screen.init() # init mainloop and application import mainloop, app_time @timed_function def refresh_time(): screen.draw_text('Hello Dragon', 14, 8, screen.FNT_ASC16) screen.draw_text('当前时间', 0, 32, screen.FNT_HZK16) screen.draw_text('13:18', 0, 48, screen.FNT_ASC48) screen.update_fast() return def main():
board.init() editor.register() def setgame(): global mousedown, keydown mousedown, keydown = game.mousedown, game.keydown board.init(loadfrom='map/example') game.register() pygame.init() size = 640, 480 screen.init(size, False) gui.drawfont = 'Arial.ttf' mainmenuspec = [ 0.8, 0.35, ["$logo.png", 0.0, 0, 0.3], ["@Play map", 0.0, 0.3, 0.05], ["@Edit map", 0.27, 0.3, 0.05], ["@Edit new map", 0.53, 0.3, 0.05] ] gui.newwindow(mainmenuspec, None, (.25, .325), [setgame, seteditor, setneweditor]) movingwindow = None movingscreen = False lastframe = pygame.time.get_ticks()
import math import texture from world import getworld, Game, transitionto import screen import texture keydown = None mousedown = None pygame.init() pymunk.init_pymunk() size = 1280, 960 worldsize = screen.init(size) transitionto(Game) lastframe = pygame.time.get_ticks() while 1: for e in pygame.event.get(): if e.type == pygame.QUIT or \ e.type == pygame.KEYDOWN and e.key == pygame.K_ESCAPE: sys.exit(0) elif e.type == pygame.KEYDOWN: getworld().keydown(e.key) elif e.type == pygame.KEYUP: getworld().keyup(e.key) elif e.type == pygame.MOUSEBUTTONDOWN:
import math import texture from world import getworld, Game, transitionto import screen import texture keydown = None mousedown = None pygame.init() pymunk.init_pymunk() size = 1280,960 worldsize = screen.init(size) transitionto(Game) lastframe = pygame.time.get_ticks() while 1: for e in pygame.event.get(): if e.type == pygame.QUIT or \ e.type == pygame.KEYDOWN and e.key == pygame.K_ESCAPE: sys.exit(0) elif e.type == pygame.KEYDOWN: getworld().keydown(e.key) elif e.type == pygame.KEYUP: getworld().keyup(e.key) elif e.type == pygame.MOUSEBUTTONDOWN:
#import texture from world import getworld, Game, transitionto import world import screen import texture keydown = None mousedown = None pygame.init() size = 1280, 720 screensize = screen.init(size) world.setscreensize(screensize) transitionto(Game) lastframe = pygame.time.get_ticks() while 1: for e in pygame.event.get(): if e.type == pygame.QUIT or \ e.type == pygame.KEYDOWN and e.key == pygame.K_ESCAPE: sys.exit(0) elif e.type == pygame.KEYDOWN: getworld().keydown(e.key) elif e.type == pygame.KEYUP: getworld().keyup(e.key)