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.
-
#createCanvas(width, height, pixelDensity: self.pixelDensity) ⇒ nil
Changes canvas size.
-
#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 of display.
-
#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.
-
#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
Define mouseDragged block.
-
#mouseMoved(&block) ⇒ Object
Define mouseMoved block.
-
#mousePressed(&block) ⇒ Object
Define mousePressed block.
-
#mouseReleased(&block) ⇒ Object
Define mouseReleased block.
-
#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.
-
#pixelDensity(density = nil) ⇒ Numeric
Changes and returns canvas pixel density.
-
#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.
-
#size(width, height, pixelDensity: self.pixelDensity) ⇒ nil
Changes canvas size.
-
#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
Define touchEnded block.
-
#touches ⇒ Array
Returns array of touches.
-
#touchMoved(&block) ⇒ Object
Define touchMoved block.
-
#touchStarted(&block) ⇒ Object
Define touchStarted block.
-
#windowHeight ⇒ Numeric
Returns window height.
-
#windowWidth ⇒ Numeric
Returns window width.
Methods included from GraphicsContext
#angleMode, #arc, #background, #bezier, #circle, #colorMode, #copy, #curve, #ellipse, #ellipseMode, #fill, #height, #image, #imageMode, #init__, #line, #noFill, #noStroke, #point, #pop, #popMatrix, #popStyle, #push, #pushMatrix, #pushStyle, #quad, #rect, #rectMode, #resetMatrix, #rotate, #scale, #square, #stroke, #strokeCap, #strokeJoin, #strokeWeight, #text, #textAlign, #textAscent, #textDescent, #textFont, #textSize, #textWidth, #translate, #triangle, #updateCanvas__, #width
Instance Method Details
#abs(value) ⇒ Numeric
Returns the absolute number of the value.
2064 2065 2066 |
# File 'lib/rubysketch/processing.rb', line 2064 def abs (value) value.abs end |
#acos(value) ⇒ Numeric
Returns the inverse of cos().
2347 2348 2349 |
# File 'lib/rubysketch/processing.rb', line 2347 def acos (value) Math.acos value end |
#asin(value) ⇒ Numeric
Returns the inverse of sin().
2337 2338 2339 |
# File 'lib/rubysketch/processing.rb', line 2337 def asin (value) Math.asin value end |
#atan(value) ⇒ Numeric
Returns the inverse of tan().
2357 2358 2359 |
# File 'lib/rubysketch/processing.rb', line 2357 def atan (value) Math.atan value end |
#atan2(y, x) ⇒ Numeric
Returns the angle from a specified point.
2368 2369 2370 |
# File 'lib/rubysketch/processing.rb', line 2368 def atan2 (y, x) Math.atan2 y, x end |
#ceil(value) ⇒ Numeric
Returns the closest integer number greater than or equal to the value.
2074 2075 2076 |
# File 'lib/rubysketch/processing.rb', line 2074 def ceil (value) value.ceil end |
#constrain(value, min, max) ⇒ Numeric
Constrains the number between min..max.
2277 2278 2279 |
# File 'lib/rubysketch/processing.rb', line 2277 def constrain (value, min, max) value < min ? min : (value > max ? max : value) end |
#cos(angle) ⇒ Numeric
Returns the cosine of an angle.
2317 2318 2319 |
# File 'lib/rubysketch/processing.rb', line 2317 def cos (angle) Math.cos angle end |
#createCanvas(width, height, pixelDensity: self.pixelDensity) ⇒ nil
Changes canvas size.
1922 1923 1924 1925 |
# File 'lib/rubysketch/processing.rb', line 1922 def createCanvas (width, height, pixelDensity: self.pixelDensity) resizeCanvas__ :createCanvas, width, height, pixelDensity nil end |
#createCapture(*args) ⇒ Capture
Creates a camera object as a video input device.
2427 2428 2429 |
# File 'lib/rubysketch/processing.rb', line 2427 def createCapture (*args) Capture.new *args end |
#createGraphics(width, height) ⇒ Graphics
Creates a new off-screen graphics context object.
2438 2439 2440 |
# File 'lib/rubysketch/processing.rb', line 2438 def createGraphics (width, height) Graphics.new width, height end |
#createVector ⇒ Vector #createVector(x, y) ⇒ Vector #createVector(x, y, z) ⇒ Vector
Creates a new vector.
2419 2420 2421 |
# File 'lib/rubysketch/processing.rb', line 2419 def createVector (*args) Vector.new *args end |
#degrees(radian) ⇒ Numeric
Converts radian to degree.
2297 2298 2299 |
# File 'lib/rubysketch/processing.rb', line 2297 def degrees (radian) radian * RAD2DEG__ end |
#displayDensity ⇒ Numeric
Returns pixel density of display.
1954 1955 1956 |
# File 'lib/rubysketch/processing.rb', line 1954 def displayDensity () @window__.painter.pixel_density end |
#dist(x1, y1, x2, y2) ⇒ Numeric #dist(x1, y1, z1, x2, y2, z2) ⇒ Numeric
Returns distance between 2 points.
2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 |
# File 'lib/rubysketch/processing.rb', line 2183 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.
1841 1842 1843 1844 |
# File 'lib/rubysketch/processing.rb', line 1841 def draw (&block) @drawBlock__ = block if block nil end |
#exp(n) ⇒ Numeric
Returns Euler's number e raised to the power of value.
2114 2115 2116 |
# File 'lib/rubysketch/processing.rb', line 2114 def exp (n) Math.exp n end |
#floor(value) ⇒ Numeric
Returns the closest integer number less than or equal to the value.
2084 2085 2086 |
# File 'lib/rubysketch/processing.rb', line 2084 def floor (value) value.floor end |
#frameCount ⇒ Integer
Returns number of frames since program started.
1978 1979 1980 |
# File 'lib/rubysketch/processing.rb', line 1978 def frameCount () @frameCount__ end |
#frameRate ⇒ Float
Returns number of frames per second.
1986 1987 1988 |
# File 'lib/rubysketch/processing.rb', line 1986 def frameRate () @window__.event.fps end |
#lerp(start, stop, amount) ⇒ Numeric
Returns the interpolated number between range start..stop.
2217 2218 2219 |
# File 'lib/rubysketch/processing.rb', line 2217 def lerp (start, stop, amount) start + (stop - start) * amount end |
#loadImage(filename, extension = nil) ⇒ Image
Loads image.
2449 2450 2451 2452 |
# File 'lib/rubysketch/processing.rb', line 2449 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.
2104 2105 2106 |
# File 'lib/rubysketch/processing.rb', line 2104 def log (n) Math.log n end |
#loop ⇒ nil
Enables calling draw block on every frame.
2034 2035 2036 |
# File 'lib/rubysketch/processing.rb', line 2034 def loop () @loop__ = true end |
#mag(x, y) ⇒ Numeric #mag(x, y, z) ⇒ Numeric
Returns the magnitude (or length) of a vector.
2160 2161 2162 2163 2164 2165 2166 2167 |
# File 'lib/rubysketch/processing.rb', line 2160 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.
2231 2232 2233 |
# File 'lib/rubysketch/processing.rb', line 2231 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.
2265 2266 2267 |
# File 'lib/rubysketch/processing.rb', line 2265 def max (*args) args.flatten.max end |
#min(a, b) ⇒ Numeric #min(a, b, c) ⇒ Numeric #min(array) ⇒ Numeric
Returns minimum value.
2248 2249 2250 |
# File 'lib/rubysketch/processing.rb', line 2248 def min (*args) args.flatten.min end |
#mouseDragged(&block) ⇒ Object
Define mouseDragged block.
1875 1876 1877 1878 |
# File 'lib/rubysketch/processing.rb', line 1875 def mouseDragged (&block) @mouseDraggedBlock__ = block if block nil end |
#mouseMoved(&block) ⇒ Object
Define mouseMoved block.
1868 1869 1870 1871 |
# File 'lib/rubysketch/processing.rb', line 1868 def mouseMoved (&block) @mouseMovedBlock__ = block if block nil end |
#mousePressed(&block) ⇒ Object
Define mousePressed block.
1854 1855 1856 1857 |
# File 'lib/rubysketch/processing.rb', line 1854 def mousePressed (&block) @mousePressedBlock__ = block if block @mousePressed__ end |
#mouseReleased(&block) ⇒ Object
Define mouseReleased block.
1861 1862 1863 1864 |
# File 'lib/rubysketch/processing.rb', line 1861 def mouseReleased (&block) @mouseReleasedBlock__ = block if block nil end |
#mouseX ⇒ Numeric
Returns mouse x position
1994 1995 1996 |
# File 'lib/rubysketch/processing.rb', line 1994 def mouseX () @mousePos__[0] end |
#mouseY ⇒ Numeric
Returns mouse y position
2002 2003 2004 |
# File 'lib/rubysketch/processing.rb', line 2002 def mouseY () @mousePos__[1] end |
#noise(x) ⇒ Numeric #noise(x, y) ⇒ Numeric #noise(x, y, z) ⇒ Numeric
Returns the perlin noise value.
2384 2385 2386 |
# File 'lib/rubysketch/processing.rb', line 2384 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.
2042 2043 2044 |
# File 'lib/rubysketch/processing.rb', line 2042 def noLoop () @loop__ = false end |
#norm(value, start, stop) ⇒ Numeric
Normalize the value from range start..stop into 0..1.
2205 2206 2207 |
# File 'lib/rubysketch/processing.rb', line 2205 def norm (value, start, stop) (value.to_f - start.to_f) / (stop.to_f - start.to_f) end |
#pixelDensity(density = nil) ⇒ Numeric
Changes and returns canvas pixel density.
1933 1934 1935 1936 |
# File 'lib/rubysketch/processing.rb', line 1933 def pixelDensity (density = nil) resizeCanvas__ :pixelDensity, width, height, density if density @painter__.pixel_density end |
#pmouseX ⇒ Numeric
Returns mouse x position in previous frame
2010 2011 2012 |
# File 'lib/rubysketch/processing.rb', line 2010 def pmouseX () @mousePrevPos__[0] end |
#pmouseY ⇒ Numeric
Returns mouse y position in previous frame
2018 2019 2020 |
# File 'lib/rubysketch/processing.rb', line 2018 def pmouseY () @mousePrevPos__[1] end |
#pow(value, exponent) ⇒ Numeric
Returns value raised to the power of exponent.
2125 2126 2127 |
# File 'lib/rubysketch/processing.rb', line 2125 def pow (value, exponent) value ** exponent end |
#radians(degree) ⇒ Numeric
Converts degree to radian.
2287 2288 2289 |
# File 'lib/rubysketch/processing.rb', line 2287 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
2401 2402 2403 2404 2405 |
# File 'lib/rubysketch/processing.rb', line 2401 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.
2050 2051 2052 |
# File 'lib/rubysketch/processing.rb', line 2050 def redraw () @redraw__ = true end |
#round(value) ⇒ Numeric
Returns the closest integer number.
2094 2095 2096 |
# File 'lib/rubysketch/processing.rb', line 2094 def round (value) value.round end |
#setup(&block) ⇒ Object
Define setup block.
1834 1835 1836 1837 |
# File 'lib/rubysketch/processing.rb', line 1834 def setup (&block) @window__.setup = block nil end |
#sin(angle) ⇒ Numeric
Returns the sine of an angle.
2307 2308 2309 |
# File 'lib/rubysketch/processing.rb', line 2307 def sin (angle) Math.sin angle end |
#size(width, height, pixelDensity: self.pixelDensity) ⇒ nil
Changes canvas size.
1909 1910 1911 1912 |
# File 'lib/rubysketch/processing.rb', line 1909 def size (width, height, pixelDensity: self.pixelDensity) resizeCanvas__ :size, width, height, pixelDensity nil end |
#sq(value) ⇒ Numeric
Returns squared value.
2135 2136 2137 |
# File 'lib/rubysketch/processing.rb', line 2135 def sq (value) value * value end |
#sqrt(value) ⇒ Numeric
Returns squared value.
2145 2146 2147 |
# File 'lib/rubysketch/processing.rb', line 2145 def sqrt (value) Math.sqrt value end |
#tan(angle) ⇒ Numeric
Returns the ratio of the sine and cosine of an angle.
2327 2328 2329 |
# File 'lib/rubysketch/processing.rb', line 2327 def tan (angle) Math.tan angle end |
#touchEnded(&block) ⇒ Object
Define touchEnded block.
1889 1890 1891 1892 |
# File 'lib/rubysketch/processing.rb', line 1889 def touchEnded (&block) @touchEndedBlock__ = block if block nil end |
#touches ⇒ Array
Returns array of touches
2026 2027 2028 |
# File 'lib/rubysketch/processing.rb', line 2026 def touches () @touches__ end |
#touchMoved(&block) ⇒ Object
Define touchMoved block.
1896 1897 1898 1899 |
# File 'lib/rubysketch/processing.rb', line 1896 def touchMoved (&block) @touchMovedBlock__ = block if block nil end |
#touchStarted(&block) ⇒ Object
Define touchStarted block.
1882 1883 1884 1885 |
# File 'lib/rubysketch/processing.rb', line 1882 def touchStarted (&block) @touchStartedBlock__ = block if block nil end |
#windowHeight ⇒ Numeric
Returns window height.
1970 1971 1972 |
# File 'lib/rubysketch/processing.rb', line 1970 def windowHeight () @window__.height end |
#windowWidth ⇒ Numeric
Returns window width.
1962 1963 1964 |
# File 'lib/rubysketch/processing.rb', line 1962 def windowWidth () @window__.width end |