Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hswick/sandoz
Ruby P5 Wrapper
https://github.com/hswick/sandoz
Last synced: 6 days ago
JSON representation
Ruby P5 Wrapper
- Host: GitHub
- URL: https://github.com/hswick/sandoz
- Owner: hswick
- License: mit
- Created: 2016-01-27T19:03:16.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-08-28T18:41:15.000Z (about 8 years ago)
- Last Synced: 2024-04-25T22:20:39.176Z (7 months ago)
- Language: Ruby
- Size: 398 KB
- Stars: 4
- Watchers: 4
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# A Gem Named Sandoz
## Rationale
But when we use Opal, all Ruby functions are defined within the Opal namespace, prepended with a `$`. So we're really defining `Opal.$setup`, `Opal.$draw`, etc.
p5.js expects that `setup` and `draw` are in the global namespace, and it also defines all of its methods in the global namespace. As such, there are two problems:* p5.js needs to call a global `setup` and `draw` but, via Opal, we can't cleanly define a global `setup` and `draw`
* Ruby code needs to call the global p5.js functions (e.g. `createCanvas`), which requires wrapping all the p5.js functions in equivalent Ruby functionsSandoz wraps the p5.js library, and bridges the Ruby methods to JavaScript, enabling us to call p5.js functions from Ruby.
## Installation
Make sure you have bundler installed
gem install bundler
Add this line to your application's Gemfile:
```ruby
gem 'sandoz'
```Then install dependencies:
bundle install
Run:
bundle exec rackup
How to Require:
require 'opal'
require 'sandoz'#Have to do this to get functions in global namespace
include Sandoz
#Option 2:
Sandoz::defsketch do
Sandoz::setup do
Sandoz::size 600, 600
Sandoz::rect 100, 100, 100, 100
end
end```ruby
defsketch("content") dosetup do
size 600, 600
enddraw do
fill 255, 0, 0
rect 100, 100, 100, 100
endend
```## Example Application
https://github.com/hswick/sandoz_demo
## Contributing
Bug reports and pull requests are welcome on GitHub at [https://github.com/hswick/sandoz](https://github.com/hswick/sandoz). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
## License
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).