Class: Processing::Context
- Inherits:
-
Object
- Object
- Processing::Context
- Includes:
- GraphicsContext, Xot::Inspectable
- Defined in:
- lib/processing/context.rb
Overview
Processing context
Constant Summary collapse
- Capture =
Processing::Capture
- Font =
Processing::Font
- Graphics =
Processing::Graphics
- Image =
Processing::Image
- Shader =
Processing::Shader
- TextBounds =
Processing::TextBounds
- Touch =
Processing::Touch
- Vector =
Processing::Vector
- PORTRAIT =
Portrait for windowOrientation
:portrait- LANDSCAPE =
Landscape for windowOrientation
:landscape
Constants included from GraphicsContext
GraphicsContext::ADD, GraphicsContext::ALT, GraphicsContext::ARC, GraphicsContext::AUTO, GraphicsContext::BACKSPACE, GraphicsContext::BASELINE, GraphicsContext::BEVEL, GraphicsContext::BLEND, GraphicsContext::BLUR, GraphicsContext::BOTTOM, GraphicsContext::CAPSLOCK, GraphicsContext::CENTER, GraphicsContext::CLAMP, GraphicsContext::CLEAR, GraphicsContext::CLOSE, GraphicsContext::COLOR_CODES, GraphicsContext::COMMAND, GraphicsContext::CONTROL, GraphicsContext::CORNER, GraphicsContext::CORNERS, GraphicsContext::DARKEST, GraphicsContext::DEGREES, GraphicsContext::DELETE, GraphicsContext::DOWN, GraphicsContext::ELLIPSE, GraphicsContext::ENTER, GraphicsContext::ESC, GraphicsContext::EXCLUSION, 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::GRAY, GraphicsContext::GROUP, GraphicsContext::HALF_PI, GraphicsContext::HELP, GraphicsContext::HOME, GraphicsContext::HSB, GraphicsContext::IMAGE, GraphicsContext::INVERT, GraphicsContext::LEFT, GraphicsContext::LIGHTEST, GraphicsContext::LINE, GraphicsContext::LINES, GraphicsContext::MITER, GraphicsContext::MULTIPLY, GraphicsContext::NORMAL, GraphicsContext::OPEN, GraphicsContext::OPTION, GraphicsContext::P5JS, GraphicsContext::PAGEDOWN, GraphicsContext::PAGEUP, GraphicsContext::PI, GraphicsContext::POINTS, GraphicsContext::PROCESSING, GraphicsContext::PROJECT, GraphicsContext::QUAD, GraphicsContext::QUADS, GraphicsContext::QUAD_STRIP, GraphicsContext::QUARTER_PI, GraphicsContext::RADIANS, GraphicsContext::RADIUS, GraphicsContext::RECT, GraphicsContext::REPEAT, GraphicsContext::REPLACE, GraphicsContext::RGB, GraphicsContext::RGBA, GraphicsContext::RIGHT, GraphicsContext::ROUND, GraphicsContext::SCREEN, GraphicsContext::SECTION, GraphicsContext::SHIFT, GraphicsContext::SPACE, GraphicsContext::SQUARE, GraphicsContext::SUBTRACT, GraphicsContext::TAB, GraphicsContext::TAU, GraphicsContext::TESS, GraphicsContext::THRESHOLD, GraphicsContext::TOP, GraphicsContext::TRIANGLE, GraphicsContext::TRIANGLES, GraphicsContext::TRIANGLE_FAN, GraphicsContext::TRIANGLE_STRIP, GraphicsContext::TWO_PI, GraphicsContext::UP, GraphicsContext::WIN
Instance Method Summary collapse
-
#createCanvas(width, height, pixelDensity: nil) ⇒ nil
Changes canvas size.
-
#deltaTime ⇒ Float
Returns the elapsed time after previous drawing event.
-
#displayDensity ⇒ Numeric
Returns the pixel density of the display.
-
#displayHeight ⇒ Numeric
Returns the height of the display.
-
#displayWidth ⇒ Numeric
Returns the width of the display.
-
#doubleClicked(&block) ⇒ nil
Defines doubleClicked block.
-
#draw(&block) ⇒ nil
Defines draw block.
-
#focused ⇒ Boolean
Returns whether the window is active or not.
-
#frameCount ⇒ Integer
Returns the number of frames since the program started.
-
#frameRate ⇒ Float
Returns the number of frames per second.
-
#fullscreen(state = nil) ⇒ Boolean
(also: #fullScreen)
Toggles full-screen state or returns the current state.
-
#key ⇒ String
Returns the last key that was pressed or released.
-
#keyCode ⇒ Symbol
Returns the last key code that was pressed or released.
-
#keyIsDown(keyCode) ⇒ Boolean
Returns whether or not the key is currently pressed.
-
#keyIsPressed ⇒ Boolean
Returns whether or not any key is pressed.
-
#keyIsRepeated ⇒ Boolean
Returns whether the current key is repeated or not.
-
#keyPressed(&block) ⇒ Boolean
Defines keyPressed block.
-
#keyReleased(&block) ⇒ nil
Defines keyReleased block.
-
#keyTyped(&block) ⇒ nil
Defines keyTyped block.
-
#loop ⇒ nil
Enables calling draw block on every frame.
-
#motion(&block) ⇒ nil
Defines motion block.
-
#motionGravity ⇒ Vector
Returns vector for real world gravity.
-
#mouseButton ⇒ Numeric
Returns which mouse button was pressed.
-
#mouseClicked(&block) ⇒ nil
Defines mouseClicked block.
-
#mouseDragged(&block) ⇒ nil
Defines mouseDragged block.
-
#mouseMoved(&block) ⇒ nil
Defines mouseMoved block.
-
#mouseOut(&block) ⇒ nil
Defines mouseOut block, called when the mouse goes out of the window.
-
#mouseOver(&block) ⇒ nil
Defines mouseOver block, called when the mouse comes over the window.
-
#mousePressed(&block) ⇒ Boolean
Defines mousePressed block.
-
#mouseReleased(&block) ⇒ nil
Defines mouseReleased block.
-
#mouseWheel(&block) ⇒ nil
Defines mouseWheel block.
-
#mouseX ⇒ Numeric
Returns mouse x position.
-
#mouseY ⇒ Numeric
Returns mouse y position.
-
#noLoop ⇒ nil
Disables calling draw block on every frame.
-
#noSmooth ⇒ nil
Disables anti-aliasing.
-
#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.
-
#redraw ⇒ nil
Calls draw block to redraw frame.
-
#setTitle(title) ⇒ nil
Changes title of window.
-
#setup(&block) ⇒ nil
Defines setup block.
-
#size(width, height, pixelDensity: nil) ⇒ nil
Changes canvas size.
-
#smooth ⇒ nil
Enables anti-aliasing.
-
#touchEnded(&block) ⇒ nil
Defines touchEnded block.
-
#touches ⇒ Array
Returns array of touches.
-
#touchMoved(&block) ⇒ nil
Defines touchMoved block.
-
#touchStarted(&block) ⇒ nil
Defines touchStarted block.
-
#windowHeight ⇒ Numeric
Returns the height of the window.
-
#windowMove(x, y) ⇒ nil
Move the position of the window.
-
#windowMoved(&block) ⇒ nil
Defines windowMoved block.
-
#windowOrientation(*orientations) ⇒ nil
Sets window orientation mask.
-
#windowResizable(resizable) ⇒ nil
Makes the window resizable or not.
-
#windowResize(width, height) ⇒ nil
Sets the size of the window.
-
#windowResized(&block) ⇒ nil
Defines windowResized block.
-
#windowWidth ⇒ Numeric
Returns the width of the window.
-
#windowX ⇒ Numeric
Returns the x position of the window.
-
#windowY ⇒ Numeric
Returns the y position of the window.
Methods included from GraphicsContext
#abs, #acos, #alpha, #angleMode, #applyMatrix, #arc, #asin, #atan, #atan2, #background, #beginContour, #beginShape, #bezier, #bezierDetail, #bezierPoint, #bezierTangent, #bezierVertex, #blend, #blendMode, #blue, #brightness, #ceil, #circle, #clear, #clip, #color, #colorMode, #constrain, #copy, #cos, #createCapture, #createFont, #createGraphics, #createImage, #createShader, #createShape, #createVector, #curve, #curveDetail, #curvePoint, #curveTangent, #curveTightness, #curveVertex, #degrees, #dist, #ellipse, #ellipseMode, #endContour, #endShape, #exp, #fill, #filter, #floor, #green, #height, #hue, #image, #imageMode, #lerp, #lerpColor, #line, #loadFont, #loadImage, #loadPixels, #loadShader, #loadShape, #log, #mag, #map, #max, #min, #noClip, #noFill, #noStroke, #noTint, #noise, #noiseDetail, #noiseSeed, #norm, #pixelHeight, #pixelWidth, #pixels, #point, #pop, #popMatrix, #popStyle, #pow, #printMatrix, #push, #pushMatrix, #pushStyle, #quad, #quadraticVertex, #radians, #random, #randomGaussian, #randomSeed, #rect, #rectMode, #red, #renderMode, #requestImage, #resetMatrix, #resetShader, #rotate, #rotateX, #rotateY, #rotateZ, #round, #saturation, #save, #scale, #shader, #shape, #shapeMode, #shearX, #shearY, #sin, #sq, #sqrt, #square, #stroke, #strokeCap, #strokeJoin, #strokeWeight, #tan, #text, #textAlign, #textAscent, #textDescent, #textFont, #textLeading, #textSize, #textWidth, #texture, #textureMode, #textureWrap, #tint, #translate, #triangle, #updatePixels, #vertex, #width
Instance Method Details
#createCanvas(width, height, pixelDensity: nil) ⇒ nil
Changes canvas size.
456 457 458 459 460 |
# File 'lib/processing/context.rb', line 456 def createCanvas(width, height, pixelDensity: nil) windowResize width, height resizeCanvas__ width, height, pixelDensity: pixelDensity, autoResize: false nil end |
#deltaTime ⇒ Float
Returns the elapsed time after previous drawing event
697 698 699 |
# File 'lib/processing/context.rb', line 697 def deltaTime() @window__.event.dt * 1000 end |
#displayDensity ⇒ Numeric
Returns the pixel density of the display.
567 568 569 |
# File 'lib/processing/context.rb', line 567 def displayDensity() @window__.painter.pixel_density end |
#displayHeight ⇒ Numeric
Returns the height of the display.
556 557 558 |
# File 'lib/processing/context.rb', line 556 def displayHeight() @window__.screen.height end |
#displayWidth ⇒ Numeric
Returns the width of the display.
545 546 547 |
# File 'lib/processing/context.rb', line 545 def displayWidth() @window__.screen.width end |
#doubleClicked(&block) ⇒ nil
Defines doubleClicked block.
326 327 328 329 |
# File 'lib/processing/context.rb', line 326 def doubleClicked(&block) @doubleClickedBlock__ = block if block nil end |
#draw(&block) ⇒ nil
Defines draw block.
218 219 220 221 |
# File 'lib/processing/context.rb', line 218 def draw(&block) @drawBlock__ = block if block nil end |
#focused ⇒ Boolean
Returns whether the window is active or not.
665 666 667 |
# File 'lib/processing/context.rb', line 665 def focused() @window__.active? end |
#frameCount ⇒ Integer
Returns the number of frames since the program started.
676 677 678 |
# File 'lib/processing/context.rb', line 676 def frameCount() @frameCount__ end |
#frameRate ⇒ Float
Returns the number of frames per second.
687 688 689 |
# File 'lib/processing/context.rb', line 687 def frameRate() @window__.event.fps end |
#fullscreen(state = nil) ⇒ Boolean Also known as: fullScreen
Toggles full-screen state or returns the current state.
498 499 500 501 |
# File 'lib/processing/context.rb', line 498 def fullscreen(state = nil) @window__.fullscreen = state if state != nil @window__.fullscreen? end |
#key ⇒ String
Returns the last key that was pressed or released.
708 709 710 |
# File 'lib/processing/context.rb', line 708 def key() @key__ end |
#keyCode ⇒ Symbol
Returns the last key code that was pressed or released.
719 720 721 |
# File 'lib/processing/context.rb', line 719 def keyCode() @keyCode__ end |
#keyIsDown(keyCode) ⇒ Boolean
Returns whether or not the key is currently pressed.
741 742 743 |
# File 'lib/processing/context.rb', line 741 def keyIsDown(keyCode) @keysPressed__.include? keyCode end |
#keyIsPressed ⇒ Boolean
Returns whether or not any key is pressed.
729 730 731 |
# File 'lib/processing/context.rb', line 729 def keyIsPressed() not @keysPressed__.empty? end |
#keyIsRepeated ⇒ Boolean
Returns whether the current key is repeated or not.
749 750 751 |
# File 'lib/processing/context.rb', line 749 def keyIsRepeated() @keyRepeat__ end |
#keyPressed(&block) ⇒ Boolean
Defines keyPressed block.
230 231 232 233 |
# File 'lib/processing/context.rb', line 230 def keyPressed(&block) @keyPressedBlock__ = block if block keyIsPressed end |
#keyReleased(&block) ⇒ nil
Defines keyReleased block.
242 243 244 245 |
# File 'lib/processing/context.rb', line 242 def keyReleased(&block) @keyReleasedBlock__ = block if block nil end |
#keyTyped(&block) ⇒ nil
Defines keyTyped block.
254 255 256 257 |
# File 'lib/processing/context.rb', line 254 def keyTyped(&block) @keyTypedBlock__ = block if block nil end |
#loop ⇒ nil
Enables calling draw block on every frame.
833 834 835 |
# File 'lib/processing/context.rb', line 833 def loop() @loop__ = true end |
#motion(&block) ⇒ nil
Defines motion block.
425 426 427 428 |
# File 'lib/processing/context.rb', line 425 def motion(&block) @motionBlock__ = block if block nil end |
#motionGravity ⇒ Vector
Returns vector for real world gravity
822 823 824 |
# File 'lib/processing/context.rb', line 822 def motionGravity() @motionGravity__ end |
#mouseButton ⇒ Numeric
Returns which mouse button was pressed
804 805 806 |
# File 'lib/processing/context.rb', line 804 def mouseButton() ((@pointersPressed__ + @pointersReleased__) & [LEFT, RIGHT, CENTER]).last end |
#mouseClicked(&block) ⇒ nil
Defines mouseClicked block.
315 316 317 318 |
# File 'lib/processing/context.rb', line 315 def mouseClicked(&block) @mouseClickedBlock__ = block if block nil end |
#mouseDragged(&block) ⇒ nil
Defines mouseDragged block.
303 304 305 306 |
# File 'lib/processing/context.rb', line 303 def mouseDragged(&block) @mouseDraggedBlock__ = block if block nil end |
#mouseMoved(&block) ⇒ nil
Defines mouseMoved block.
291 292 293 294 |
# File 'lib/processing/context.rb', line 291 def mouseMoved(&block) @mouseMovedBlock__ = block if block nil end |
#mouseOut(&block) ⇒ nil
Defines mouseOut block, called when the mouse goes out of the window.
348 349 350 351 |
# File 'lib/processing/context.rb', line 348 def mouseOut(&block) @mouseOutBlock__ = block if block nil end |
#mouseOver(&block) ⇒ nil
Defines mouseOver block, called when the mouse comes over the window.
337 338 339 340 |
# File 'lib/processing/context.rb', line 337 def mouseOver(&block) @mouseOverBlock__ = block if block nil end |
#mousePressed(&block) ⇒ Boolean
Defines mousePressed block.
267 268 269 270 |
# File 'lib/processing/context.rb', line 267 def mousePressed(&block) @mousePressedBlock__ = block if block not @pointersPressed__.empty? end |
#mouseReleased(&block) ⇒ nil
Defines mouseReleased block.
279 280 281 282 |
# File 'lib/processing/context.rb', line 279 def mouseReleased(&block) @mouseReleasedBlock__ = block if block nil end |
#mouseWheel(&block) ⇒ nil
Defines mouseWheel block.
360 361 362 363 |
# File 'lib/processing/context.rb', line 360 def mouseWheel(&block) @mouseWheelBlock__ = block if block nil end |
#mouseX ⇒ Numeric
Returns mouse x position
760 761 762 |
# File 'lib/processing/context.rb', line 760 def mouseX() @pointer__&.x || 0 end |
#mouseY ⇒ Numeric
Returns mouse y position
771 772 773 |
# File 'lib/processing/context.rb', line 771 def mouseY() @pointer__&.y || 0 end |
#noLoop ⇒ nil
Disables calling draw block on every frame.
844 845 846 |
# File 'lib/processing/context.rb', line 844 def noLoop() @loop__ = false end |
#noSmooth ⇒ nil
Disables anti-aliasing.
526 527 528 529 |
# File 'lib/processing/context.rb', line 526 def noSmooth() @smooth__ = false resizeCanvas__ width, height end |
#pixelDensity(density = nil) ⇒ Numeric
Changes and returns canvas pixel density.
484 485 486 487 |
# File 'lib/processing/context.rb', line 484 def pixelDensity(density = nil) resizeCanvas__ width, height, pixelDensity: density if density @window__.canvas.pixel_density end |
#pmouseX ⇒ Numeric
Returns mouse x position in previous frame
782 783 784 |
# File 'lib/processing/context.rb', line 782 def pmouseX() @pointerPrev__&.x || 0 end |
#pmouseY ⇒ Numeric
Returns mouse y position in previous frame
793 794 795 |
# File 'lib/processing/context.rb', line 793 def pmouseY() @pointerPrev__&.y || 0 end |
#redraw ⇒ nil
Calls draw block to redraw frame.
855 856 857 |
# File 'lib/processing/context.rb', line 855 def redraw() @redraw__ = true end |
#setTitle(title) ⇒ nil
Changes title of window.
470 471 472 473 |
# File 'lib/processing/context.rb', line 470 def setTitle(title) @window__.title = title nil end |
#setup(&block) ⇒ nil
Defines setup block.
206 207 208 209 |
# File 'lib/processing/context.rb', line 206 def setup(&block) @window__.setup = block if block nil end |
#size(width, height, pixelDensity: nil) ⇒ nil
Changes canvas size.
440 441 442 443 444 |
# File 'lib/processing/context.rb', line 440 def size(width, height, pixelDensity: nil) windowResize width, height resizeCanvas__ width, height, pixelDensity: pixelDensity, autoResize: false nil end |
#smooth ⇒ nil
Enables anti-aliasing. (Anti-aliasing is disabled on high DPI screen)
513 514 515 516 517 |
# File 'lib/processing/context.rb', line 513 def smooth() @smooth__ = true resizeCanvas__ width, height nil end |
#touchEnded(&block) ⇒ nil
Defines touchEnded block.
382 383 384 385 |
# File 'lib/processing/context.rb', line 382 def touchEnded(&block) @touchEndedBlock__ = block if block nil end |
#touches ⇒ Array
Returns array of touches
814 815 816 |
# File 'lib/processing/context.rb', line 814 def touches() @touches__ end |
#touchMoved(&block) ⇒ nil
Defines touchMoved block.
393 394 395 396 |
# File 'lib/processing/context.rb', line 393 def touchMoved(&block) @touchMovedBlock__ = block if block nil end |
#touchStarted(&block) ⇒ nil
Defines touchStarted block.
371 372 373 374 |
# File 'lib/processing/context.rb', line 371 def touchStarted(&block) @touchStartedBlock__ = block if block nil end |
#windowHeight ⇒ Numeric
Returns the height of the window.
654 655 656 |
# File 'lib/processing/context.rb', line 654 def windowHeight() @window__.height end |
#windowMove(x, y) ⇒ nil
Move the position of the window.
580 581 582 583 |
# File 'lib/processing/context.rb', line 580 def windowMove(x, y) @window__.pos = [x, y] nil end |
#windowMoved(&block) ⇒ nil
Defines windowMoved block.
404 405 406 407 |
# File 'lib/processing/context.rb', line 404 def windowMoved(&block) @windowMovedBlock__ = block if block nil end |
#windowOrientation(*orientations) ⇒ nil
Sets window orientation mask
618 619 620 |
# File 'lib/processing/context.rb', line 618 def windowOrientation(*orientations) @window__.orientations = orientations.flatten.uniq end |
#windowResizable(resizable) ⇒ nil
Makes the window resizable or not.
607 608 609 610 |
# File 'lib/processing/context.rb', line 607 def windowResizable(resizable) @window__.resizable = resizable nil end |
#windowResize(width, height) ⇒ nil
Sets the size of the window.
594 595 596 597 |
# File 'lib/processing/context.rb', line 594 def windowResize(width, height) @window__.size = [width, height] nil end |
#windowResized(&block) ⇒ nil
Defines windowResized block.
416 417 418 419 |
# File 'lib/processing/context.rb', line 416 def windowResized(&block) @windowResizedBlock__ = block if block nil end |
#windowWidth ⇒ Numeric
Returns the width of the window.
644 645 646 |
# File 'lib/processing/context.rb', line 644 def windowWidth() @window__.width end |
#windowX ⇒ Numeric
Returns the x position of the window.
626 627 628 |
# File 'lib/processing/context.rb', line 626 def windowX() @window__.x end |
#windowY ⇒ Numeric
Returns the y position of the window.
634 635 636 |
# File 'lib/processing/context.rb', line 634 def windowY() @window__.y end |