# MIT License # # Copyright (c) 2026 Tidepost contributors # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. # # Exception: assets/glyphs.json contains rasterized glyph data derived from # Noto Sans CJK JP (SIL Open Font License 1.1). See assets/NOTO-LICENSE.txt. # Pyxel is an external dependency under its own MIT license. """入力・更新・描画の共通入門 1/3。独立した練習画面。""" WIDTH, HEIGHT = 320, 180 FPS = 30 START_X, START_Y = 20, 70 class App: def control(self, pressed, held): pass def draw(self, p): p.cls(1) p.rect(START_X, START_Y, 8, 8, 10) p.text(8, 12, "ONE WINDOW / ORIGIN IS TOP LEFT", 7) p.text(8, 95, "YELLOW SQUARE: X"+str(START_X)+" Y"+str(START_Y), 10) p.text(8, 140, "UPDATE DOES NOTHING / DRAW ONLY READS", 6) p.text(8, 160, "ESC QUIT", 6) KEYS = ("LEFT", "RIGHT", "R", "P") def main(headless=False, screenshot=None, demo=False): from pathlib import Path import pyxel as p screenshot = str(Path(screenshot).resolve()) if screenshot else None if screenshot: Path(screenshot).parent.mkdir(parents=True,exist_ok=True) app = App() p.init(WIDTH,HEIGHT,title="Input / Update / Draw",fps=FPS,display_scale=3,headless=headless) keys = {key:getattr(p,"KEY_"+key) for key in KEYS} limit = 12 def frame_update(): if headless and p.frame_count>=limit: if screenshot: p.screenshot(screenshot,scale=3) p.quit() return if headless and demo: f = p.frame_count app.control(set(),set()) elif not headless: app.control({k for k,v in keys.items() if p.btnp(v)}, {k for k,v in keys.items() if p.btn(v)}) p.run(frame_update,lambda:app.draw(p)) return app if __name__=="__main__": import argparse parser=argparse.ArgumentParser() parser.add_argument("--headless-smoke",action="store_true") parser.add_argument("--demo-checkpoint",action="store_true") parser.add_argument("--screenshot") args=parser.parse_args() main(args.headless_smoke,args.screenshot,args.demo_checkpoint)