{"id":20750549,"url":"https://github.com/micycle1/pthreading","last_synced_at":"2025-10-11T20:34:59.788Z","repository":{"id":133574932,"uuid":"210012664","full_name":"micycle1/PThreading","owner":"micycle1","description":"A framework for multithreaded drawing in Processing","archived":false,"fork":false,"pushed_at":"2020-10-08T19:52:45.000Z","size":360,"stargazers_count":13,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-28T12:57:31.746Z","etag":null,"topics":["framework","multithreading","processing","processing-sketch","rendering"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/micycle1.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-09-21T15:53:48.000Z","updated_at":"2024-09-16T17:44:35.000Z","dependencies_parsed_at":null,"dependency_job_id":"f0be1095-f73d-4e84-9541-0fea76a507f0","html_url":"https://github.com/micycle1/PThreading","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/micycle1/PThreading","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/micycle1%2FPThreading","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/micycle1%2FPThreading/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/micycle1%2FPThreading/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/micycle1%2FPThreading/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/micycle1","download_url":"https://codeload.github.com/micycle1/PThreading/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/micycle1%2FPThreading/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279008619,"owners_count":26084480,"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-10-11T02:00:06.511Z","response_time":55,"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":["framework","multithreading","processing","processing-sketch","rendering"],"created_at":"2024-11-17T08:27:50.044Z","updated_at":"2025-10-11T20:34:59.749Z","avatar_url":"https://github.com/micycle1.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PThreading\nPThreading: A framework for multithreaded drawing in [Processing](https://processing.org/).\n\n---\n\nThe framework consists of two classes: `PThread` and `PThreadManager`. Override the `PThread` class with Processing code and then add instances of your new class to a PThreadManager; this will run the instances as threads that draw into your Processing sketch in a multithreaded manner.\n\n## Motivation\n\nNatively, Processing runs on a single thread -- all drawing is done within the *draw()* loop.\n\nProcessing does indeed provide a quick and dirty way to implement a simple thread with its *thread()* method, although as the [docs](https://processing.org/reference/thread_.html) describe...\n\n\u003e You cannot draw to the screen from a function called by thread(). Because it runs independently, the code will not be synchronized to the animation thread, causing strange or at least inconsistent results.\n\n... leaving *thread()* suitable only for CPU-bound sketches, at best. \n\nIn contrast, PThreading provides a way to do **multithreaded drawing** -- not just calculation -- and does so in an easy-to-use and well-synchronized manner. It exploits the fact that *PGraphics* objects can be drawn into safely from other threads.\n\n## Setup\n\nDownload *pthreading.jar* from [releases](https://github.com/micycle1/PThreading/releases).\n\n#### In the Processing IDE (PDE):\n\n* Drag \u0026 drop *pthreading.jar* onto the PDE, or see the Processing [wiki](https://github.com/processing/processing/wiki/How-to-Install-a-Contributed-Library#non-processing-libraries) on how to add an external library to a Processing sketch.\n\n#### In other Java IDEs:\n* Add pthreading.jar to the classpath of your project.\n\n## Getting Started\n\n*The Javadoc is available [online](https://micycle1.github.io/PThreading/pthreading/package-summary.html) -- here, every method and class is thoroughly documented.*\n\n### 1. Extending PThread\n\nCreate a new class that extends PThread. You have to override the PThread's *draw()* method; overriding *calc()* and *setup()* is optional. In *draw()*, put Processing drawing code that you wish to be executed as a thread. A very simple example is shown below:\n\n#### PDE Example:\n\n```\nclass myThread extends PThread { \n  \n  private final int n;\n  \n  public myThread(PApplet p, int n) {\n    super(p);\n    this.n = n;\n  }\n  \n  @Override\n  public void draw(){\n    g.ellipse(mouseX + n, mouseY, 50, 50);\n  }\n  \n}\n```\n\n#### Non-PDE Example:\n\n```\nclass myThread extends PThread { \n  \n  private final int n;\n  \n  public myThread(PApplet p, int n) {\n    super(p);\n    this.n = n;\n  }\n  \n  @Override\n  public void draw(){\n    g.ellipse(p.mouseX + n, p.mouseY, 50, 50); // note mouseX and mouseY are prefixed with 'p.'\n  }\n  \n}\n```\n\n**Important**: \n* Prefix every call to a Processing **draw method** with **g** -- for example: *g.rect(10,10,10,10)* (relevant in all environments).\n* Prefix every call to a Processing **variable** with **p** -- for example: *p.mousePressed* (relevant in non-PDE environments only).\n* By default, *smooth()* is enabled for threads. Put *g.noSmooth();* in the thread consructor to disable anti-aliasing and thereby improve draw FPS.\n\n### 2. Creating a PThreadManager\nCreate a thread manager and add threads to it. A [variety](micycle1.github.io/PThreading/pthreading/PThreadManager.html) of constructors are available. In this example the most simple constructor has been chosen. You can add multiple types of threads to a single thread manager.\n\n```\nthreadManager = new PThreadManager(this);\nmyThread a = new myThread(this, 50);\nmyThread b = new myThread(this, -50);\nthreadManager.addThread(a, b);\n```\n\n### 3. Drawing threads\nAfter adding a thread to a thread manager it will run immediately; however this does not mean the thread will be drawn into the sketch. To do this, call `draw()` on the thread manager.\n\n```\nvoid draw() {\n  background(255);\n  threadManager.draw();\n}\n```\n\nAlternatively, you can call `threadManager.bindDraw()` once -- in `setup` for example -- to bind the `draw()` method of the thread manager to the end of the draw method of the sketch. After doing this, you no longer need to make a manual call to `threadManager.draw()` to draw threads.\n\n---\n\nThat's it: now `a` and `b` will run as threads, drawing into the sketch. See the repo [examples](https://github.com/micycle1/PThreading/tree/master/examples) for the framework in action and more sophisticated behaviour.\n\n## Limitations\nEach thread uses the `Java2D` renderer, since this is the only renderer that allows PGraphics objects to be instantiated and drawn into from other threads. As a consequence you cannot **thread** `OPENGL` drawing, or any 3D draw functions -- note that you can still use the framework with a 3D sketch but any drawing with the PThreads is limited to 2D.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicycle1%2Fpthreading","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmicycle1%2Fpthreading","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicycle1%2Fpthreading/lists"}