Module: Sandoz
- Defined in:
- lib/sandoz.rb,
lib/sandoz/version.rb
Constant Summary collapse
- VERSION =
"0.1.1"
Instance Method Summary collapse
- #background(r, g = nil, b = nil) ⇒ Object
- #color(r, g = nil, b = nil, a = nil) ⇒ Object
-
#defsketch(id, &block) ⇒ Object
github.com/processing/p5.js/wiki/p5.js-overview#instantiation–namespace todo Add html element argument.
- #dist(x1, y1, x2, y2) ⇒ Object
- #draw(&block) ⇒ Object
- #ellipse(x, y, w, h) ⇒ Object
- #fill(r, g = nil, b = nil, a = nil) ⇒ Object
- #height ⇒ Object
- #init(p) ⇒ Object
- #line(x1, y1, x2, y2) ⇒ Object
- #map(value, start1, stop1, start2, stop2) ⇒ Object
- #millis ⇒ Object
- #no_fill ⇒ Object
- #no_stroke ⇒ Object
- #noise(x, y = nil, z = nil) ⇒ Object
- #point(x, y) ⇒ Object
- #random(min, max = nil) ⇒ Object
- #rect(x, y, w, h) ⇒ Object
- #setup(&block) ⇒ Object
- #size(w, h) ⇒ Object
- #stroke(r, g = nil, b = nil, a = nil) ⇒ Object
- #stroke_weight(weight) ⇒ Object
- #text(text, x, y) ⇒ Object
- #view_p ⇒ Object
- #width ⇒ Object
Instance Method Details
#background(r, g = nil, b = nil) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/sandoz.rb', line 26 def background(r, g=nil, b=nil) if g == nil && b == nil `#{@@p}.background(#{r})` else `#{@@p}.background(#{r}, #{g}, #{b})` end end |
#color(r, g = nil, b = nil, a = nil) ⇒ Object
106 107 108 109 110 111 112 113 114 |
# File 'lib/sandoz.rb', line 106 def color(r, g=nil, b=nil, a=nil) if g==nil && b ==nil `return #{@@p}.color(#{r})` elsif a == nil `return #{@@p}.color(#{r}, #{g}, #{b})` else `return #{@@p}.color(#{r}, #{g}, #{b}, #{a})` end end |
#defsketch(id, &block) ⇒ Object
github.com/processing/p5.js/wiki/p5.js-overview#instantiation–namespace todo Add html element argument
6 7 8 9 10 11 12 |
# File 'lib/sandoz.rb', line 6 def defsketch(id, &block) sketch = Proc.new do |p| init(p) block.call end @p5 = `new p5(#{sketch}, #{id})` end |
#dist(x1, y1, x2, y2) ⇒ Object
94 95 96 |
# File 'lib/sandoz.rb', line 94 def dist(x1, y1, x2, y2) `return #{@@p}.dist(x1, y1, x2, y2)` end |
#draw(&block) ⇒ Object
90 91 92 |
# File 'lib/sandoz.rb', line 90 def draw(&block) `#{@@p}.draw = #{block}` end |
#ellipse(x, y, w, h) ⇒ Object
48 49 50 |
# File 'lib/sandoz.rb', line 48 def ellipse(x, y, w, h) `#{@@p}.ellipse(#{x}, #{y}, #{w}, #{h})` end |
#fill(r, g = nil, b = nil, a = nil) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/sandoz.rb', line 34 def fill(r, g=nil, b=nil, a=nil) if g==nil && b ==nil `#{@@p}.fill(#{r})` elsif a == nil `#{@@p}.fill(#{r}, #{g}, #{b})` else `#{@@p}.fill(#{r}, #{g}, #{b}, #{a})` end end |
#height ⇒ Object
56 57 58 |
# File 'lib/sandoz.rb', line 56 def height `#{@@p}.height` end |
#init(p) ⇒ Object
18 19 20 |
# File 'lib/sandoz.rb', line 18 def init(p) @@p = p end |
#line(x1, y1, x2, y2) ⇒ Object
60 61 62 |
# File 'lib/sandoz.rb', line 60 def line(x1, y1, x2, y2) `#{@@p}.line(#{x1}, #{y1}, #{x2}, #{y2})` end |
#map(value, start1, stop1, start2, stop2) ⇒ Object
116 117 118 |
# File 'lib/sandoz.rb', line 116 def map(value, start1, stop1, start2, stop2) `return #{@@p}.map(#{value}, #{start1}, #{stop1}, #{start2}, #{stop2})` end |
#millis ⇒ Object
120 121 122 |
# File 'lib/sandoz.rb', line 120 def millis `return #{@@p}.millis();` end |
#no_fill ⇒ Object
124 125 126 |
# File 'lib/sandoz.rb', line 124 def no_fill `#{@@p}.noFill()` end |
#no_stroke ⇒ Object
78 79 80 |
# File 'lib/sandoz.rb', line 78 def no_stroke `#{@@p}.noStroke()` end |
#noise(x, y = nil, z = nil) ⇒ Object
128 129 130 131 132 133 134 135 136 |
# File 'lib/sandoz.rb', line 128 def noise(x, y=nil, z=nil) if y == nil && z == nil `return #{@@p}.noise(#{x})` elsif z == nil `return #{@@p}.noise(#{x}, #{y})` else `return #{@@p}.noise(#{x}, #{y}, #{z})` end end |
#point(x, y) ⇒ Object
64 65 66 |
# File 'lib/sandoz.rb', line 64 def point(x, y) `#{@@p}.point(#{x}, #{y})` end |
#random(min, max = nil) ⇒ Object
98 99 100 101 102 103 104 |
# File 'lib/sandoz.rb', line 98 def random(min, max=nil) if max `return #{@@p}.random(#{min}, #{max})` else `return #{@@p}.random(#{min})` end end |
#rect(x, y, w, h) ⇒ Object
44 45 46 |
# File 'lib/sandoz.rb', line 44 def rect(x, y, w, h) `#{@@p}.rect(#{x}, #{y}, #{w}, #{h})` end |
#setup(&block) ⇒ Object
86 87 88 |
# File 'lib/sandoz.rb', line 86 def setup(&block) `#{@@p}.setup = #{block}` end |
#size(w, h) ⇒ Object
22 23 24 |
# File 'lib/sandoz.rb', line 22 def size(w, h) `#{@@p}.createCanvas(#{w}, #{h})` end |
#stroke(r, g = nil, b = nil, a = nil) ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'lib/sandoz.rb', line 68 def stroke(r, g=nil, b=nil, a=nil) if g==nil && b ==nil `#{@@p}.stroke(#{r})` elsif a == nil `#{@@p}.stroke(#{r}, #{g}, #{b})` else `#{@@p}.stroke(#{r}, #{g}, #{b}, #{a})` end end |
#stroke_weight(weight) ⇒ Object
82 83 84 |
# File 'lib/sandoz.rb', line 82 def stroke_weight(weight) `#{@@p}.strokeWeight(#{weight})` end |
#text(text, x, y) ⇒ Object
138 139 140 |
# File 'lib/sandoz.rb', line 138 def text(text, x, y) `#{@@p}.text(#{text}, #{x}, #{y})` end |
#view_p ⇒ Object
14 15 16 |
# File 'lib/sandoz.rb', line 14 def view_p `return #{@p5}` end |
#width ⇒ Object
52 53 54 |
# File 'lib/sandoz.rb', line 52 def width `#{@@p}.width` end |