{"id":15066787,"url":"https://github.com/mcthomas/opal-p5rb","last_synced_at":"2026-01-02T19:12:43.168Z","repository":{"id":256079045,"uuid":"854241879","full_name":"mcthomas/opal-p5rb","owner":"mcthomas","description":"Ruby bindings to P5.js via Opal","archived":false,"fork":false,"pushed_at":"2024-11-05T05:36:22.000Z","size":2180,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-09T13:47:44.545Z","etag":null,"topics":["2d","3d","art","bindings","browser","coding","creative","drawing","javascript","js","lib","library","oop","opal","p5","p5js","rb","ruby","sketch","wrapper"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mcthomas.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-08T18:41:46.000Z","updated_at":"2025-02-07T23:34:08.000Z","dependencies_parsed_at":"2024-09-29T11:24:22.291Z","dependency_job_id":"ecf6714a-637e-415b-9956-a931684ae1cf","html_url":"https://github.com/mcthomas/opal-p5rb","commit_stats":null,"previous_names":["mcthomas/opal-p5rb"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcthomas%2Fopal-p5rb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcthomas%2Fopal-p5rb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcthomas%2Fopal-p5rb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcthomas%2Fopal-p5rb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mcthomas","download_url":"https://codeload.github.com/mcthomas/opal-p5rb/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243822311,"owners_count":20353496,"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","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":["2d","3d","art","bindings","browser","coding","creative","drawing","javascript","js","lib","library","oop","opal","p5","p5js","rb","ruby","sketch","wrapper"],"created_at":"2024-09-25T01:12:05.492Z","updated_at":"2026-01-02T19:12:43.118Z","avatar_url":"https://github.com/mcthomas.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# opal-p5rb\nRuby bindings to P5.js via Opal\n\n## Purpose\n\nThere are several projects aiming to create bindings between the P5.js lib and Ruby via Opal, with varying degrees of success.  I wanted to avoid having to explicitly embed js within the rb context in my sketches.  While it has been proven to be easy enough to map static P5 functions and top-level variables to rb using Opal, I wanted to take this further and have the ability to instantiate P5 classes (e.g. p5.Vector) and use those objects in the rb context.  The currently incomplete step in this process, is finding a way to access instance members and methods on instances of P5 objects in the rb context (see `call_p5_method()`).  As of now, I can only instantiate them and pass around the references.  For many sketches, this may not be an issue, since they most often lean on static drawing functions at each frame.  In some cases where P5 instance members or methods are needed, the best workaround at present is to use the instance within a new class that stands in for any missing functionality (as exemplified below).\n\n### Progress\n\n- [x] P5 global constants\n\n- [x] P5 mutable globals\n\n- [x] P5 static functions\n\n- [x] P5 class instantiation\n\n- [ ] P5 instance members\n\n- [ ] P5 instance methods\n\n### Usage\n\nCreate your sketch in `sketch.rb` or in a new file which you include.  Then launch a local server from the working directory (e.g. `python -m http.server`).\n\n_passive js console errors will appear for any event functions that you don't define in your sketch, e.g. mouseMoved()_\n\n### Example Sketch _(in src at ./sketch.rb)_\n\n![cubes](./sketch.gif)\n\n```ruby\nclass Box\n  def initialize(position, rotation_speed)\n    @position = position\n    @rotation = P5::Vector.new\n    @rotation_speed = rotation_speed\n  end\n\n  def update\n    @rotation.x += @rotation_speed.x\n    @rotation.y += @rotation_speed.y\n  end\n\n  def display\n    P5.push()\n    P5.translate(@position.x, @position.y, @position.z)\n    P5.rotateX(@rotation.x)\n    P5.rotateY(@rotation.y)\n    P5.stroke(255)\n    P5.fill(0)\n    P5.box(80)\n    P5.pop()\n  end\nend\n\ndef setup\n  P5.createCanvas(800, 600, P5.WEBGL)\n  @boxes = []\n  box_spacing = 200\n  initial_x = -box_spacing\n  3.times do\n    pos = P5::Vector.new(initial_x, 0, 0)\n    rotation_speed = P5::Vector.new(P5.random(0.005, 0.02), P5.random(0.005, 0.02), 0)\n    @boxes \u003c\u003c Box.new(pos, rotation_speed)\n    initial_x += box_spacing\n  end\nend\n\ndef draw\n  P5.background(0)\n  @boxes.each do |box|\n    box.update\n    box.display\n  end\nend\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcthomas%2Fopal-p5rb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmcthomas%2Fopal-p5rb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcthomas%2Fopal-p5rb/lists"}