sandoz 0.1.51 → 0.1.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +0 -5
- data/README.md +16 -1
- data/bin/console +3 -3
- data/bin/sandoz +5 -0
- data/lib/cli.rb +19 -0
- data/lib/sandoz.rb +10 -1
- data/lib/sandoz/sandoz.rb +138 -6
- data/lib/sandoz/version.rb +1 -1
- data/sandoz.gemspec +7 -11
- metadata +14 -14
- data/lib/sandoz/sandoz/sandoz.rb +0 -140
- data/lib/sandoz/sandoz/version.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf64bb67df7459677060242d7f1774430cdabc11
|
4
|
+
data.tar.gz: afc7cffa8eb0c1beb50e1d61da6254ffb4819d42
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd944b01ac2617e1ac6df825fb7c93ec5182a89f05606eda79587a2dfffa77b18b745b5b456e8b1a410c5d367462ca1e554ff560b4baa62e84de43e37555780f
|
7
|
+
data.tar.gz: e966f0a287b670baf09551c3ab07e0c25e7a4ad18c3cd0f4b62a86f6dce1a5707cc53ca0ef191fc51078a0d2fda25b3c94de92ce96770d0f03e81c4c1d9b283a
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,14 +1,27 @@
|
|
1
1
|
# A Gem Named Sandoz
|
2
2
|
|
3
|
+
## Rationale
|
4
|
+
|
5
|
+
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.
|
6
|
+
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:
|
7
|
+
|
8
|
+
* p5.js needs to call a global `setup` and `draw` but, via Opal, we can't cleanly define a global `setup` and `draw`
|
9
|
+
* Ruby code needs to call the global p5.js functions (e.g. `createCanvas`), which requires wrapping all the p5.js functions in equivalent Ruby functions
|
10
|
+
|
11
|
+
Sandoz wraps the p5.js library, and bridges the Ruby methods to JavaScript, enabling us to call p5.js functions from Ruby.
|
12
|
+
|
3
13
|
## Installation
|
14
|
+
|
4
15
|
Make sure you have bundler installed
|
5
16
|
|
6
17
|
gem install bundler
|
18
|
+
|
7
19
|
Add this line to your application's Gemfile:
|
8
20
|
|
9
21
|
```ruby
|
10
22
|
gem 'sandoz'
|
11
23
|
```
|
24
|
+
|
12
25
|
Then install dependencies:
|
13
26
|
|
14
27
|
bundle install
|
@@ -34,6 +47,7 @@ How to Require:
|
|
34
47
|
|
35
48
|
```ruby
|
36
49
|
defsketch("content") do
|
50
|
+
|
37
51
|
setup do
|
38
52
|
size 600, 600
|
39
53
|
end
|
@@ -42,12 +56,13 @@ defsketch("content") do
|
|
42
56
|
fill 255, 0, 0
|
43
57
|
rect 100, 100, 100, 100
|
44
58
|
end
|
59
|
+
|
45
60
|
end
|
46
61
|
```
|
47
62
|
|
48
63
|
## Contributing
|
49
64
|
|
50
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
65
|
+
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.
|
51
66
|
|
52
67
|
|
53
68
|
## License
|
data/bin/console
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'sandoz'
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +10,5 @@ require "foo_gem"
|
|
10
10
|
# require "pry"
|
11
11
|
# Pry.start
|
12
12
|
|
13
|
-
require
|
13
|
+
require 'irb'
|
14
14
|
IRB.start
|
data/bin/sandoz
ADDED
data/lib/cli.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'thor'
|
2
|
+
|
3
|
+
module Sandoz
|
4
|
+
|
5
|
+
class Cli < Thor
|
6
|
+
|
7
|
+
desc "hello", "Say hello"
|
8
|
+
def hello
|
9
|
+
puts "Well, I met a girl called Sandoz\nAnd she taught me many, many things\nGood things, very good things, sweet things."
|
10
|
+
end
|
11
|
+
|
12
|
+
desc "new", "Take a hit and create a new sandoz project"
|
13
|
+
def new
|
14
|
+
`say Well, I met a girl called Sandoz`
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
data/lib/sandoz.rb
CHANGED
@@ -1 +1,10 @@
|
|
1
|
-
require
|
1
|
+
# require all the files, only if Opal is executing
|
2
|
+
if RUBY_ENGINE == 'opal'
|
3
|
+
require_relative 'sandoz/sandoz.rb'
|
4
|
+
require_relative 'sandoz/version'
|
5
|
+
else
|
6
|
+
# NOT running inside of opal, set things up
|
7
|
+
# so opal can find the files.
|
8
|
+
require 'opal'
|
9
|
+
Opal.append_path File.expand_path('..', __FILE__).untaint
|
10
|
+
end
|
data/lib/sandoz/sandoz.rb
CHANGED
@@ -1,8 +1,140 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
module Sandoz
|
2
|
+
# https://github.com/processing/p5.js/wiki/p5.js-overview#instantiation--namespace
|
3
|
+
# TODO Add html element argument
|
4
|
+
def defsketch(id, &block)
|
5
|
+
sketch = Proc.new do |p|
|
6
|
+
init(p)
|
7
|
+
block.call
|
8
|
+
end
|
9
|
+
@p5 = `new p5(#{sketch}, #{id})`
|
10
|
+
end
|
11
|
+
|
12
|
+
def view_p
|
13
|
+
`return #{@p5}`
|
14
|
+
end
|
15
|
+
|
16
|
+
def init(p)
|
17
|
+
@@p = p
|
18
|
+
end
|
19
|
+
|
20
|
+
def size(w, h)
|
21
|
+
`#{@@p}.createCanvas(#{w}, #{h})`
|
22
|
+
end
|
23
|
+
|
24
|
+
def background(r, g=nil, b=nil)
|
25
|
+
if g == nil && b == nil
|
26
|
+
`#{@@p}.background(#{r})`
|
27
|
+
else
|
28
|
+
`#{@@p}.background(#{r}, #{g}, #{b})`
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def fill(r, g=nil, b=nil, a=nil)
|
33
|
+
if g==nil && b ==nil
|
34
|
+
`#{@@p}.fill(#{r})`
|
35
|
+
elsif a == nil
|
36
|
+
`#{@@p}.fill(#{r}, #{g}, #{b})`
|
37
|
+
else
|
38
|
+
`#{@@p}.fill(#{r}, #{g}, #{b}, #{a})`
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def rect(x, y, w, h)
|
43
|
+
`#{@@p}.rect(#{x}, #{y}, #{w}, #{h})`
|
44
|
+
end
|
45
|
+
|
46
|
+
def ellipse(x, y, w, h)
|
47
|
+
`#{@@p}.ellipse(#{x}, #{y}, #{w}, #{h})`
|
48
|
+
end
|
49
|
+
|
50
|
+
def width
|
51
|
+
`#{@@p}.width`
|
52
|
+
end
|
53
|
+
|
54
|
+
def height
|
55
|
+
`#{@@p}.height`
|
56
|
+
end
|
57
|
+
|
58
|
+
def line(x1, y1, x2, y2)
|
59
|
+
`#{@@p}.line(#{x1}, #{y1}, #{x2}, #{y2})`
|
60
|
+
end
|
61
|
+
|
62
|
+
def point(x, y)
|
63
|
+
`#{@@p}.point(#{x}, #{y})`
|
64
|
+
end
|
65
|
+
|
66
|
+
def stroke(r, g=nil, b=nil, a=nil)
|
67
|
+
if g==nil && b ==nil
|
68
|
+
`#{@@p}.stroke(#{r})`
|
69
|
+
elsif a == nil
|
70
|
+
`#{@@p}.stroke(#{r}, #{g}, #{b})`
|
71
|
+
else
|
72
|
+
`#{@@p}.stroke(#{r}, #{g}, #{b}, #{a})`
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def no_stroke
|
77
|
+
`#{@@p}.noStroke()`
|
78
|
+
end
|
79
|
+
|
80
|
+
def stroke_weight(weight)
|
81
|
+
`#{@@p}.strokeWeight(#{weight})`
|
82
|
+
end
|
83
|
+
|
84
|
+
def setup(&block)
|
85
|
+
`#{@@p}.setup = #{block}`
|
86
|
+
end
|
87
|
+
|
88
|
+
def draw(&block)
|
89
|
+
`#{@@p}.draw = #{block}`
|
90
|
+
end
|
91
|
+
|
92
|
+
def dist(x1, y1, x2, y2)
|
93
|
+
`return #{@@p}.dist(x1, y1, x2, y2)`
|
94
|
+
end
|
95
|
+
|
96
|
+
def random(min, max=nil)
|
97
|
+
if max
|
98
|
+
`return #{@@p}.random(#{min}, #{max})`
|
99
|
+
else
|
100
|
+
`return #{@@p}.random(#{min})`
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def color(r, g=nil, b=nil, a=nil)
|
105
|
+
if g==nil && b ==nil
|
106
|
+
`return #{@@p}.color(#{r})`
|
107
|
+
elsif a == nil
|
108
|
+
`return #{@@p}.color(#{r}, #{g}, #{b})`
|
109
|
+
else
|
110
|
+
`return #{@@p}.color(#{r}, #{g}, #{b}, #{a})`
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def map(value, start1, stop1, start2, stop2)
|
115
|
+
`return #{@@p}.map(#{value}, #{start1}, #{stop1}, #{start2}, #{stop2})`
|
116
|
+
end
|
117
|
+
|
118
|
+
def millis
|
119
|
+
`return #{@@p}.millis();`
|
120
|
+
end
|
121
|
+
|
122
|
+
def no_fill
|
123
|
+
`#{@@p}.noFill()`
|
124
|
+
end
|
125
|
+
|
126
|
+
def noise(x, y=nil, z=nil)
|
127
|
+
if y == nil && z == nil
|
128
|
+
`return #{@@p}.noise(#{x})`
|
129
|
+
elsif z == nil
|
130
|
+
`return #{@@p}.noise(#{x}, #{y})`
|
131
|
+
else
|
132
|
+
`return #{@@p}.noise(#{x}, #{y}, #{z})`
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def text(text, x, y)
|
137
|
+
`#{@@p}.text(#{text}, #{x}, #{y})`
|
138
|
+
end
|
6
139
|
|
7
|
-
Opal.append_path File.expand_path('../..', __FILE__).untaint
|
8
140
|
end
|
data/lib/sandoz/version.rb
CHANGED
data/sandoz.gemspec
CHANGED
@@ -1,20 +1,16 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'sandoz/version'
|
2
|
+
require File.expand_path('../lib/sandoz/version', __FILE__)
|
5
3
|
|
6
4
|
Gem::Specification.new do |s|
|
7
|
-
s.name
|
5
|
+
s.name = 'sandoz'
|
8
6
|
s.version = Sandoz::VERSION
|
9
7
|
s.authors = ["Harley Swick"]
|
10
8
|
s.email = ["hswick@example.com"]
|
11
|
-
s.summary =
|
12
|
-
s.description =
|
9
|
+
s.summary = "A gem named Sandoz."
|
10
|
+
s.description = "Ruby p5.js wrapper for trippy visuals."
|
13
11
|
s.homepage = "https://github.com/hswick/sandoz"
|
14
12
|
s.license = "MIT"
|
15
13
|
|
16
|
-
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
17
|
-
# delete this section to allow pushing this gem to any host.
|
18
14
|
if s.respond_to?(:metadata)
|
19
15
|
s.metadata['allowed_push_host'] = "https://rubygems.org"
|
20
16
|
else
|
@@ -22,11 +18,11 @@ Gem::Specification.new do |s|
|
|
22
18
|
end
|
23
19
|
|
24
20
|
s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
-
s.bindir = "
|
26
|
-
s.executables =
|
21
|
+
s.bindir = "bin"
|
22
|
+
s.executables = ["sandoz"]
|
27
23
|
s.require_paths = ["lib"]
|
28
24
|
|
29
25
|
s.add_development_dependency 'bundler', '~> 1.11'
|
30
|
-
s.add_dependency 'sinatra', '~> 1.4'
|
31
26
|
s.add_dependency 'opal', '~> 0.9'
|
27
|
+
s.add_dependency 'thor', '~> 0.19.1'
|
32
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sandoz
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.52
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Harley Swick
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -25,37 +25,38 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.11'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: opal
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0.9'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0.9'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: thor
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 0.19.1
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
55
|
-
description:
|
54
|
+
version: 0.19.1
|
55
|
+
description: Ruby p5.js wrapper for trippy visuals.
|
56
56
|
email:
|
57
57
|
- hswick@example.com
|
58
|
-
executables:
|
58
|
+
executables:
|
59
|
+
- sandoz
|
59
60
|
extensions: []
|
60
61
|
extra_rdoc_files: []
|
61
62
|
files:
|
@@ -63,16 +64,15 @@ files:
|
|
63
64
|
- CODE_OF_CONDUCT.md
|
64
65
|
- CONTRIBUTING.md
|
65
66
|
- Gemfile
|
66
|
-
- Gemfile.lock
|
67
67
|
- LICENSE.txt
|
68
68
|
- README.md
|
69
69
|
- Rakefile
|
70
70
|
- bin/console
|
71
|
+
- bin/sandoz
|
71
72
|
- bin/setup
|
73
|
+
- lib/cli.rb
|
72
74
|
- lib/sandoz.rb
|
73
75
|
- lib/sandoz/sandoz.rb
|
74
|
-
- lib/sandoz/sandoz/sandoz.rb
|
75
|
-
- lib/sandoz/sandoz/version.rb
|
76
76
|
- lib/sandoz/version.rb
|
77
77
|
- sandoz.gemspec
|
78
78
|
homepage: https://github.com/hswick/sandoz
|
data/lib/sandoz/sandoz/sandoz.rb
DELETED
@@ -1,140 +0,0 @@
|
|
1
|
-
module Sandoz
|
2
|
-
# https://github.com/processing/p5.js/wiki/p5.js-overview#instantiation--namespace
|
3
|
-
# TODO Add html element argument
|
4
|
-
def defsketch(id, &block)
|
5
|
-
sketch = Proc.new do |p|
|
6
|
-
init(p)
|
7
|
-
block.call
|
8
|
-
end
|
9
|
-
@p5 = `new p5(#{sketch}, #{id})`
|
10
|
-
end
|
11
|
-
|
12
|
-
def view_p
|
13
|
-
`return #{@p5}`
|
14
|
-
end
|
15
|
-
|
16
|
-
def init(p)
|
17
|
-
@@p = p
|
18
|
-
end
|
19
|
-
|
20
|
-
def size(w, h)
|
21
|
-
`#{@@p}.createCanvas(#{w}, #{h})`
|
22
|
-
end
|
23
|
-
|
24
|
-
def background(r, g=nil, b=nil)
|
25
|
-
if g == nil && b == nil
|
26
|
-
`#{@@p}.background(#{r})`
|
27
|
-
else
|
28
|
-
`#{@@p}.background(#{r}, #{g}, #{b})`
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def fill(r, g=nil, b=nil, a=nil)
|
33
|
-
if g==nil && b ==nil
|
34
|
-
`#{@@p}.fill(#{r})`
|
35
|
-
elsif a == nil
|
36
|
-
`#{@@p}.fill(#{r}, #{g}, #{b})`
|
37
|
-
else
|
38
|
-
`#{@@p}.fill(#{r}, #{g}, #{b}, #{a})`
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def rect(x, y, w, h)
|
43
|
-
`#{@@p}.rect(#{x}, #{y}, #{w}, #{h})`
|
44
|
-
end
|
45
|
-
|
46
|
-
def ellipse(x, y, w, h)
|
47
|
-
`#{@@p}.ellipse(#{x}, #{y}, #{w}, #{h})`
|
48
|
-
end
|
49
|
-
|
50
|
-
def width
|
51
|
-
`#{@@p}.width`
|
52
|
-
end
|
53
|
-
|
54
|
-
def height
|
55
|
-
`#{@@p}.height`
|
56
|
-
end
|
57
|
-
|
58
|
-
def line(x1, y1, x2, y2)
|
59
|
-
`#{@@p}.line(#{x1}, #{y1}, #{x2}, #{y2})`
|
60
|
-
end
|
61
|
-
|
62
|
-
def point(x, y)
|
63
|
-
`#{@@p}.point(#{x}, #{y})`
|
64
|
-
end
|
65
|
-
|
66
|
-
def stroke(r, g=nil, b=nil, a=nil)
|
67
|
-
if g==nil && b ==nil
|
68
|
-
`#{@@p}.stroke(#{r})`
|
69
|
-
elsif a == nil
|
70
|
-
`#{@@p}.stroke(#{r}, #{g}, #{b})`
|
71
|
-
else
|
72
|
-
`#{@@p}.stroke(#{r}, #{g}, #{b}, #{a})`
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def no_stroke
|
77
|
-
`#{@@p}.noStroke()`
|
78
|
-
end
|
79
|
-
|
80
|
-
def stroke_weight(weight)
|
81
|
-
`#{@@p}.strokeWeight(#{weight})`
|
82
|
-
end
|
83
|
-
|
84
|
-
def setup(&block)
|
85
|
-
`#{@@p}.setup = #{block}`
|
86
|
-
end
|
87
|
-
|
88
|
-
def draw(&block)
|
89
|
-
`#{@@p}.draw = #{block}`
|
90
|
-
end
|
91
|
-
|
92
|
-
def dist(x1, y1, x2, y2)
|
93
|
-
`return #{@@p}.dist(x1, y1, x2, y2)`
|
94
|
-
end
|
95
|
-
|
96
|
-
def random(min, max=nil)
|
97
|
-
if max
|
98
|
-
`return #{@@p}.random(#{min}, #{max})`
|
99
|
-
else
|
100
|
-
`return #{@@p}.random(#{min})`
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
def color(r, g=nil, b=nil, a=nil)
|
105
|
-
if g==nil && b ==nil
|
106
|
-
`return #{@@p}.color(#{r})`
|
107
|
-
elsif a == nil
|
108
|
-
`return #{@@p}.color(#{r}, #{g}, #{b})`
|
109
|
-
else
|
110
|
-
`return #{@@p}.color(#{r}, #{g}, #{b}, #{a})`
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
def map(value, start1, stop1, start2, stop2)
|
115
|
-
`return #{@@p}.map(#{value}, #{start1}, #{stop1}, #{start2}, #{stop2})`
|
116
|
-
end
|
117
|
-
|
118
|
-
def millis
|
119
|
-
`return #{@@p}.millis();`
|
120
|
-
end
|
121
|
-
|
122
|
-
def no_fill
|
123
|
-
`#{@@p}.noFill()`
|
124
|
-
end
|
125
|
-
|
126
|
-
def noise(x, y=nil, z=nil)
|
127
|
-
if y == nil && z == nil
|
128
|
-
`return #{@@p}.noise(#{x})`
|
129
|
-
elsif z == nil
|
130
|
-
`return #{@@p}.noise(#{x}, #{y})`
|
131
|
-
else
|
132
|
-
`return #{@@p}.noise(#{x}, #{y}, #{z})`
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
def text(text, x, y)
|
137
|
-
`#{@@p}.text(#{text}, #{x}, #{y})`
|
138
|
-
end
|
139
|
-
|
140
|
-
end
|