Class: Processing::Context

Inherits:
Object
  • Object
show all
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

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.

Parameters:

  • width (Integer)

    new width

  • height (Integer)

    new height

  • pixelDensity (Numeric, AUTO) (defaults to: nil)

    new pixel density, or AUTO to track display

Returns:

  • (nil)

    nil

See Also:



436
437
438
439
440
# File 'lib/processing/context.rb', line 436

def createCanvas(width, height, pixelDensity: nil)
  windowResize width, height
  resizeCanvas__ width, height, pixelDensity: pixelDensity, autoResize: false
  nil
end

#deltaTimeFloat

Returns the elapsed time after previous drawing event

Returns:

  • (Float)

    elapsed time in milliseconds

See Also:



677
678
679
# File 'lib/processing/context.rb', line 677

def deltaTime()
  @window__.event.dt * 1000
end

#displayDensityNumeric

Returns the pixel density of the display.



547
548
549
# File 'lib/processing/context.rb', line 547

def displayDensity()
  @window__.painter.pixel_density
end

#displayHeightNumeric

Returns the height of the display.



536
537
538
# File 'lib/processing/context.rb', line 536

def displayHeight()
  @window__.screen.height
end

#displayWidthNumeric

Returns the width of the display.



525
526
527
# File 'lib/processing/context.rb', line 525

def displayWidth()
  @window__.screen.width
end

#doubleClicked(&block) ⇒ nil

Defines doubleClicked block.

Returns:

  • (nil)

    nil

See Also:



328
329
330
331
# File 'lib/processing/context.rb', line 328

def doubleClicked(&block)
  @doubleClickedBlock__ = block if block
  nil
end

#draw(&block) ⇒ nil

Defines draw block.



220
221
222
223
# File 'lib/processing/context.rb', line 220

def draw(&block)
  @drawBlock__ = block if block
  nil
end

#focusedBoolean

Returns whether the window is active or not.



645
646
647
# File 'lib/processing/context.rb', line 645

def focused()
  @window__.active?
end

#frameCountInteger

Returns the number of frames since the program started.



656
657
658
# File 'lib/processing/context.rb', line 656

def frameCount()
  @frameCount__
end

#frameRateFloat

Returns the number of frames per second.



667
668
669
# File 'lib/processing/context.rb', line 667

def frameRate()
  @window__.event.fps
end

#fullscreen(state = nil) ⇒ Boolean Also known as: fullScreen

Toggles full-screen state or returns the current state.

Parameters:

  • state (Boolean) (defaults to: nil)

    Whether to display full-screen or not

Returns:

  • (Boolean)

    current state

See Also:



478
479
480
481
# File 'lib/processing/context.rb', line 478

def fullscreen(state = nil)
  @window__.fullscreen = state if state != nil
  @window__.fullscreen?
end

#keyString

Returns the last key that was pressed or released.



688
689
690
# File 'lib/processing/context.rb', line 688

def key()
  @key__
end

#keyCodeSymbol

Returns the last key code that was pressed or released.



699
700
701
# File 'lib/processing/context.rb', line 699

def keyCode()
  @keyCode__
end

#keyIsDown(keyCode) ⇒ Boolean

Returns whether or not the key is currently pressed.

Parameters:

  • keyCode (Numeric)

    code for the key

Returns:

  • (Boolean)

    is the key pressed or not

See Also:



721
722
723
# File 'lib/processing/context.rb', line 721

def keyIsDown(keyCode)
  @keysPressed__.include? keyCode
end

#keyIsPressedBoolean

Returns whether or not any key is pressed.

Returns:

  • (Boolean)

    is any key pressed or not

See Also:



709
710
711
# File 'lib/processing/context.rb', line 709

def keyIsPressed()
  not @keysPressed__.empty?
end

#keyIsRepeatedBoolean

Returns whether the current key is repeated or not.

Returns:

  • (Boolean)

    is the key repeated or not



729
730
731
# File 'lib/processing/context.rb', line 729

def keyIsRepeated()
  @keyRepeat__
end

#keyPressed(&block) ⇒ Boolean

Defines keyPressed block.

Returns:

  • (Boolean)

    is any key pressed or not

See Also:



232
233
234
235
# File 'lib/processing/context.rb', line 232

def keyPressed(&block)
  @keyPressedBlock__ = block if block
  keyIsPressed
end

#keyReleased(&block) ⇒ nil

Defines keyReleased block.



244
245
246
247
# File 'lib/processing/context.rb', line 244

def keyReleased(&block)
  @keyReleasedBlock__ = block if block
  nil
end

#keyTyped(&block) ⇒ nil

Defines keyTyped block.



256
257
258
259
# File 'lib/processing/context.rb', line 256

def keyTyped(&block)
  @keyTypedBlock__ = block if block
  nil
end

#loopnil

Enables calling draw block on every frame.



813
814
815
# File 'lib/processing/context.rb', line 813

def loop()
  @loop__ = true
end

#motion(&block) ⇒ nil

Defines motion block.

Returns:

  • (nil)

    nil



405
406
407
408
# File 'lib/processing/context.rb', line 405

def motion(&block)
  @motionBlock__ = block if block
  nil
end

#motionGravityVector

Returns vector for real world gravity

Returns:



802
803
804
# File 'lib/processing/context.rb', line 802

def motionGravity()
  @motionGravity__
end

#mouseButtonNumeric

Returns which mouse button was pressed

Returns:

  • (Numeric)

    LEFT, RIGHT, CENTER or 0

See Also:



784
785
786
# File 'lib/processing/context.rb', line 784

def mouseButton()
  ((@pointersPressed__ + @pointersReleased__) & [LEFT, RIGHT, CENTER]).last
end

#mouseClicked(&block) ⇒ nil

Defines mouseClicked block.



317
318
319
320
# File 'lib/processing/context.rb', line 317

def mouseClicked(&block)
  @mouseClickedBlock__ = block if block
  nil
end

#mouseDragged(&block) ⇒ nil

Defines mouseDragged block.



305
306
307
308
# File 'lib/processing/context.rb', line 305

def mouseDragged(&block)
  @mouseDraggedBlock__ = block if block
  nil
end

#mouseMoved(&block) ⇒ nil

Defines mouseMoved block.



293
294
295
296
# File 'lib/processing/context.rb', line 293

def mouseMoved(&block)
  @mouseMovedBlock__ = block if block
  nil
end

#mousePressed(&block) ⇒ Boolean

Defines mousePressed block.



269
270
271
272
# File 'lib/processing/context.rb', line 269

def mousePressed(&block)
  @mousePressedBlock__ = block if block
  not @pointersPressed__.empty?
end

#mouseReleased(&block) ⇒ nil

Defines mouseReleased block.



281
282
283
284
# File 'lib/processing/context.rb', line 281

def mouseReleased(&block)
  @mouseReleasedBlock__ = block if block
  nil
end

#mouseWheel(&block) ⇒ nil

Defines mouseWheel block.



340
341
342
343
# File 'lib/processing/context.rb', line 340

def mouseWheel(&block)
  @mouseWheelBlock__ = block if block
  nil
end

#mouseXNumeric

Returns mouse x position

Returns:

  • (Numeric)

    horizontal position of mouse

See Also:



740
741
742
# File 'lib/processing/context.rb', line 740

def mouseX()
  @pointer__&.x || 0
end

#mouseYNumeric

Returns mouse y position

Returns:

  • (Numeric)

    vertical position of mouse

See Also:



751
752
753
# File 'lib/processing/context.rb', line 751

def mouseY()
  @pointer__&.y || 0
end

#noLoopnil

Disables calling draw block on every frame.



824
825
826
# File 'lib/processing/context.rb', line 824

def noLoop()
  @loop__ = false
end

#noSmoothnil

Disables anti-aliasing.



506
507
508
509
# File 'lib/processing/context.rb', line 506

def noSmooth()
  @smooth__ = false
  resizeCanvas__ width, height
end

#pixelDensity(density = nil) ⇒ Numeric

Changes and returns canvas pixel density.

Parameters:

  • density (Numeric, AUTO) (defaults to: nil)

    new pixel density, or AUTO to track display

Returns:

  • (Numeric)

    current pixel density

See Also:



464
465
466
467
# File 'lib/processing/context.rb', line 464

def pixelDensity(density = nil)
  resizeCanvas__ width, height, pixelDensity: density if density
  @window__.canvas.pixel_density
end

#pmouseXNumeric

Returns mouse x position in previous frame

Returns:

  • (Numeric)

    horizontal position of mouse

See Also:



762
763
764
# File 'lib/processing/context.rb', line 762

def pmouseX()
  @pointerPrev__&.x || 0
end

#pmouseYNumeric

Returns mouse y position in previous frame

Returns:

  • (Numeric)

    vertical position of mouse

See Also:



773
774
775
# File 'lib/processing/context.rb', line 773

def pmouseY()
  @pointerPrev__&.y || 0
end

#redrawnil

Calls draw block to redraw frame.



835
836
837
# File 'lib/processing/context.rb', line 835

def redraw()
  @redraw__ = true
end

#setTitle(title) ⇒ nil

Changes title of window.

Parameters:

  • title (String)

    new title

Returns:

  • (nil)

    nil

See Also:



450
451
452
453
# File 'lib/processing/context.rb', line 450

def setTitle(title)
  @window__.title = title
  nil
end

#setup(&block) ⇒ nil

Defines setup block.



208
209
210
211
# File 'lib/processing/context.rb', line 208

def setup(&block)
  @window__.setup = block if block
  nil
end

#size(width, height, pixelDensity: nil) ⇒ nil

Changes canvas size.

Parameters:

  • width (Integer)

    new width

  • height (Integer)

    new height

  • pixelDensity (Numeric, AUTO) (defaults to: nil)

    new pixel density, or AUTO to track display

Returns:

  • (nil)

    nil

See Also:



420
421
422
423
424
# File 'lib/processing/context.rb', line 420

def size(width, height, pixelDensity: nil)
  windowResize width, height
  resizeCanvas__ width, height, pixelDensity: pixelDensity, autoResize: false
  nil
end

#smoothnil

Enables anti-aliasing. (Anti-aliasing is disabled on high DPI screen)



493
494
495
496
497
# File 'lib/processing/context.rb', line 493

def smooth()
  @smooth__ = true
  resizeCanvas__ width, height
  nil
end

#touchEnded(&block) ⇒ nil

Defines touchEnded block.

Returns:

  • (nil)

    nil

See Also:



362
363
364
365
# File 'lib/processing/context.rb', line 362

def touchEnded(&block)
  @touchEndedBlock__ = block if block
  nil
end

#touchesArray

Returns array of touches

Returns:

  • (Array)

    Touch objects

See Also:



794
795
796
# File 'lib/processing/context.rb', line 794

def touches()
  @touches__
end

#touchMoved(&block) ⇒ nil

Defines touchMoved block.

Returns:

  • (nil)

    nil

See Also:



373
374
375
376
# File 'lib/processing/context.rb', line 373

def touchMoved(&block)
  @touchMovedBlock__ = block if block
  nil
end

#touchStarted(&block) ⇒ nil

Defines touchStarted block.

Returns:

  • (nil)

    nil

See Also:



351
352
353
354
# File 'lib/processing/context.rb', line 351

def touchStarted(&block)
  @touchStartedBlock__ = block if block
  nil
end

#windowHeightNumeric

Returns the height of the window.

Returns:

  • (Numeric)

    window height

See Also:



634
635
636
# File 'lib/processing/context.rb', line 634

def windowHeight()
  @window__.height
end

#windowMove(x, y) ⇒ nil

Move the position of the window.

Parameters:

  • x (Numeric)

    x position of the window

  • y (Numeric)

    y position of the window

Returns:

  • (nil)

    nil

See Also:



560
561
562
563
# File 'lib/processing/context.rb', line 560

def windowMove(x, y)
  @window__.pos = [x, y]
  nil
end

#windowMoved(&block) ⇒ nil

Defines windowMoved block.

Returns:

  • (nil)

    nil

See Also:



384
385
386
387
# File 'lib/processing/context.rb', line 384

def windowMoved(&block)
  @windowMovedBlock__ = block if block
  nil
end

#windowOrientation(*orientations) ⇒ nil

Sets window orientation mask

Parameters:

Returns:

  • (nil)

    nil



598
599
600
# File 'lib/processing/context.rb', line 598

def windowOrientation(*orientations)
  @window__.orientations = orientations.flatten.uniq
end

#windowResizable(resizable) ⇒ nil

Makes the window resizable or not.

Parameters:

  • resizable (Boolean)

    resizable or not

Returns:

  • (nil)

    nil

See Also:



587
588
589
590
# File 'lib/processing/context.rb', line 587

def windowResizable(resizable)
  @window__.resizable = resizable
  nil
end

#windowResize(width, height) ⇒ nil

Sets the size of the window.

Parameters:

  • width (Numeric)

    width of the window

  • height (Numeric)

    height of the window

Returns:

  • (nil)

    nil

See Also:



574
575
576
577
# File 'lib/processing/context.rb', line 574

def windowResize(width, height)
  @window__.size = [width, height]
  nil
end

#windowResized(&block) ⇒ nil

Defines windowResized block.



396
397
398
399
# File 'lib/processing/context.rb', line 396

def windowResized(&block)
  @windowResizedBlock__ = block if block
  nil
end

#windowWidthNumeric

Returns the width of the window.

Returns:

  • (Numeric)

    window width

See Also:



624
625
626
# File 'lib/processing/context.rb', line 624

def windowWidth()
  @window__.width
end

#windowXNumeric

Returns the x position of the window.

Returns:

  • (Numeric)

    horizontal position of the window



606
607
608
# File 'lib/processing/context.rb', line 606

def windowX()
  @window__.x
end

#windowYNumeric

Returns the y position of the window.

Returns:

  • (Numeric)

    vertical position of the window



614
615
616
# File 'lib/processing/context.rb', line 614

def windowY()
  @window__.y
end