{"id":25488015,"url":"https://github.com/mwja/piston2d-python","last_synced_at":"2025-08-26T16:07:24.732Z","repository":{"id":136000926,"uuid":"366529294","full_name":"mwja/piston2d-python","owner":"mwja","description":"Python bindings for piston2d","archived":false,"fork":false,"pushed_at":"2021-05-31T17:40:53.000Z","size":5944,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-18T20:08:08.956Z","etag":null,"topics":["graphics","loop","opengl","piston2d","python","python-bindings","rust","rust-bindings"],"latest_commit_sha":null,"homepage":"https://starsflower.github.io/piston2d-python/","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mwja.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2021-05-11T22:36:42.000Z","updated_at":"2021-09-09T00:37:21.000Z","dependencies_parsed_at":null,"dependency_job_id":"a9821dcc-33a6-4b4a-bea5-b5a7e7da3f4c","html_url":"https://github.com/mwja/piston2d-python","commit_stats":null,"previous_names":["jacobmacweb/piston2d-python","raclettes/piston2d-python","mwja/piston2d-python"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/mwja/piston2d-python","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mwja%2Fpiston2d-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mwja%2Fpiston2d-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mwja%2Fpiston2d-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mwja%2Fpiston2d-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mwja","download_url":"https://codeload.github.com/mwja/piston2d-python/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mwja%2Fpiston2d-python/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272235295,"owners_count":24897181,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-26T02:00:07.904Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["graphics","loop","opengl","piston2d","python","python-bindings","rust","rust-bindings"],"created_at":"2025-02-18T20:39:00.632Z","updated_at":"2025-08-26T16:07:24.685Z","avatar_url":"https://github.com/mwja.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# piston2d\n[![](https://img.shields.io/github/v/release/starsflower/piston2d-python.svg?include_prereleases)](https://GitHub.com/starsflower/piston2d-python/releases/) ![](https://img.shields.io/github/license/starsflower/piston2d-python.svg) [![made-with-python](https://img.shields.io/badge/Made%20with-Python-1f425f.svg)](https://www.python.org/) [![made-with-rust](https://img.shields.io/badge/Made%20with-Rust-b7410e.svg)](https://www.rust-lang.org/) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-green.svg)](https://github.com/starsflower/piston2d-python/pulls)\n\n\n\n\n`piston2d`, or `piston2d-python`, is a Python binding for the amazing Rust library `piston2d`.\n\n*This is very WIP, so I will not accept any issues (yet). Assume that breaking changes happen with every commit.*\n\n## Getting started\nThis assumes you have installed the library to your computer. This is not meant to be extensive, but will develop into a proper tutorial as the project goes on.\n\n### Setting up the window and event handlers\n```python\nfrom piston2d.window import Window\nfrom piston2d.window import WindowSettings\n\nfrom piston2d.window.events import Events\nfrom piston2d.window.events import EventSettings\n\nwindow = Window(WindowSettings(\"my window name\", (180, 180)))\nevents = Events(EventSettings())\n```\n\n### Setting up graphics\n```python\nfrom piston2d.opengl import GlGraphics\n\n# ...\n\ngraphics = GlGraphics(\"3.2\")\n```\n\n### Start the loop\n```python\n# List to keep track of keys...\nkeys = []\n\nwhile event := events.next(window):\n    if button := event.press_args():\n        keys.append(button.value())\n        print(\"Keys pressed: {}\".format(keys))\n\n    if button := event.release_args():\n        try:\n            keys.remove(button.value())\n        except:\n            pass\n```\n\n### Draw loop\n```python\nwhile event := events.next(window):\n    # ...\n    if args := event.render_args():\n        # Begin the draw loop\n        context = graphics.draw_begin(args.viewport)\n\n        # Draw code here\n        \n        # End the draw loop\n        graphics.draw_end()\n```\n\n### Drawing shapes\nAs of writing, only the rectangle and circle arc are implemented:\n\n```python\nfrom piston2d.graphics import circle_arc, rectangle\n\nWHITE = [1.0, 1.0, 1.0, 1.0]\n# ...\nwhile event := events.next(window):\n    # ...\n    if args := event.render_args():\n        # Begin the draw loop\n        context = graphics.draw_begin(args.viewport)\n\n        # Draw circle arc in center (ish)\n        circle_arc(WHITE, 15.0, 0.0,\n                   math.tau, [50, 50, 80, 80], context.transform(), graphics)\n\n        # Draw rectangle in top left corner\n        rectangle(WHITE,\n                  [0, 0, 30, 30], context.transform(), graphics)\n        \n        # End the draw loop\n        graphics.draw_end()\n```\n\nYou may also want to clear the screen:\n```python\n# ...\n\nBLACK = [0.0, 0.0, 0.0, 1.0]\nwhile event := events.next(window):\n    # ...\n    if args := event.render_args():\n        # Begin the draw loop\n        context = graphics.draw_begin(args.viewport)\n\n        # Clear the screen\n        graphics.clear_color(BLACK)\n\n        # Draw code here...\n        \n        # End the draw loop\n        graphics.draw_end()\n```\n\n## Examples\n- `tests/simple_window.py` \u0026bull; A simple window to test drawing using `GlGraphics`.\n\n  Example:\n  ![Example](https://i.discord.fr/Vyv.png)\n\n## Building\nUse setuptools to build\n```python\npip install setuptools wheel setuptools_rust\npython setup.py install\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmwja%2Fpiston2d-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmwja%2Fpiston2d-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmwja%2Fpiston2d-python/lists"}