Class: RubySketch::Processing::Context
- Inherits:
-
Object
- Object
- RubySketch::Processing::Context
- Includes:
- GraphicsContext
- Defined in:
- lib/rubysketch/processing.rb
Overview
Processing context
Constant Summary collapse
- Vector =
Processing::Vector
- Capture =
Processing::Capture
- Graphics =
Processing::Graphics
Constants included from GraphicsContext
GraphicsContext::BASELINE, GraphicsContext::BOTTOM, GraphicsContext::BUTT, GraphicsContext::CENTER, GraphicsContext::CORNER, GraphicsContext::CORNERS, GraphicsContext::DEGREES, GraphicsContext::HALF_PI, GraphicsContext::HSB, GraphicsContext::LEFT, GraphicsContext::MITER, GraphicsContext::PI, GraphicsContext::QUARTER_PI, GraphicsContext::RADIANS, GraphicsContext::RADIUS, GraphicsContext::RGB, GraphicsContext::RIGHT, GraphicsContext::ROUND, GraphicsContext::SQUARE, GraphicsContext::TAU, GraphicsContext::TOP, GraphicsContext::TWO_PI
Instance Method Summary collapse
-
#abs(value) ⇒ Numeric
Returns the absolute number of the value.
-
#acos(value) ⇒ Numeric
Returns the inverse of cos().
-
#asin(value) ⇒ Numeric
Returns the inverse of sin().
-
#atan(value) ⇒ Numeric
Returns the inverse of tan().
-
#atan2(y, x) ⇒ Numeric
Returns the angle from a specified point.
-
#ceil(value) ⇒ Numeric
Returns the closest integer number greater than or equal to the value.
-
#constrain(value, min, max) ⇒ Numeric
Constrains the number between min..max.
-
#cos(angle) ⇒ Numeric
Returns the cosine of an angle.
-
#createCapture(*args) ⇒ Capture
Creates a camera object as a video input device.
-
#createGraphics(width, height) ⇒ Graphics
Creates a new off-screen graphics context object.
-
#createVector(*args) ⇒ Vector
Creates a new vector.
-
#degrees(radian) ⇒ Numeric
Converts radian to degree.
-
#displayDensity ⇒ Numeric
Returns pixel density.
-
#dist(*args) ⇒ Numeric
Returns distance between 2 points.
-
#draw(&block) ⇒ Object
Define draw block.
-
#exp(n) ⇒ Numeric
Returns Euler's number e raised to the power of value.
-
#floor(value) ⇒ Numeric
Returns the closest integer number less than or equal to the value.
-
#frameCount ⇒ Integer
Returns number of frames since program started.
-
#frameRate ⇒ Float
Returns number of frames per second.
- #key(&block) ⇒ Object
-
#lerp(start, stop, amount) ⇒ Numeric
Returns the interpolated number between range start..stop.
-
#loadImage(filename, extension = nil) ⇒ Image
Loads image.
-
#log(n) ⇒ Numeric
Returns the natural logarithm (the base-e logarithm) of a number.
-
#loop ⇒ nil
Enables calling draw block on every frame.
-
#mag(*args) ⇒ Numeric
Returns the magnitude (or length) of a vector.
-
#map(value, start1, stop1, start2, stop2) ⇒ Numeric
Maps a number from range start1..stop1 to range start2..stop2.
-
#max(*args) ⇒ Numeric
Returns maximum value.
-
#min(*args) ⇒ Numeric
Returns minimum value.
- #mouseDragged(&block) ⇒ Object
- #mouseMoved(&block) ⇒ Object
- #mousePressed(&block) ⇒ Object
- #mouseReleased(&block) ⇒ Object
-
#mouseX ⇒ Numeric
Returns mouse x position.
-
#mouseY ⇒ Numeric
Returns mouse y position.
-
#noise(x, y = 0, z = 0) ⇒ Numeric
Returns the perlin noise value.
-
#noLoop ⇒ nil
Disables calling draw block on every frame.
-
#norm(value, start, stop) ⇒ Numeric
Normalize the value from range start..stop into 0..1.
-
#pmouseX ⇒ Numeric
Returns mouse x position in previous frame.
-
#pmouseY ⇒ Numeric
Returns mouse y position in previous frame.
-
#pow(value, exponent) ⇒ Numeric
Returns value raised to the power of exponent.
-
#radians(degree) ⇒ Numeric
Converts degree to radian.
-
#random(*args) ⇒ Float
Returns a random number in range low…high.
-
#redraw ⇒ nil
Calls draw block to redraw frame.
-
#round(value) ⇒ Numeric
Returns the closest integer number.
-
#setup(&block) ⇒ Object
Define setup block.
-
#sin(angle) ⇒ Numeric
Returns the sine of an angle.
-
#sq(value) ⇒ Numeric
Returns squared value.
-
#sqrt(value) ⇒ Numeric
Returns squared value.
-
#tan(angle) ⇒ Numeric
Returns the ratio of the sine and cosine of an angle.
- #touchEnded(&block) ⇒ Object
-
#touches ⇒ Array
Returns array of touches.
- #touchMoved(&block) ⇒ Object
- #touchStarted(&block) ⇒ Object
- #windowHeight ⇒ Object
- #windowWidth ⇒ Object
Methods included from GraphicsContext
#angleMode, #arc, #background, #bezier, #circle, #colorMode, #copy, #curve, #ellipse, #ellipseMode, #fill, #height, #image, #imageMode, #line, #noFill, #noStroke, #point, #pop, #popMatrix, #popStyle, #push, #pushMatrix, #pushStyle, #quad, #rect, #rectMode, #resetMatrix, #rotate, #scale, #setup__, #square, #stroke, #strokeCap, #strokeJoin, #strokeWeight, #text, #textAlign, #textAscent, #textDescent, #textFont, #textSize, #textWidth, #translate, #triangle, #width
Instance Method Details
#abs(value) ⇒ Numeric
Returns the absolute number of the value.
1997 1998 1999 |
# File 'lib/rubysketch/processing.rb', line 1997 def abs (value) value.abs end |
#acos(value) ⇒ Numeric
Returns the inverse of cos().
2280 2281 2282 |
# File 'lib/rubysketch/processing.rb', line 2280 def acos (value) Math.acos value end |
#asin(value) ⇒ Numeric
Returns the inverse of sin().
2270 2271 2272 |
# File 'lib/rubysketch/processing.rb', line 2270 def asin (value) Math.asin value end |
#atan(value) ⇒ Numeric
Returns the inverse of tan().
2290 2291 2292 |
# File 'lib/rubysketch/processing.rb', line 2290 def atan (value) Math.atan value end |
#atan2(y, x) ⇒ Numeric
Returns the angle from a specified point.
2301 2302 2303 |
# File 'lib/rubysketch/processing.rb', line 2301 def atan2 (y, x) Math.atan2 y, x end |
#ceil(value) ⇒ Numeric
Returns the closest integer number greater than or equal to the value.
2007 2008 2009 |
# File 'lib/rubysketch/processing.rb', line 2007 def ceil (value) value.ceil end |
#constrain(value, min, max) ⇒ Numeric
Constrains the number between min..max.
2210 2211 2212 |
# File 'lib/rubysketch/processing.rb', line 2210 def constrain (value, min, max) value < min ? min : (value > max ? max : value) end |
#cos(angle) ⇒ Numeric
Returns the cosine of an angle.
2250 2251 2252 |
# File 'lib/rubysketch/processing.rb', line 2250 def cos (angle) Math.cos angle end |
#createCapture(*args) ⇒ Capture
Creates a camera object as a video input device.
2360 2361 2362 |
# File 'lib/rubysketch/processing.rb', line 2360 def createCapture (*args) Capture.new *args end |
#createGraphics(width, height) ⇒ Graphics
Creates a new off-screen graphics context object.
2371 2372 2373 |
# File 'lib/rubysketch/processing.rb', line 2371 def createGraphics (width, height) Graphics.new width, height end |
#createVector ⇒ Vector #createVector(x, y) ⇒ Vector #createVector(x, y, z) ⇒ Vector
Creates a new vector.
2352 2353 2354 |
# File 'lib/rubysketch/processing.rb', line 2352 def createVector (*args) Vector.new *args end |
#degrees(radian) ⇒ Numeric
Converts radian to degree.
2230 2231 2232 |
# File 'lib/rubysketch/processing.rb', line 2230 def degrees (radian) radian * RAD2DEG__ end |
#displayDensity ⇒ Numeric
Returns pixel density
1919 1920 1921 |
# File 'lib/rubysketch/processing.rb', line 1919 def displayDensity () @painter__.pixel_density end |
#dist(x1, y1, x2, y2) ⇒ Numeric #dist(x1, y1, z1, x2, y2, z2) ⇒ Numeric
Returns distance between 2 points.
2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 |
# File 'lib/rubysketch/processing.rb', line 2116 def dist (*args) case args.size when 4 x1, y1, x2, y2 = *args xx, yy = x2 - x1, y2 - y1 Math.sqrt xx * xx + yy * yy when 3 x1, y1, z1, x2, y2, z2 = *args xx, yy, zz = x2 - x1, y2 - y1, z2 - z1 Math.sqrt xx * xx + yy * yy + zz * zz else raise ArgumentError end end |
#draw(&block) ⇒ Object
Define draw block.
1835 1836 1837 1838 |
# File 'lib/rubysketch/processing.rb', line 1835 def draw (&block) @drawBlock__ = block if block nil end |
#exp(n) ⇒ Numeric
Returns Euler's number e raised to the power of value.
2047 2048 2049 |
# File 'lib/rubysketch/processing.rb', line 2047 def exp (n) Math.exp n end |
#floor(value) ⇒ Numeric
Returns the closest integer number less than or equal to the value.
2017 2018 2019 |
# File 'lib/rubysketch/processing.rb', line 2017 def floor (value) value.floor end |
#frameCount ⇒ Integer
Returns number of frames since program started.
1903 1904 1905 |
# File 'lib/rubysketch/processing.rb', line 1903 def frameCount () @frameCount__ end |
#frameRate ⇒ Float
Returns number of frames per second.
1911 1912 1913 |
# File 'lib/rubysketch/processing.rb', line 1911 def frameRate () @window__.event.fps end |
#key(&block) ⇒ Object
1840 1841 1842 1843 |
# File 'lib/rubysketch/processing.rb', line 1840 def key (&block) @window__.key = block nil end |
#lerp(start, stop, amount) ⇒ Numeric
Returns the interpolated number between range start..stop.
2150 2151 2152 |
# File 'lib/rubysketch/processing.rb', line 2150 def lerp (start, stop, amount) start + (stop - start) * amount end |
#loadImage(filename, extension = nil) ⇒ Image
Loads image.
2382 2383 2384 2385 |
# File 'lib/rubysketch/processing.rb', line 2382 def loadImage (filename, extension = nil) filename = getImage__ filename, extension if filename =~ %r|^https?://| Image.new Rays::Image.load filename end |
#log(n) ⇒ Numeric
Returns the natural logarithm (the base-e logarithm) of a number.
2037 2038 2039 |
# File 'lib/rubysketch/processing.rb', line 2037 def log (n) Math.log n end |
#loop ⇒ nil
Enables calling draw block on every frame.
1967 1968 1969 |
# File 'lib/rubysketch/processing.rb', line 1967 def loop () @loop__ = true end |
#mag(x, y) ⇒ Numeric #mag(x, y, z) ⇒ Numeric
Returns the magnitude (or length) of a vector.
2093 2094 2095 2096 2097 2098 2099 2100 |
# File 'lib/rubysketch/processing.rb', line 2093 def mag (*args) x, y, z = *args case args.size when 2 then Math.sqrt x * x + y * y when 3 then Math.sqrt x * x + y * y + z * z else raise ArgumentError end end |
#map(value, start1, stop1, start2, stop2) ⇒ Numeric
Maps a number from range start1..stop1 to range start2..stop2.
2164 2165 2166 |
# File 'lib/rubysketch/processing.rb', line 2164 def map (value, start1, stop1, start2, stop2) lerp start2, stop2, norm(value, start1, stop1) end |
#max(a, b) ⇒ Numeric #max(a, b, c) ⇒ Numeric #max(array) ⇒ Numeric
Returns maximum value.
2198 2199 2200 |
# File 'lib/rubysketch/processing.rb', line 2198 def max (*args) args.flatten.max end |
#min(a, b) ⇒ Numeric #min(a, b, c) ⇒ Numeric #min(array) ⇒ Numeric
Returns minimum value.
2181 2182 2183 |
# File 'lib/rubysketch/processing.rb', line 2181 def min (*args) args.flatten.min end |
#mouseDragged(&block) ⇒ Object
1860 1861 1862 1863 |
# File 'lib/rubysketch/processing.rb', line 1860 def mouseDragged (&block) @mouseDraggedBlock__ = block if block nil end |
#mouseMoved(&block) ⇒ Object
1855 1856 1857 1858 |
# File 'lib/rubysketch/processing.rb', line 1855 def mouseMoved (&block) @mouseMovedBlock__ = block if block nil end |
#mousePressed(&block) ⇒ Object
1845 1846 1847 1848 |
# File 'lib/rubysketch/processing.rb', line 1845 def mousePressed (&block) @mousePressedBlock__ = block if block @mousePressed__ end |
#mouseReleased(&block) ⇒ Object
1850 1851 1852 1853 |
# File 'lib/rubysketch/processing.rb', line 1850 def mouseReleased (&block) @mouseReleasedBlock__ = block if block nil end |
#mouseX ⇒ Numeric
Returns mouse x position
1927 1928 1929 |
# File 'lib/rubysketch/processing.rb', line 1927 def mouseX () @mousePos__.x end |
#mouseY ⇒ Numeric
Returns mouse y position
1935 1936 1937 |
# File 'lib/rubysketch/processing.rb', line 1935 def mouseY () @mousePos__.y end |
#noise(x) ⇒ Numeric #noise(x, y) ⇒ Numeric #noise(x, y, z) ⇒ Numeric
Returns the perlin noise value.
2317 2318 2319 |
# File 'lib/rubysketch/processing.rb', line 2317 def noise (x, y = 0, z = 0) Rays.perlin(x, y, z) / 2.0 + 0.5 end |
#noLoop ⇒ nil
Disables calling draw block on every frame.
1975 1976 1977 |
# File 'lib/rubysketch/processing.rb', line 1975 def noLoop () @loop__ = false end |
#norm(value, start, stop) ⇒ Numeric
Normalize the value from range start..stop into 0..1.
2138 2139 2140 |
# File 'lib/rubysketch/processing.rb', line 2138 def norm (value, start, stop) (value.to_f - start.to_f) / (stop.to_f - start.to_f) end |
#pmouseX ⇒ Numeric
Returns mouse x position in previous frame
1943 1944 1945 |
# File 'lib/rubysketch/processing.rb', line 1943 def pmouseX () @mousePrevPos__.x end |
#pmouseY ⇒ Numeric
Returns mouse y position in previous frame
1951 1952 1953 |
# File 'lib/rubysketch/processing.rb', line 1951 def pmouseY () @mousePrevPos__.y end |
#pow(value, exponent) ⇒ Numeric
Returns value raised to the power of exponent.
2058 2059 2060 |
# File 'lib/rubysketch/processing.rb', line 2058 def pow (value, exponent) value ** exponent end |
#radians(degree) ⇒ Numeric
Converts degree to radian.
2220 2221 2222 |
# File 'lib/rubysketch/processing.rb', line 2220 def radians (degree) degree * DEG2RAD__ end |
#random ⇒ Float #random(high) ⇒ Float #random(low, high) ⇒ Float #random(choices) ⇒ Float
Returns a random number in range low…high
2334 2335 2336 2337 2338 |
# File 'lib/rubysketch/processing.rb', line 2334 def random (*args) return args.first.sample if args.first.kind_of? Array high, low = args.reverse rand (low || 0).to_f...(high || 1).to_f end |
#redraw ⇒ nil
Calls draw block to redraw frame.
1983 1984 1985 |
# File 'lib/rubysketch/processing.rb', line 1983 def redraw () @redraw__ = true end |
#round(value) ⇒ Numeric
Returns the closest integer number.
2027 2028 2029 |
# File 'lib/rubysketch/processing.rb', line 2027 def round (value) value.round end |
#setup(&block) ⇒ Object
Define setup block.
1828 1829 1830 1831 |
# File 'lib/rubysketch/processing.rb', line 1828 def setup (&block) @window__.setup = block nil end |
#sin(angle) ⇒ Numeric
Returns the sine of an angle.
2240 2241 2242 |
# File 'lib/rubysketch/processing.rb', line 2240 def sin (angle) Math.sin angle end |
#sq(value) ⇒ Numeric
Returns squared value.
2068 2069 2070 |
# File 'lib/rubysketch/processing.rb', line 2068 def sq (value) value * value end |
#sqrt(value) ⇒ Numeric
Returns squared value.
2078 2079 2080 |
# File 'lib/rubysketch/processing.rb', line 2078 def sqrt (value) Math.sqrt value end |
#tan(angle) ⇒ Numeric
Returns the ratio of the sine and cosine of an angle.
2260 2261 2262 |
# File 'lib/rubysketch/processing.rb', line 2260 def tan (angle) Math.tan angle end |
#touchEnded(&block) ⇒ Object
1870 1871 1872 1873 |
# File 'lib/rubysketch/processing.rb', line 1870 def touchEnded (&block) @touchEndedBlock__ = block if block nil end |
#touches ⇒ Array
Returns array of touches
1959 1960 1961 |
# File 'lib/rubysketch/processing.rb', line 1959 def touches () @touches__ end |
#touchMoved(&block) ⇒ Object
1875 1876 1877 1878 |
# File 'lib/rubysketch/processing.rb', line 1875 def touchMoved (&block) @touchMovedBlock__ = block if block nil end |
#touchStarted(&block) ⇒ Object
1865 1866 1867 1868 |
# File 'lib/rubysketch/processing.rb', line 1865 def touchStarted (&block) @touchStartedBlock__ = block if block nil end |
#windowHeight ⇒ Object
1895 1896 1897 |
# File 'lib/rubysketch/processing.rb', line 1895 def windowHeight () @window__.height end |
#windowWidth ⇒ Object
1891 1892 1893 |
# File 'lib/rubysketch/processing.rb', line 1891 def windowWidth () @window__.width end |