Class: RubySketch::Processing::Context
- Inherits:
-
Object
- Object
- RubySketch::Processing::Context
- Includes:
- GraphicsContext
- Defined in:
- lib/rubysketch/processing.rb
Overview
Processing context
Constant Summary collapse
- @@context__ =
nil
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, GraphicsContext::Vector
Class Method Summary collapse
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.
-
#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.
-
#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.
-
#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.
-
#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, #beginDraw, #bezier, #circle, #colorMode, #copy, #curve, #ellipse, #ellipseMode, #endDraw, #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
Class Method Details
.context__ ⇒ Object
1641 1642 1643 |
# File 'lib/rubysketch/processing.rb', line 1641 def self.context__ () @@context__ end |
Instance Method Details
#abs(value) ⇒ Numeric
Returns the absolute number of the value.
1882 1883 1884 |
# File 'lib/rubysketch/processing.rb', line 1882 def abs (value) value.abs end |
#acos(value) ⇒ Numeric
Returns the inverse of cos().
2135 2136 2137 |
# File 'lib/rubysketch/processing.rb', line 2135 def acos (value) Math.acos value end |
#asin(value) ⇒ Numeric
Returns the inverse of sin().
2125 2126 2127 |
# File 'lib/rubysketch/processing.rb', line 2125 def asin (value) Math.asin value end |
#atan(value) ⇒ Numeric
Returns the inverse of tan().
2145 2146 2147 |
# File 'lib/rubysketch/processing.rb', line 2145 def atan (value) Math.atan value end |
#atan2(y, x) ⇒ Numeric
Returns the angle from a specified point.
2156 2157 2158 |
# File 'lib/rubysketch/processing.rb', line 2156 def atan2 (y, x) Math.atan2 y, x end |
#ceil(value) ⇒ Numeric
Returns the closest integer number greater than or equal to the value.
1892 1893 1894 |
# File 'lib/rubysketch/processing.rb', line 1892 def ceil (value) value.ceil end |
#constrain(value, min, max) ⇒ Numeric
Constrains the number between min..max.
2065 2066 2067 |
# File 'lib/rubysketch/processing.rb', line 2065 def constrain (value, min, max) value < min ? min : (value > max ? max : value) end |
#cos(angle) ⇒ Numeric
Returns the cosine of an angle.
2105 2106 2107 |
# File 'lib/rubysketch/processing.rb', line 2105 def cos (angle) Math.cos angle end |
#createGraphics(width, height) ⇒ Graphics
Creates a new off-screen graphics context object.
2218 2219 2220 |
# File 'lib/rubysketch/processing.rb', line 2218 def createGraphics (width, height) Graphics.new width, height end |
#createVector ⇒ Vector #createVector(x, y) ⇒ Vector #createVector(x, y, z) ⇒ Vector
Creates a new vector.
2207 2208 2209 |
# File 'lib/rubysketch/processing.rb', line 2207 def createVector (*args) Vector.new *args end |
#degrees(radian) ⇒ Numeric
Converts radian to degree.
2085 2086 2087 |
# File 'lib/rubysketch/processing.rb', line 2085 def degrees (radian) radian * RAD2DEG__ end |
#displayDensity ⇒ Numeric
Returns pixel density
1804 1805 1806 |
# File 'lib/rubysketch/processing.rb', line 1804 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.
1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 |
# File 'lib/rubysketch/processing.rb', line 1971 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.
1720 1721 1722 1723 |
# File 'lib/rubysketch/processing.rb', line 1720 def draw (&block) @drawBlock__ = block if block nil end |
#floor(value) ⇒ Numeric
Returns the closest integer number less than or equal to the value.
1902 1903 1904 |
# File 'lib/rubysketch/processing.rb', line 1902 def floor (value) value.floor end |
#frameCount ⇒ Integer
Returns number of frames since program started.
1788 1789 1790 |
# File 'lib/rubysketch/processing.rb', line 1788 def frameCount () @frameCount__ end |
#frameRate ⇒ Float
Returns number of frames per second.
1796 1797 1798 |
# File 'lib/rubysketch/processing.rb', line 1796 def frameRate () @window__.event.fps end |
#key(&block) ⇒ Object
1725 1726 1727 1728 |
# File 'lib/rubysketch/processing.rb', line 1725 def key (&block) @window__.key = block nil end |
#lerp(start, stop, amount) ⇒ Numeric
Returns the interpolated number between range start..stop.
2005 2006 2007 |
# File 'lib/rubysketch/processing.rb', line 2005 def lerp (start, stop, amount) start + (stop - start) * amount end |
#loadImage(filename, extension = nil) ⇒ Image
Loads image.
2229 2230 2231 2232 |
# File 'lib/rubysketch/processing.rb', line 2229 def loadImage (filename, extension = nil) filename = getImage__ filename, extension if filename =~ %r|^https?://| Image.new Rays::Image.load filename end |
#loop ⇒ nil
Enables calling draw block on every frame.
1852 1853 1854 |
# File 'lib/rubysketch/processing.rb', line 1852 def loop () @loop__ = true end |
#mag(x, y) ⇒ Numeric #mag(x, y, z) ⇒ Numeric
Returns the magnitude (or length) of a vector.
1948 1949 1950 1951 1952 1953 1954 1955 |
# File 'lib/rubysketch/processing.rb', line 1948 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.
2019 2020 2021 |
# File 'lib/rubysketch/processing.rb', line 2019 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.
2053 2054 2055 |
# File 'lib/rubysketch/processing.rb', line 2053 def max (*args) args.flatten.max end |
#min(a, b) ⇒ Numeric #min(a, b, c) ⇒ Numeric #min(array) ⇒ Numeric
Returns minimum value.
2036 2037 2038 |
# File 'lib/rubysketch/processing.rb', line 2036 def min (*args) args.flatten.min end |
#mouseDragged(&block) ⇒ Object
1745 1746 1747 1748 |
# File 'lib/rubysketch/processing.rb', line 1745 def mouseDragged (&block) @mouseDraggedBlock__ = block if block nil end |
#mouseMoved(&block) ⇒ Object
1740 1741 1742 1743 |
# File 'lib/rubysketch/processing.rb', line 1740 def mouseMoved (&block) @mouseMovedBlock__ = block if block nil end |
#mousePressed(&block) ⇒ Object
1730 1731 1732 1733 |
# File 'lib/rubysketch/processing.rb', line 1730 def mousePressed (&block) @mousePressedBlock__ = block if block @mousePressed__ end |
#mouseReleased(&block) ⇒ Object
1735 1736 1737 1738 |
# File 'lib/rubysketch/processing.rb', line 1735 def mouseReleased (&block) @mouseReleasedBlock__ = block if block nil end |
#mouseX ⇒ Numeric
Returns mouse x position
1812 1813 1814 |
# File 'lib/rubysketch/processing.rb', line 1812 def mouseX () @mousePos__.x end |
#mouseY ⇒ Numeric
Returns mouse y position
1820 1821 1822 |
# File 'lib/rubysketch/processing.rb', line 1820 def mouseY () @mousePos__.y end |
#noise(x) ⇒ Numeric #noise(x, y) ⇒ Numeric #noise(x, y, z) ⇒ Numeric
Returns the perlin noise value.
2172 2173 2174 |
# File 'lib/rubysketch/processing.rb', line 2172 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.
1860 1861 1862 |
# File 'lib/rubysketch/processing.rb', line 1860 def noLoop () @loop__ = false end |
#norm(value, start, stop) ⇒ Numeric
Normalize the value from range start..stop into 0..1.
1993 1994 1995 |
# File 'lib/rubysketch/processing.rb', line 1993 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
1828 1829 1830 |
# File 'lib/rubysketch/processing.rb', line 1828 def pmouseX () @mousePrevPos__.x end |
#pmouseY ⇒ Numeric
Returns mouse y position in previous frame
1836 1837 1838 |
# File 'lib/rubysketch/processing.rb', line 1836 def pmouseY () @mousePrevPos__.y end |
#pow(value, exponent) ⇒ Numeric
Returns value raised to the power of exponent.
1923 1924 1925 |
# File 'lib/rubysketch/processing.rb', line 1923 def pow (value, exponent) value ** exponent end |
#radians(degree) ⇒ Numeric
Converts degree to radian.
2075 2076 2077 |
# File 'lib/rubysketch/processing.rb', line 2075 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
2189 2190 2191 2192 2193 |
# File 'lib/rubysketch/processing.rb', line 2189 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.
1868 1869 1870 |
# File 'lib/rubysketch/processing.rb', line 1868 def redraw () @redraw__ = true end |
#round(value) ⇒ Numeric
Returns the closest integer number.
1912 1913 1914 |
# File 'lib/rubysketch/processing.rb', line 1912 def round (value) value.round end |
#setup(&block) ⇒ Object
Define setup block.
1713 1714 1715 1716 |
# File 'lib/rubysketch/processing.rb', line 1713 def setup (&block) @window__.setup = block nil end |
#sin(angle) ⇒ Numeric
Returns the sine of an angle.
2095 2096 2097 |
# File 'lib/rubysketch/processing.rb', line 2095 def sin (angle) Math.sin angle end |
#sq(value) ⇒ Numeric
Returns squared value.
1933 1934 1935 |
# File 'lib/rubysketch/processing.rb', line 1933 def sq (value) value * value end |
#tan(angle) ⇒ Numeric
Returns the ratio of the sine and cosine of an angle.
2115 2116 2117 |
# File 'lib/rubysketch/processing.rb', line 2115 def tan (angle) Math.tan angle end |
#touchEnded(&block) ⇒ Object
1755 1756 1757 1758 |
# File 'lib/rubysketch/processing.rb', line 1755 def touchEnded (&block) @touchEndedBlock__ = block if block nil end |
#touches ⇒ Array
Returns array of touches
1844 1845 1846 |
# File 'lib/rubysketch/processing.rb', line 1844 def touches () @touches__ end |
#touchMoved(&block) ⇒ Object
1760 1761 1762 1763 |
# File 'lib/rubysketch/processing.rb', line 1760 def touchMoved (&block) @touchMovedBlock__ = block if block nil end |
#touchStarted(&block) ⇒ Object
1750 1751 1752 1753 |
# File 'lib/rubysketch/processing.rb', line 1750 def touchStarted (&block) @touchStartedBlock__ = block if block nil end |
#windowHeight ⇒ Object
1780 1781 1782 |
# File 'lib/rubysketch/processing.rb', line 1780 def windowHeight () @window__.height end |
#windowWidth ⇒ Object
1776 1777 1778 |
# File 'lib/rubysketch/processing.rb', line 1776 def windowWidth () @window__.width end |