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

Constants included from GraphicsContext

GraphicsContext::ADD, GraphicsContext::ALT, GraphicsContext::BACKSPACE, GraphicsContext::BASELINE, GraphicsContext::BLEND, GraphicsContext::BLUR, GraphicsContext::BOTTOM, GraphicsContext::CAPSLOCK, GraphicsContext::CENTER, GraphicsContext::CLEAR, GraphicsContext::COMMAND, GraphicsContext::CONTROL, GraphicsContext::CORNER, GraphicsContext::CORNERS, GraphicsContext::DARKEST, GraphicsContext::DEGREES, GraphicsContext::DELETE, GraphicsContext::DOWN, 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::HALF_PI, GraphicsContext::HELP, GraphicsContext::HOME, GraphicsContext::HSB, GraphicsContext::INVERT, GraphicsContext::LEFT, GraphicsContext::LIGHTEST, GraphicsContext::MITER, GraphicsContext::MULTIPLY, GraphicsContext::OPTION, GraphicsContext::PAGEDOWN, GraphicsContext::PAGEUP, GraphicsContext::PI, GraphicsContext::PROJECT, GraphicsContext::QUARTER_PI, GraphicsContext::RADIANS, GraphicsContext::RADIUS, 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::THRESHOLD, GraphicsContext::TOP, GraphicsContext::TWO_PI, GraphicsContext::UP, GraphicsContext::WIN

Instance Method Summary collapse

Methods included from GraphicsContext

#abs, #acos, #angleMode, #arc, #asin, #atan, #atan2, #background, #bezier, #blend, #blendMode, #ceil, #circle, #clip, #colorMode, #constrain, #copy, #cos, #createCapture, #createGraphics, #createImage, #createShader, #createVector, #curve, #degrees, #dist, #ellipse, #ellipseMode, #exp, #fill, #filter, #floor, #height, #image, #imageMode, #lerp, #line, #loadImage, #loadShader, #log, #mag, #map, #max, #min, #noClip, #noFill, #noStroke, #noTint, #noise, #norm, #pixelHeight, #pixelWidth, #point, #pop, #popMatrix, #popStyle, #pow, #push, #pushMatrix, #pushStyle, #quad, #radians, #random, #rect, #rectMode, #resetMatrix, #resetShader, #rotate, #round, #save, #scale, #shader, #sin, #sq, #sqrt, #square, #stroke, #strokeCap, #strokeJoin, #strokeWeight, #tan, #text, #textAlign, #textAscent, #textDescent, #textFont, #textSize, #textWidth, #tint, #translate, #triangle, #width

Instance Method Details

#createCanvas(width, height, pixelDensity: self.pixelDensity) ⇒ nil

Changes canvas size.

Parameters:

  • width (Integer)

    new width

  • height (Integer)

    new height

  • pixelDensity (Numeric) (defaults to: self.pixelDensity)

    new pixel density

Returns:

  • (nil)

    nil



345
346
347
348
# File 'lib/processing/context.rb', line 345

def createCanvas(width, height, pixelDensity: self.pixelDensity)
  resizeCanvas__ :createCanvas, width, height, pixelDensity
  nil
end

#displayDensityNumeric

Returns the pixel density of the display.

Returns:

  • (Numeric)

    pixel density



400
401
402
# File 'lib/processing/context.rb', line 400

def displayDensity()
  @window__.painter.pixel_density
end

#displayHeightNumeric

Returns the height of the display.

Returns:

  • (Numeric)

    height



392
393
394
# File 'lib/processing/context.rb', line 392

def displayHeight()
  @window__.screen.height
end

#displayWidthNumeric

Returns the width of the display.

Returns:

  • (Numeric)

    width



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

def displayWidth()
  @window__.screen.width
end

#draw(&block) ⇒ nil

Defines draw block.

Returns:

  • (nil)

    nil



193
194
195
196
# File 'lib/processing/context.rb', line 193

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

#frameCountInteger

Returns the number of frames since the program started.

Returns:

  • (Integer)

    total number of frames



475
476
477
# File 'lib/processing/context.rb', line 475

def frameCount()
  @frameCount__
end

#frameRateFloat

Returns the number of frames per second.

Returns:

  • (Float)

    frames per second



483
484
485
# File 'lib/processing/context.rb', line 483

def frameRate()
  @window__.event.fps
end

#keyString

Returns the last key that was pressed or released.

Returns:

  • (String)

    last key



491
492
493
# File 'lib/processing/context.rb', line 491

def key()
  @key__
end

#keyCodeSymbol

Returns the last key code that was pressed or released.

Returns:

  • (Symbol)

    last key code



499
500
501
# File 'lib/processing/context.rb', line 499

def keyCode()
  @keyCode__
end

#keyPressed(&block) ⇒ Boolean

Defines keyPressed block.

Returns:

  • (Boolean)

    is any key pressed or not



202
203
204
205
# File 'lib/processing/context.rb', line 202

def keyPressed(&block)
  @keyPressedBlock__ = block if block
  not @keysPressed__.empty?
end

#keyReleased(&block) ⇒ nil

Defines keyReleased block.

Returns:

  • (nil)

    nil



211
212
213
214
# File 'lib/processing/context.rb', line 211

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

#keyTyped(&block) ⇒ nil

Defines keyTyped block.

Returns:

  • (nil)

    nil



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

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

#loopnil

Enables calling draw block on every frame.

Returns:

  • (nil)

    nil



563
564
565
# File 'lib/processing/context.rb', line 563

def loop()
  @loop__ = true
end

#motion(&block) ⇒ nil

Defines motion block.

Returns:

  • (nil)

    nil



319
320
321
322
# File 'lib/processing/context.rb', line 319

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

#motionGravityVector

Returns vector for real world gravity

Returns:



555
556
557
# File 'lib/processing/context.rb', line 555

def motionGravity()
  @motionGravity__
end

#mouseButtonNumeric

Returns which mouse button was pressed

Returns:

  • (Numeric)

    LEFT, RIGHT, CENTER or 0



539
540
541
# File 'lib/processing/context.rb', line 539

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

#mouseClicked(&block) ⇒ nil

Defines mouseClicked block.

Returns:

  • (nil)

    nil



265
266
267
268
# File 'lib/processing/context.rb', line 265

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

#mouseDragged(&block) ⇒ nil

Defines mouseDragged block.

Returns:

  • (nil)

    nil



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

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

#mouseMoved(&block) ⇒ nil

Defines mouseMoved block.

Returns:

  • (nil)

    nil



247
248
249
250
# File 'lib/processing/context.rb', line 247

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

#mousePressed(&block) ⇒ Boolean

Defines mousePressed block.

Returns:

  • (Boolean)

    is any mouse button pressed or not



229
230
231
232
# File 'lib/processing/context.rb', line 229

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

#mouseReleased(&block) ⇒ nil

Defines mouseReleased block.

Returns:

  • (nil)

    nil



238
239
240
241
# File 'lib/processing/context.rb', line 238

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

#mouseXNumeric

Returns mouse x position

Returns:

  • (Numeric)

    horizontal position of mouse



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

def mouseX()
  @pointerPos__.x
end

#mouseYNumeric

Returns mouse y position

Returns:

  • (Numeric)

    vertical position of mouse



515
516
517
# File 'lib/processing/context.rb', line 515

def mouseY()
  @pointerPos__.y
end

#noLoopnil

Disables calling draw block on every frame.

Returns:

  • (nil)

    nil



571
572
573
# File 'lib/processing/context.rb', line 571

def noLoop()
  @loop__ = false
end

#pixelDensity(density = nil) ⇒ Numeric

Changes and returns canvas pixel density.

Parameters:

  • density (Numeric) (defaults to: nil)

    new pixel density

Returns:

  • (Numeric)

    current pixel density



367
368
369
370
# File 'lib/processing/context.rb', line 367

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

#pmouseXNumeric

Returns mouse x position in previous frame

Returns:

  • (Numeric)

    horizontal position of mouse



523
524
525
# File 'lib/processing/context.rb', line 523

def pmouseX()
  @pointerPrevPos__.x
end

#pmouseYNumeric

Returns mouse y position in previous frame

Returns:

  • (Numeric)

    vertical position of mouse



531
532
533
# File 'lib/processing/context.rb', line 531

def pmouseY()
  @pointerPrevPos__.y
end

#redrawnil

Calls draw block to redraw frame.

Returns:

  • (nil)

    nil



579
580
581
# File 'lib/processing/context.rb', line 579

def redraw()
  @redraw__ = true
end

#setTitle(title) ⇒ nil

Changes title of window.

Parameters:

  • title (String)

    new title

Returns:

  • (nil)

    nil



356
357
358
359
# File 'lib/processing/context.rb', line 356

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

#setup(&block) ⇒ nil

Defines setup block.

Returns:

  • (nil)

    nil



165
166
167
168
# File 'lib/processing/context.rb', line 165

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

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

Changes canvas size.

Parameters:

  • width (Integer)

    new width

  • height (Integer)

    new height

  • pixelDensity (Numeric) (defaults to: self.pixelDensity)

    new pixel density

Returns:

  • (nil)

    nil



332
333
334
335
# File 'lib/processing/context.rb', line 332

def size(width, height, pixelDensity: self.pixelDensity)
  resizeCanvas__ :size, width, height, pixelDensity
  nil
end

#touchEnded(&block) ⇒ nil

Defines touchEnded block.

Returns:

  • (nil)

    nil



283
284
285
286
# File 'lib/processing/context.rb', line 283

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

#touchesArray

Returns array of touches

Returns:

  • (Array)

    Touch objects



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

def touches()
  @touches__
end

#touchMoved(&block) ⇒ nil

Defines touchMoved block.

Returns:

  • (nil)

    nil



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

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

#touchStarted(&block) ⇒ nil

Defines touchStarted block.

Returns:

  • (nil)

    nil



274
275
276
277
# File 'lib/processing/context.rb', line 274

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

#windowHeightNumeric

Returns the height of the window.

Returns:

  • (Numeric)

    window height



467
468
469
# File 'lib/processing/context.rb', line 467

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



411
412
413
414
# File 'lib/processing/context.rb', line 411

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

#windowMoved(&block) ⇒ nil

Defines windowMoved block.

Returns:

  • (nil)

    nil



301
302
303
304
# File 'lib/processing/context.rb', line 301

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

#windowResizable(resizable) ⇒ nil

Makes the window resizable or not.

Parameters:

  • resizable (Boolean)

    resizable or not

Returns:

  • (nil)

    nil



434
435
436
437
# File 'lib/processing/context.rb', line 434

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



423
424
425
426
# File 'lib/processing/context.rb', line 423

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

#windowResized(&block) ⇒ nil

Defines windowResized block.

Returns:

  • (nil)

    nil



310
311
312
313
# File 'lib/processing/context.rb', line 310

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

#windowWidthNumeric

Returns the width of the window.

Returns:

  • (Numeric)

    window width



459
460
461
# File 'lib/processing/context.rb', line 459

def windowWidth()
  @window__.width
end

#windowXNumeric

Returns the x position of the window.

Returns:

  • (Numeric)

    horizontal position of the window



443
444
445
# File 'lib/processing/context.rb', line 443

def windowX()
  @window__.x
end

#windowYNumeric

Returns the y position of the window.

Returns:

  • (Numeric)

    vertical position of the window



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

def windowY()
  @window__.y
end