def run(script, opt1, opt2): global _option global opts global cmd if md == 'custom': opt2 = '__custom__' framework.run(script, opt1, opt2) print '' _option = [] opts = {} cmd = ''
20. 5. 게임 실행 순서: 1. stream.py -> framework.py 2. begin.py 3. main.py 4. stage_intro.py -> game_executor.py -> game_container.py -> ... 외부 파일 수정 사항: 1. pico2d.py 의 open_canvas 함수 수정 (창 핸들 반환) 2. pico2d.py 의 image 클래스 수정 (중심점 설정: xoffset, yoffset), 설정 함수 추가 3. pico2d.py 의 printfps 함수 실행부 삭제 4. sdl2.keycode.py 에 __all__ 추가 (확인 바람) 5. pico2d.py 에 background_color, draw_color 와 그 set, get 메서드 추가 6. pico2d.py 에 문자 정렬 추가 7. rect.py 의 생성자에 int 변환 씌움 ] """ # noinspection PyUnresolvedReferences if __name__ == "__main__": framework.game_begin() sprite_json_loads() audio_json_loads() import begin framework.run(begin) framework.game_end()
#while world_intro.loop(): # events.trigger_event('cleanup') world_menu.create() while world_menu.loop(): events.trigger_event('cleanup') #world_hire.create() #while world_hire.loop(): # events.trigger_event('cleanup') world_strategy.create() while world_strategy.loop(): events.trigger_event('cleanup') framework.shutdown() if __name__ == '__main__': framework.init(debug='--debug' in sys.argv) framework.events.register_event('boot', words.boot) if '--debug' in sys.argv: cProfile.run('framework.run(main)', 'profile.dat') else: framework.run(main)
import pico2d import framework import state_Start # open_canvas 하고 이미지 로드해야한다 pico2d.open_canvas(800, 800, sync=13) framework.run(state_Start) pico2d.close_canvas()
# events.trigger_event('cleanup') world_menu.create() while world_menu.loop(): events.trigger_event('cleanup') #world_hire.create() #while world_hire.loop(): # events.trigger_event('cleanup') world_strategy.create() while world_strategy.loop(): events.trigger_event('cleanup') framework.shutdown() if __name__ == '__main__': framework.init(debug='--debug' in sys.argv) framework.events.register_event('boot', words.boot) if '--debug' in sys.argv: cProfile.run('framework.run(main)', 'profile.dat') else: framework.run(main)
from pico2d import * import framework import game_value import main_game import main_menu import test open_canvas(game_value.WINDOW_SIZE[0], game_value.WINDOW_SIZE[1], sync=True) framework.run(main_menu) close_canvas()
cr.fill() # draw a rectangle cr.set_source_rgb(1.0, 1.0, 1.0) cr.rectangle(10, 10, width - 20, height - 20) cr.fill() # set up a transform so that (0,0) to (1,1) # maps to (20, 20) to (width - 40, height - 40) cr.translate(20, 20) cr.scale((width - 40) / 1.0, (height - 40) / 1.0) # draw lines cr.set_line_width(0.01) cr.set_source_rgb(0.0, 0.0, 0.8) cr.move_to(1 / 3.0, 1 / 3.0) cr.rel_line_to(0, 1 / 6.0) cr.move_to(2 / 3.0, 1 / 3.0) cr.rel_line_to(0, 1 / 6.0) cr.stroke() # and a circle cr.set_source_rgb(1.0, 0.0, 0.0) radius = 1 cr.arc(0.5, 0.5, 0.5, 0, 2 * pi) cr.stroke() cr.arc(0.5, 0.5, 0.33, pi / 3, 2 * pi / 3) cr.stroke() framework.run(Transform)
from tkinter import * import framework import startState framework.load() framework.run(startState.StartState()) framework.save()
import os import platform if platform.architecture()[0] == '32bit': os.environ["PYSDL2_DLL_PATH"] = "./SDL2/x86" else: os.environ["PYSDL2_DLL_PATH"] = "./SDL2/x64" import framework import first_state from pico2d import * open_canvas() framework.run(first_state) close_canvas()
from framework import run args = { 'submission': True, 'test_size': 0.2, 'random_state': 12345, 'expt': 'expt_4', 'cross_val_score': False, 'k-fold': 3, 'model': 'Rating' # 'model': 'Visit' } if __name__ == "__main__": run(args)
def count(self): return len(self.input()) + 5 def expected(self): return self.input() class Scanln_InputEndsWithLineSeps_LineSepsAreTrimmed(Scanln_Test, framework.Test): def __init__(self): super().__init__() def input(self): return f"{self.expected()}{os.linesep}{os.linesep}" def count(self): return len(self.input()) + 5 def expected(self): return "expected line" class CursorUp_Works(framework.Test): def __init__(self): super().__init__() def test(self): result = subprocess.run([ "python", f"{scriptdir}/io_cursorUp.py" ]) framework.expect(result.returncode == 0, f"io_cursorUp.py exited with {result.returncode}") if __name__ == "__main__": exit(0 if framework.run(__name__) else 1)
import framework @framework.route('/') def homepage(): page = 'static/index.html' return page if __name__ == '__main__': app = framework.make_app() framework.use_default_server() framework.run(ip='localhost', port="8080")
surface = cairo.ImageSurface.create_for_data(arr, cairo.FORMAT_RGB24, size, size) cr.set_source_surface(surface) cr.paint() cr.set_source_rgb(1, 1, 1) for obj in objs: obj.draw(cr) cr.stroke() cr.set_source_rgba(1, 1, 1, 0.01) cr.set_line_width(1) for _ in range(40000): isfirst = 0 pos = np.random.rand(2) * size pos = [size / 2, size / 2] angle = rand.random() * math.pi * 2 direction = np.array([math.cos(angle), math.sin(angle)]) for bounces in range(10): marchpos = raymarch(pos, direction) cr.move_to(marchpos[0][0], marchpos[0][1]) cr.line_to(marchpos[-1][0], marchpos[-1][1]) cr.stroke() if isinside(marchpos[-1]): direction = reflect(marchpos[-1], direction) pos = marchpos[-1] + direction else: break framework.run(SDFRenderer, size, size) framework.run(LightRenderer, size, size) # printsdf(sdf)
from math import pi class Shapes(framework.Screen): def draw(self, cr, width, height): cr.set_source_rgb(0.5, 0.5, 0.5) cr.rectangle(0, 0, width, height) cr.fill() # draw a rectangle cr.set_source_rgb(1.0, 1.0, 1.0) cr.rectangle(10, 10, width - 20, height - 20) cr.fill() # draw lines cr.set_source_rgb(0.0, 0.0, 0.8) cr.move_to(width / 3.0, height / 3.0) cr.rel_line_to(0, height / 6.0) cr.move_to(2 * width / 3.0, height / 3.0) cr.rel_line_to(0, height / 6.0) cr.stroke() # and a circle cr.set_source_rgb(1.0, 0.0, 0.0) radius = min(width, height) cr.arc(width / 2.0, height / 2.0, radius / 2.0 - 20, 0, 2 * pi) cr.stroke() cr.arc(width / 2.0, height / 2.0, radius / 3.0 - 10, pi / 3, 2 * pi / 3) cr.stroke() framework.run(Shapes)
# -- Draw the down arrow... # cr.set_line_width(0.003) cr.move_to(-0.02, 0.45) cr.line_to(0.02, 0.45) cr.line_to(0, 0.5) cr.close_path() cr.stroke() # -- Show the telemetry... # cr.restore() cr.set_source_rgba(1, 1, 1, 0.8) cr.select_font_face("sans-serif") cr.set_font_size(32) angle = unicode(round(degrees(self.rotation), 1)) + u'\u00b0' (x, y, w, h, xa, ya) = cr.text_extents(angle) cr.move_to(width - 40 - w, 40) cr.show_text(angle) if __name__ == "__main__": provider = None if (providers.NokiaAccelerometer.available()): provider = providers.NokiaAccelerometer() else: provider = providers.Demo() framework.run(Attitude(provider))
import framework def hello(match): return "Hello world!" def user(match): return "This is %s's user page!" % match.group(1) if __name__ == '__main__': framework.ROUTES['\Auser/([a-zA-Z0-9]+)\Z'] = ('example', 'user') framework.ROUTES['hello'] = ('example', 'hello') framework.run()
from __future__ import print_function import string from nltk.corpus import stopwords from framework import run stops = set(stopwords.words('english')) | set(string.punctuation) def wcmap(text): wc = [] for word in text: w = word.lower() if w not in stops: wc.append((w, 1)) return wc def wcreduce(word, counts): return word, sum(counts) from book import text1 for word, count in run(text1*1000, wcmap, wcreduce): print(word, count)
raise Exception("inconclusive() did not raise Inconclusive") except Inconclusive as err: if expected != str(err): raise Exception("raised Inconclusive has wrong str()") class TestResult_NoMessage_Passed(Test): def __init__(self): super().__init__() def test(self): if not TestResult().passed: raise Exception("TestResult().passed is false") class TestResult_Message_FailedWithMessage(Test): def __init__(self): super().__init__() def test(self): expected = "expected message" result = TestResult(expected) if result.passed: raise Exception("TestResult(message).passed is true") if expected != result.message: raise Exception("TestResult(message) has wrong message") if __name__ == "__main__": exit(0 if run(__name__) else 1)