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::ALT, GraphicsContext::BACKSPACE, GraphicsContext::BASELINE, GraphicsContext::BOTTOM, GraphicsContext::BUTT, GraphicsContext::CAPSLOCK, GraphicsContext::CENTER, GraphicsContext::CLEAR, GraphicsContext::COMMAND, GraphicsContext::CONTROL, GraphicsContext::CORNER, GraphicsContext::CORNERS, GraphicsContext::DEGREES, GraphicsContext::DELETE, GraphicsContext::DOWN, GraphicsContext::ENTER, GraphicsContext::ESC, GraphicsContext::F1, GraphicsContext::F10, GraphicsContext::F11, GraphicsContext::F12, GraphicsContext::F13, GraphicsContext::F14, GraphicsContext::F15, GraphicsContext::F16, GraphicsContext::F17, GraphicsContext::F18, GraphicsContext::F19, GraphicsContext::F2, GraphicsContext::F20, GraphicsContext::F21, GraphicsContext::F22, GraphicsContext::F23, GraphicsContext::F24, GraphicsContext::F3, GraphicsContext::F4, GraphicsContext::F5, GraphicsContext::F6, GraphicsContext::F7, GraphicsContext::F8, GraphicsContext::F9, GraphicsContext::FUNCTION, GraphicsContext::HALF_PI, GraphicsContext::HELP, GraphicsContext::HOME, GraphicsContext::HSB, GraphicsContext::LEFT, GraphicsContext::MITER, GraphicsContext::OPTION, GraphicsContext::PAGEDOWN, GraphicsContext::PAGEUP, GraphicsContext::PI, GraphicsContext::QUARTER_PI, GraphicsContext::RADIANS, GraphicsContext::RADIUS, GraphicsContext::RGB, GraphicsContext::RIGHT, GraphicsContext::ROUND, GraphicsContext::SECTION, GraphicsContext::SHIFT, GraphicsContext::SPACE, GraphicsContext::SQUARE, GraphicsContext::TAB, GraphicsContext::TAU, GraphicsContext::TOP, GraphicsContext::TWO_PI, GraphicsContext::UP, GraphicsContext::WIN
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
Defines 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 ⇒ String
Returns the last key that was pressed or released.
-
#keyCode ⇒ Symbol
Returns the last key code that was pressed or released.
-
#keyPressed(&block) ⇒ Boolean
Defines keyPressed block.
-
#keyReleased(&block) ⇒ Object
Defines keyReleased block.
-
#keyTyped(&block) ⇒ Object
Defines keyTyped block.
-
#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.
-
#motion(&block) ⇒ Object
Defines motion block.
-
#motionGravity ⇒ Vector
Returns vector for real world gravity.
-
#mouseDragged(&block) ⇒ Object
Defines mouseDragged block.
-
#mouseMoved(&block) ⇒ Object
Defines mouseMoved block.
-
#mousePressed(&block) ⇒ Boolean
Defines mousePressed block.
-
#mouseReleased(&block) ⇒ Object
Defines 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
Defines 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
Defines touchEnded block.
-
#touches ⇒ Array
Returns array of touches.
-
#touchMoved(&block) ⇒ Object
Defines touchMoved block.
-
#touchStarted(&block) ⇒ Object
Defines 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.
2195 2196 2197 |
# File 'lib/rubysketch/processing.rb', line 2195 def abs(value) value.abs end |
#acos(value) ⇒ Numeric
Returns the inverse of cos().
2478 2479 2480 |
# File 'lib/rubysketch/processing.rb', line 2478 def acos(value) Math.acos value end |
#asin(value) ⇒ Numeric
Returns the inverse of sin().
2468 2469 2470 |
# File 'lib/rubysketch/processing.rb', line 2468 def asin(value) Math.asin value end |
#atan(value) ⇒ Numeric
Returns the inverse of tan().
2488 2489 2490 |
# File 'lib/rubysketch/processing.rb', line 2488 def atan(value) Math.atan value end |
#atan2(y, x) ⇒ Numeric
Returns the angle from a specified point.
2499 2500 2501 |
# File 'lib/rubysketch/processing.rb', line 2499 def atan2(y, x) Math.atan2 y, x end |
#ceil(value) ⇒ Numeric
Returns the closest integer number greater than or equal to the value.
2205 2206 2207 |
# File 'lib/rubysketch/processing.rb', line 2205 def ceil(value) value.ceil end |
#constrain(value, min, max) ⇒ Numeric
Constrains the number between min..max.
2408 2409 2410 |
# File 'lib/rubysketch/processing.rb', line 2408 def constrain(value, min, max) value < min ? min : (value > max ? max : value) end |
#cos(angle) ⇒ Numeric
Returns the cosine of an angle.
2448 2449 2450 |
# File 'lib/rubysketch/processing.rb', line 2448 def cos(angle) Math.cos angle end |
#createCanvas(width, height, pixelDensity: self.pixelDensity) ⇒ nil
Changes canvas size.
2029 2030 2031 2032 |
# File 'lib/rubysketch/processing.rb', line 2029 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.
2558 2559 2560 |
# File 'lib/rubysketch/processing.rb', line 2558 def createCapture(*args) Capture.new(*args) end |
#createGraphics(width, height) ⇒ Graphics
Creates a new off-screen graphics context object.
2569 2570 2571 |
# File 'lib/rubysketch/processing.rb', line 2569 def createGraphics(width, height) Graphics.new width, height end |
#createVector ⇒ Vector #createVector(x, y) ⇒ Vector #createVector(x, y, z) ⇒ Vector
Creates a new vector.
2550 2551 2552 |
# File 'lib/rubysketch/processing.rb', line 2550 def createVector(*args) Vector.new(*args, context: self) end |
#degrees(radian) ⇒ Numeric
Converts radian to degree.
2428 2429 2430 |
# File 'lib/rubysketch/processing.rb', line 2428 def degrees(radian) radian * RAD2DEG__ end |
#displayDensity ⇒ Numeric
Returns pixel density of display.
2061 2062 2063 |
# File 'lib/rubysketch/processing.rb', line 2061 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.
2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 |
# File 'lib/rubysketch/processing.rb', line 2314 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
Defines draw block.
1922 1923 1924 1925 |
# File 'lib/rubysketch/processing.rb', line 1922 def draw(&block) @drawBlock__ = block if block nil end |
#exp(n) ⇒ Numeric
Returns Euler's number e raised to the power of value.
2245 2246 2247 |
# File 'lib/rubysketch/processing.rb', line 2245 def exp(n) Math.exp n end |
#floor(value) ⇒ Numeric
Returns the closest integer number less than or equal to the value.
2215 2216 2217 |
# File 'lib/rubysketch/processing.rb', line 2215 def floor(value) value.floor end |
#frameCount ⇒ Integer
Returns number of frames since program started.
2085 2086 2087 |
# File 'lib/rubysketch/processing.rb', line 2085 def frameCount() @frameCount__ end |
#frameRate ⇒ Float
Returns number of frames per second.
2093 2094 2095 |
# File 'lib/rubysketch/processing.rb', line 2093 def frameRate() @window__.event.fps end |
#key ⇒ String
Returns the last key that was pressed or released.
2101 2102 2103 |
# File 'lib/rubysketch/processing.rb', line 2101 def key() @key__ end |
#keyCode ⇒ Symbol
Returns the last key code that was pressed or released.
2109 2110 2111 |
# File 'lib/rubysketch/processing.rb', line 2109 def keyCode() @keyCode__ end |
#keyPressed(&block) ⇒ Boolean
Defines keyPressed block.
1931 1932 1933 1934 |
# File 'lib/rubysketch/processing.rb', line 1931 def keyPressed(&block) @keyPressedBlock__ = block if block not @keysPressed__.empty? end |
#keyReleased(&block) ⇒ Object
Defines keyReleased block.
1938 1939 1940 1941 |
# File 'lib/rubysketch/processing.rb', line 1938 def keyReleased(&block) @keyReleasedBlock__ = block if block nil end |
#keyTyped(&block) ⇒ Object
Defines keyTyped block.
1945 1946 1947 1948 |
# File 'lib/rubysketch/processing.rb', line 1945 def keyTyped(&block) @keyTypedBlock__ = block if block nil end |
#lerp(start, stop, amount) ⇒ Numeric
Returns the interpolated number between range start..stop.
2348 2349 2350 |
# File 'lib/rubysketch/processing.rb', line 2348 def lerp(start, stop, amount) start + (stop - start) * amount end |
#loadImage(filename, extension = nil) ⇒ Image
Loads image.
2580 2581 2582 2583 |
# File 'lib/rubysketch/processing.rb', line 2580 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.
2235 2236 2237 |
# File 'lib/rubysketch/processing.rb', line 2235 def log(n) Math.log n end |
#loop ⇒ nil
Enables calling draw block on every frame.
2165 2166 2167 |
# File 'lib/rubysketch/processing.rb', line 2165 def loop() @loop__ = true end |
#mag(x, y) ⇒ Numeric #mag(x, y, z) ⇒ Numeric
Returns the magnitude (or length) of a vector.
2291 2292 2293 2294 2295 2296 2297 2298 |
# File 'lib/rubysketch/processing.rb', line 2291 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.
2362 2363 2364 |
# File 'lib/rubysketch/processing.rb', line 2362 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.
2396 2397 2398 |
# File 'lib/rubysketch/processing.rb', line 2396 def max(*args) args.flatten.max end |
#min(a, b) ⇒ Numeric #min(a, b, c) ⇒ Numeric #min(array) ⇒ Numeric
Returns minimum value.
2379 2380 2381 |
# File 'lib/rubysketch/processing.rb', line 2379 def min(*args) args.flatten.min end |
#motion(&block) ⇒ Object
Defines motion block.
2003 2004 2005 2006 |
# File 'lib/rubysketch/processing.rb', line 2003 def motion(&block) @motionBlock__ = block if block nil end |
#motionGravity ⇒ Vector
Returns vector for real world gravity
2157 2158 2159 |
# File 'lib/rubysketch/processing.rb', line 2157 def motionGravity() @motionGravity__ end |
#mouseDragged(&block) ⇒ Object
Defines mouseDragged block.
1975 1976 1977 1978 |
# File 'lib/rubysketch/processing.rb', line 1975 def mouseDragged(&block) @mouseDraggedBlock__ = block if block nil end |
#mouseMoved(&block) ⇒ Object
Defines mouseMoved block.
1968 1969 1970 1971 |
# File 'lib/rubysketch/processing.rb', line 1968 def mouseMoved(&block) @mouseMovedBlock__ = block if block nil end |
#mousePressed(&block) ⇒ Boolean
Defines mousePressed block.
1954 1955 1956 1957 |
# File 'lib/rubysketch/processing.rb', line 1954 def mousePressed(&block) @mousePressedBlock__ = block if block not @pointersPressed__.empty? end |
#mouseReleased(&block) ⇒ Object
Defines mouseReleased block.
1961 1962 1963 1964 |
# File 'lib/rubysketch/processing.rb', line 1961 def mouseReleased(&block) @mouseReleasedBlock__ = block if block nil end |
#mouseX ⇒ Numeric
Returns mouse x position
2117 2118 2119 |
# File 'lib/rubysketch/processing.rb', line 2117 def mouseX() @pointerPos__[0] end |
#mouseY ⇒ Numeric
Returns mouse y position
2125 2126 2127 |
# File 'lib/rubysketch/processing.rb', line 2125 def mouseY() @pointerPos__[1] end |
#noise(x) ⇒ Numeric #noise(x, y) ⇒ Numeric #noise(x, y, z) ⇒ Numeric
Returns the perlin noise value.
2515 2516 2517 |
# File 'lib/rubysketch/processing.rb', line 2515 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.
2173 2174 2175 |
# File 'lib/rubysketch/processing.rb', line 2173 def noLoop() @loop__ = false end |
#norm(value, start, stop) ⇒ Numeric
Normalize the value from range start..stop into 0..1.
2336 2337 2338 |
# File 'lib/rubysketch/processing.rb', line 2336 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.
2040 2041 2042 2043 |
# File 'lib/rubysketch/processing.rb', line 2040 def pixelDensity(density = nil) resizeCanvas__ :pixelDensity, width, height, density if density @painter__.pixel_density end |
#pmouseX ⇒ Numeric
Returns mouse x position in previous frame
2133 2134 2135 |
# File 'lib/rubysketch/processing.rb', line 2133 def pmouseX() @pointerPrevPos__[0] end |
#pmouseY ⇒ Numeric
Returns mouse y position in previous frame
2141 2142 2143 |
# File 'lib/rubysketch/processing.rb', line 2141 def pmouseY() @pointerPrevPos__[1] end |
#pow(value, exponent) ⇒ Numeric
Returns value raised to the power of exponent.
2256 2257 2258 |
# File 'lib/rubysketch/processing.rb', line 2256 def pow(value, exponent) value ** exponent end |
#radians(degree) ⇒ Numeric
Converts degree to radian.
2418 2419 2420 |
# File 'lib/rubysketch/processing.rb', line 2418 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
2532 2533 2534 2535 2536 |
# File 'lib/rubysketch/processing.rb', line 2532 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.
2181 2182 2183 |
# File 'lib/rubysketch/processing.rb', line 2181 def redraw() @redraw__ = true end |
#round(value) ⇒ Numeric
Returns the closest integer number.
2225 2226 2227 |
# File 'lib/rubysketch/processing.rb', line 2225 def round(value) value.round end |
#setup(&block) ⇒ Object
Defines setup block.
1915 1916 1917 1918 |
# File 'lib/rubysketch/processing.rb', line 1915 def setup(&block) @window__.setup = block nil end |
#sin(angle) ⇒ Numeric
Returns the sine of an angle.
2438 2439 2440 |
# File 'lib/rubysketch/processing.rb', line 2438 def sin(angle) Math.sin angle end |
#size(width, height, pixelDensity: self.pixelDensity) ⇒ nil
Changes canvas size.
2016 2017 2018 2019 |
# File 'lib/rubysketch/processing.rb', line 2016 def size(width, height, pixelDensity: self.pixelDensity) resizeCanvas__ :size, width, height, pixelDensity nil end |
#sq(value) ⇒ Numeric
Returns squared value.
2266 2267 2268 |
# File 'lib/rubysketch/processing.rb', line 2266 def sq(value) value * value end |
#sqrt(value) ⇒ Numeric
Returns squared value.
2276 2277 2278 |
# File 'lib/rubysketch/processing.rb', line 2276 def sqrt(value) Math.sqrt value end |
#tan(angle) ⇒ Numeric
Returns the ratio of the sine and cosine of an angle.
2458 2459 2460 |
# File 'lib/rubysketch/processing.rb', line 2458 def tan(angle) Math.tan angle end |
#touchEnded(&block) ⇒ Object
Defines touchEnded block.
1989 1990 1991 1992 |
# File 'lib/rubysketch/processing.rb', line 1989 def touchEnded(&block) @touchEndedBlock__ = block if block nil end |
#touches ⇒ Array
Returns array of touches
2149 2150 2151 |
# File 'lib/rubysketch/processing.rb', line 2149 def touches() @touches__ end |
#touchMoved(&block) ⇒ Object
Defines touchMoved block.
1996 1997 1998 1999 |
# File 'lib/rubysketch/processing.rb', line 1996 def touchMoved(&block) @touchMovedBlock__ = block if block nil end |
#touchStarted(&block) ⇒ Object
Defines touchStarted block.
1982 1983 1984 1985 |
# File 'lib/rubysketch/processing.rb', line 1982 def touchStarted(&block) @touchStartedBlock__ = block if block nil end |
#windowHeight ⇒ Numeric
Returns window height.
2077 2078 2079 |
# File 'lib/rubysketch/processing.rb', line 2077 def windowHeight() @window__.height end |
#windowWidth ⇒ Numeric
Returns window width.
2069 2070 2071 |
# File 'lib/rubysketch/processing.rb', line 2069 def windowWidth() @window__.width end |