Title: Python sketches are not Pythonic · Issue #230 · processing/libprocessing · GitHub
Open Graph Title: Python sketches are not Pythonic · Issue #230 · processing/libprocessing
X Title: Python sketches are not Pythonic · Issue #230 · processing/libprocessing
Description: Sorry for the vague title, feel free to update it. Using https://github.com/processing/processing-examples-mewnala/blob/6e416d80852ee9e147b70ae93cbf8f6dda871ba3/Basics/Structure/Redraw/Redraw.py as an example, a mewnala sketch structure ...
Open Graph Description: Sorry for the vague title, feel free to update it. Using https://github.com/processing/processing-examples-mewnala/blob/6e416d80852ee9e147b70ae93cbf8f6dda871ba3/Basics/Structure/Redraw/Redraw.py as...
X Description: Sorry for the vague title, feel free to update it. Using https://github.com/processing/processing-examples-mewnala/blob/6e416d80852ee9e147b70ae93cbf8f6dda871ba3/Basics/Structure/Redraw/Redraw.py as...
Opengraph URL: https://github.com/processing/libprocessing/issues/230
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Python sketches are not Pythonic","articleBody":"_Sorry for the vague title, feel free to update it._\n\nUsing https://github.com/processing/processing-examples-mewnala/blob/6e416d80852ee9e147b70ae93cbf8f6dda871ba3/Basics/Structure/Redraw/Redraw.py as an example, a mewnala sketch structure and common techniques has several issues that makes it less ideal as Python code:\n\n* Sharing state between frames requires the use of `global`\n* Even when wildcard import is removed, some variables are injected at the runtime and linters catch them as \"undefined\":\n * https://github.com/processing/libprocessing/issues/150\n* `setup` function is not meaningful, the same results can be achieved just without. Using `setup` to initialize variables etc. causes even more undefined issues because how scopes work in Python.\n\nAs an alternative, a class based approach can solve all these issues:\n\n```python\nfrom mewnala import (\n Line,\n Sketch as BaseSketch,\n)\n\nclass Sketch(BaseSketch):\n def __init__(self, width=640, height=480):\n super().__init__()\n\n self.width = width\n self.height = height\n\n def setup(self):\n self.size = (self.width, self.height)\n self.stroke = 255\n self.loop = False\n\n self.y = 180\n\n def draw(self):\n self.background = 0\n\n self.y -= 4\n if self.y \u003c 0:\n self.y = self.height\n\n line = Line(0, self.y, self.width, self.y)\n line.draw()\n\n def mouse_pressed(self):\n self.redraw()\n\n\nif __name__ == \"__main__\":\n sketch = Sketch(width=1920, height=1080)\n sketch.run()\n```\n\nNo more magic imports, no more undefined variables, and now the sketch has a Python-native syntax feel much more natural comparing to the previous version.\n\n_I removed the setter function calls too, it's a Java-native pattern and feels weird with Python._\n\nWe can go one step further and eliminate the `setup()` What does it do for the sketch can be covered by `__init__` in a class context.","author":{"url":"https://github.com/ulgens","@type":"Person","name":"ulgens"},"datePublished":"2026-08-12T12:29:50Z","url":"https://github.com/processing/libprocessing/issues/230"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:9236054d-48a1-329e-caf8-2573abcdacac |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B920:3C6858:1246C3:187433:6B05F763 |
| html-safe-nonce | 252679afb6e5b721a6e8686eadacf0eccbaf4dde87ba9a9e7ef278e5f6b3a513 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCOTIwOjNDNjg1ODoxMjQ2QzM6MTg3NDMzOjZCMDVGNzYzIiwidmlzaXRvcl9pZCI6IjkxMDc1NDQzMzQxMTQ2MTcxODciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | e529ccc51ac9e1e53c869377f7f08b3ca5e1bf66b646a1c7d9c4962cc547eb78 |
| hovercard-subject-tag | issue:5130882659 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/processing/libprocessing/230/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4e5632293360e2d42661577cb46cde597dcfd17967978107081f17bfe3a32936/processing/libprocessing/issues/230 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4e5632293360e2d42661577cb46cde597dcfd17967978107081f17bfe3a32936/processing/libprocessing/issues/230 |
| og:image:alt | Sorry for the vague title, feel free to update it. Using https://github.com/processing/processing-examples-mewnala/blob/6e416d80852ee9e147b70ae93cbf8f6dda871ba3/Basics/Structure/Redraw/Redraw.py as... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ulgens |
| hostname | github.com |
| expected-hostname | github.com |
| None | c214754a6652274794ed4e054a7b71be999d69843f103ba54893001d45010ece |
| turbo-cache-control | no-preview |
| go-import | github.com/processing/libprocessing git https://github.com/processing/libprocessing.git |
| octolytics-dimension-user_id | 1617169 |
| octolytics-dimension-user_login | processing |
| octolytics-dimension-repository_id | 1101329545 |
| octolytics-dimension-repository_nwo | processing/libprocessing |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1101329545 |
| octolytics-dimension-repository_network_root_nwo | processing/libprocessing |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7d164a4e71eb333b2b17fd5b17e18efb7855505c |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width