Class: Processing::Context

Inherits:
Object
  • Object
show all
Includes:
GraphicsContext
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, #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



312
313
314
315
# File 'lib/processing/context.rb', line 312

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

#displayDensityNumeric

Returns pixel density of display.

Returns:

  • (Numeric)

    pixel density



354
355
356
# File 'lib/processing/context.rb', line 354

def displayDensity()
  @window__.painter.pixel_density
end

#draw(&block) ⇒ nil

Defines draw block.

Returns:

  • (nil)

    nil



178
179
180
181
# File 'lib/processing/context.rb', line 178

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

#frameCountInteger

Returns number of frames since program started.

Returns:

  • (Integer)

    total number of frames



378
379
380
# File 'lib/processing/context.rb', line 378

def frameCount()
  @frameCount__
end

#frameRateFloat

Returns number of frames per second.

Returns:

  • (Float)

    frames per second



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

def frameRate()
  @window__.event.fps
end

#keyString

Returns the last key that was pressed or released.

Returns:

  • (String)

    last key



394
395
396
# File 'lib/processing/context.rb', line 394

def key()
  @key__
end

#keyCodeSymbol

Returns the last key code that was pressed or released.

Returns:

  • (Symbol)

    last key code



402
403
404
# File 'lib/processing/context.rb', line 402

def keyCode()
  @keyCode__
end

#keyPressed(&block) ⇒ Boolean

Defines keyPressed block.

Returns:

  • (Boolean)

    is any key pressed or not



187
188
189
190
# File 'lib/processing/context.rb', line 187

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

#keyReleased(&block) ⇒ nil

Defines keyReleased block.

Returns:

  • (nil)

    nil



196
197
198
199
# File 'lib/processing/context.rb', line 196

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

#keyTyped(&block) ⇒ nil

Defines keyTyped block.

Returns:

  • (nil)

    nil



205
206
207
208
# File 'lib/processing/context.rb', line 205

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

#loopnil

Enables calling draw block on every frame.

Returns:

  • (nil)

    nil



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

def loop()
  @loop__ = true
end

#motion(&block) ⇒ nil

Defines motion block.

Returns:

  • (nil)

    nil



286
287
288
289
# File 'lib/processing/context.rb', line 286

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

#motionGravityVector

Returns vector for real world gravity

Returns:



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

def motionGravity()
  @motionGravity__
end

#mouseButtonNumeric

Returns which mouse button was pressed

Returns:

  • (Numeric)

    LEFT, RIGHT, CENTER or 0



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

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

#mouseClicked(&block) ⇒ nil

Defines mouseClicked block.

Returns:

  • (nil)

    nil



250
251
252
253
# File 'lib/processing/context.rb', line 250

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

#mouseDragged(&block) ⇒ nil

Defines mouseDragged block.

Returns:

  • (nil)

    nil



241
242
243
244
# File 'lib/processing/context.rb', line 241

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

#mouseMoved(&block) ⇒ nil

Defines mouseMoved block.

Returns:

  • (nil)

    nil



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

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

#mousePressed(&block) ⇒ Boolean

Defines mousePressed block.

Returns:

  • (Boolean)

    is any mouse button pressed or not



214
215
216
217
# File 'lib/processing/context.rb', line 214

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

#mouseReleased(&block) ⇒ nil

Defines mouseReleased block.

Returns:

  • (nil)

    nil



223
224
225
226
# File 'lib/processing/context.rb', line 223

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

#mouseXNumeric

Returns mouse x position

Returns:

  • (Numeric)

    horizontal position of mouse



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

def mouseX()
  @pointerPos__.x
end

#mouseYNumeric

Returns mouse y position

Returns:

  • (Numeric)

    vertical position of mouse



418
419
420
# File 'lib/processing/context.rb', line 418

def mouseY()
  @pointerPos__.y
end

#noLoopnil

Disables calling draw block on every frame.

Returns:

  • (nil)

    nil



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

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



334
335
336
337
# File 'lib/processing/context.rb', line 334

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



426
427
428
# File 'lib/processing/context.rb', line 426

def pmouseX()
  @pointerPrevPos__.x
end

#pmouseYNumeric

Returns mouse y position in previous frame

Returns:

  • (Numeric)

    vertical position of mouse



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

def pmouseY()
  @pointerPrevPos__.y
end

#redrawnil

Calls draw block to redraw frame.

Returns:

  • (nil)

    nil



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

def redraw()
  @redraw__ = true
end

#setTitle(title) ⇒ nil

Changes title of window.

Parameters:

  • title (String)

    new title

Returns:

  • (nil)

    nil



323
324
325
326
# File 'lib/processing/context.rb', line 323

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

#setup(&block) ⇒ nil

Defines setup block.

Returns:

  • (nil)

    nil



152
153
154
155
# File 'lib/processing/context.rb', line 152

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



299
300
301
302
# File 'lib/processing/context.rb', line 299

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

#touchEnded(&block) ⇒ nil

Defines touchEnded block.

Returns:

  • (nil)

    nil



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

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

#touchesArray

Returns array of touches

Returns:

  • (Array)

    Touch objects



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

def touches()
  @touches__
end

#touchMoved(&block) ⇒ nil

Defines touchMoved block.

Returns:

  • (nil)

    nil



277
278
279
280
# File 'lib/processing/context.rb', line 277

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

#touchStarted(&block) ⇒ nil

Defines touchStarted block.

Returns:

  • (nil)

    nil



259
260
261
262
# File 'lib/processing/context.rb', line 259

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

#windowHeightNumeric

Returns window height.

Returns:

  • (Numeric)

    window height



370
371
372
# File 'lib/processing/context.rb', line 370

def windowHeight()
  @window__.height
end

#windowWidthNumeric

Returns window width.

Returns:

  • (Numeric)

    window width



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

def windowWidth()
  @window__.width
end