def save(req): if req.method != "POST": log.error('bead method') return redirect(resolve('error')) d = req.stream.read(req.stream_length).decode('ascii') d = parse_qs(d) if 'text' not in d or 'name' not in d: log.error('bead `name` or `text`') return render('error.html', {'message': "required `name` and `text`!"}) text = d['text'][0] name = d['name'][0] # name = secure_filename(name) path = os.path.join('data', name) with open(path, 'w') as f: log.info('write to {0}'.format(path)) f.write(text) next = req.get.get('next') if next: next = resolve(next[0]) else: next = resolve("apps.index.get") + "?name=" + name return render('save.html', { 'timeout': 2000, 'next': next, 'name': name, })
def auRender(lazy = False): scene = core.Scene() ## globals options = { "filename" : cmds.getAttr("AURglobals.fileName"), "lightsamples" : cmds.getAttr("AURglobals.lightsamples"), "mindepth" : cmds.getAttr("AURglobals.mindepth"), "maxdepth" : cmds.getAttr("AURglobals.maxdepth"), "pixelsamples" : cmds.getAttr("AURglobals.pixelsamples"), "resolution" : [cmds.getAttr("AURglobals.resX"), cmds.getAttr("AURglobals.resY")], } scene.setOptions(options) ## camera cam = ls(type='camera')[1] ## TODO: pretty darn hacky to take the 2nd arg here.. for c in ls(type='camera'): if "persp" in c.name(): cam = c trans = cam.getParent().getTranslation() rot = cam.getParent().getRotation() renderCam = core.Camera(fov = cmds.getAttr("AURglobals.fieldofview")) renderCam.translate(trans[0], trans[1], trans[2]) renderCam.rotateZ(rot[2]) renderCam.rotateY(rot[1]) renderCam.rotateX(rot[0]) scene.setCamera(renderCam) ## objects print "MtoAur: Parsing objects." for mesh in ls(type='mesh', visible=True): obj = parseMesh(mesh, lazy) # get shading groups from shapes: shadingGrps = listConnections(mesh,type='shadingEngine') # get the shaders: shd = ls(listConnections(shadingGrps),materials=1) material = parseMaterial(shd[0], mesh.name(), scene) # appen to shader pool scene.appendMaterial(material) obj.setMaterial(material.getName()) scene.append(obj) ## lights print "MtoAur: Parsing lights." for light in ls(type="light"): liObj = parseLight(light) scene.append(liObj) print "MtoAur: Rendering" core.render(scene) print "MtoAur: Done rendering."
def test_mainloop(): expected_effects = [(Display(render(initial_state)), noop), (Prompt("> "), lambda i: "move east"), (Display("Okay."), noop), (SaveGame(state=in_street), noop), (Display(render(in_street)), noop), (Prompt("> "), lambda i: raise_(KeyboardInterrupt())), (Display("\nThanks for playing!"), noop)] eff = mainloop(initial_state) with raises(SystemExit): perform_sequence(expected_effects, eff)
def test_step(): expected_effects = [(Display(render(initial_state)), noop), (Prompt("> "), lambda i: "move east"), (Display("Okay."), noop)] eff = step(initial_state) result = perform_sequence(expected_effects, eff) assert result == in_street
def test_step_bad_command(): expected_effects = [ (Display(render(initial_state)), noop), (Prompt("> "), lambda i: "do a flip"), (Display("Expected: `take <item>` or `move <direction>`"), noop) ] eff = step(initial_state) result = perform_sequence(expected_effects, eff) assert result == initial_state
def get(req): name = req.get.get('name') if not name: return render('error.html', {'message': "No name!"}) name = name[0] # name = secure_filename(name) path = os.path.join('data', name) if not os.path.exists(path): return render('error.html', {'message': "Not Exists!"}) handler = ContentHandler() xml.sax.parse(path, handler) context = dict(name=handler['name'], descr=handler['description'], data=handler['data']) return render('xml.html', context)
def test_quit_game(): for exc in (KeyboardInterrupt(), EOFError()): expected_effects = [ (Display(render(initial_state)), noop), (Prompt("> "), lambda i: raise_(exc)), (Display("\nThanks for playing!"), noop), ] eff = step(initial_state) with raises(SystemExit): perform_sequence(expected_effects, eff)
def step(state): yield display(render(state)) try: user_input = yield Effect(Prompt("> ")) cmd, arg = parse(user_input) result = dispatch(state, cmd, arg) yield display("Okay.") yield do_return(result) except (EOFError, KeyboardInterrupt): yield display("\nThanks for playing!") sys.exit(0) except Exception as e: yield display(str(e)) yield do_return(state)
def get(req): name = req.get.get('name') if not name: return render('error.html', {'message': "No name!"}) name = name[0] # name = secure_filename(name) path = os.path.join('data', name) if not os.path.exists(path): return render('error.html', {'message': "Not Exists!"}) handler = ContentHandler() parser = xml.sax.make_parser() parser.setContentHandler(handler) parser.setFeature(xml.sax.handler.feature_external_ges, 0) parser.parse(path) context = dict(name=handler['name'], descr=handler['description'], data=handler['data']) return render('xml.html', context)
def main(resolution=(1920, 1080), bounds=(0, 0, 1920, 1080), vertex_code=None, fragment_code=None, filepath=None): raw_data = render(resolution, bounds, fragment_code=fragment_code) if filepath is None: buff = memoryview(raw_data).tobytes() sys.stdout.buffer.write(buff) sys.stdout.buffer.flush() quit() if not re.match(r"^(.+)\.buffer$", filepath): saveimg(raw_data, filepath) else: buff = memoryview(raw_data).tobytes() file = os.path.join(os.path.dirname(__file__), "temp/output.buffer") with open(file, "wb") as f: f.write(buff)
# Dragon dragon = geometry.ObjMesh("dragon", "/Users/espennordahl/Downloads/dino1.obj") dragon.scale(30, 30, 30) dragon.rotateY(-15) dragon.translate(280, 0, 280) scene.append(dragon) #material = shaders.MatteSurface(color(1,1,1)) #dragon.material = material # Cube cube = geometry.ObjMesh("cube", "/Users/espennordahl/Downloads/dino2.obj") cube.scale(30, 30, 30) cube.rotateY(-15) cube.translate(280, 0, 280) scene.append(cube) # Cornell box # [...] # Light #light = lights.SquareAreaLight(exposure = 5.75, color = color(1,1,1)) #light.translate(280, 548.7, 280) #scene.append(light) core.render(scene)
bullets.append(player.shoot(scroll,display,sounds['shoot'])) if move > 0: player.translate([player.speed*dt*1.5,0]) elif move < 0: player.translate([-player.speed*dt,0]) player.update(dt,sounds['jump'],boulders) for blt in bullets: blt.update(dt,boulders,tiles,sounds['hit']) for bder in boulders: bder.set_tiles(tiles) bder.update(dt) #---------------------------------------rendering--------------------------------------- bg.render(display,scroll) #render_map(game_map_bg,display,bg_tileset,scroll,[],16) core.render(display,scroll) tiles = render_map(game_map,display,tileset,scroll,['1','2']) for bder in boulders: bder.render(display,scroll) for bullet in bullets: bullet.render(display,scroll) player.set_tiles(tiles) player.render(display,scroll) text = font1.render("Score :",True,(255,255,255)) text2 = font2.render(str(score),True,(255,255,255)) screen.blit(pygame.transform.scale(display,WINDOW_SIZE),(0,0)) screen.blit(text,(screen.get_width()/2 - 40,0)) screen.blit(text2,(screen.get_width()/2 + 50,0)) pygame.display.update() clock.tick(60)
def index(req): return render("index.html")