Module: Processing::GraphicsContext

Included in:
Context, Graphics
Defined in:
lib/processing/graphics_context.rb

Overview

Drawing context

Constant Summary collapse

PI =

PI

Math::PI
HALF_PI =

PI / 2

PI / 2
QUARTER_PI =

PI / 4

PI / 4
TWO_PI =

PI * 2

PI * 2
TAU =

PI * 2

PI * 2
RGBA =

RGBA format for createImage().

:rgba
RGB =

RGB format for createImage, or RGB mode for colorMode().

:rgb
HSB =

HSB mode for colorMode().

:hsb
RADIANS =

Radian mode for angleMode().

:radians
DEGREES =

Degree mode for angleMode().

:degrees
CORNER =

Mode for rectMode(), ellipseMode() and imageMode().

:corner
CORNERS =

Mode for rectMode(), ellipseMode() and imageMode().

:corners
CENTER =

Mode for rectMode(), ellipseMode(), imageMode() and textAlign().

:center
RADIUS =

Mode for rectMode() and ellipseMode().

:radius
PROJECT =

Mode for strokeCap().

:square
MITER =

Mode for strokeJoin().

:miter
ROUND =

Mode for strokeCap() and strokeJoin().

:round
SQUARE =

Mode for strokeCap() and strokeJoin().

:butt
BLEND =

Mode for blendMode().

:normal
ADD =

Mode for blendMode().

:add
SUBTRACT =

Mode for blendMode().

:subtract
LIGHTEST =

Mode for blendMode().

:lightest
DARKEST =

Mode for blendMode().

:darkest
EXCLUSION =

Mode for blendMode().

:exclusion
MULTIPLY =

Mode for blendMode().

:multiply
SCREEN =

Mode for blendMode().

:screen
REPLACE =

Mode for blendMode().

:replace
LEFT =

Key code or Mode for textAlign().

:left
RIGHT =

Key code or Mode for textAlign().

:right
TOP =

Mode for textAlign().

:top
BOTTOM =

Mode for textAlign().

:bottom
BASELINE =

Mode for textAlign().

:baseline
THRESHOLD =

Filter type for filter()

:threshold
GRAY =

Filter type for filter()

:gray
INVERT =

Filter type for filter()

:invert
BLUR =

Filter type for filter()

:blur
ENTER =

Key codes.

:enter
SPACE =
:space
TAB =
:tab
DELETE =
:delete
BACKSPACE =
:backspace
ESC =
:escape
HOME =
:home
PAGEUP =

END = :end

:pageup
PAGEDOWN =
:pagedown
CLEAR =
:clear
SHIFT =
:shift
CONTROL =
:control
ALT =
:alt
WIN =
:win
COMMAND =
:command
OPTION =
:option
FUNCTION =
:function
CAPSLOCK =
:capslock
SECTION =
:section
HELP =
:help
F1 =
:f1
F2 =
:f2
F3 =
:f3
F4 =
:f4
F5 =
:f5
F6 =
:f6
F7 =
:f7
F8 =
:f8
F9 =
:f9
F10 =
:f10
F11 =
:f11
F12 =
:f12
F13 =
:f13
F14 =
:f14
F15 =
:f15
F16 =
:f16
F17 =
:f17
F18 =
:f18
F19 =
:f19
F20 =
:f20
F21 =
:f21
F22 =
:f22
F23 =
:f23
F24 =
:f24
UP =
:up
DOWN =
:down

Instance Method Summary collapse

Instance Method Details

#abs(value) ⇒ Numeric

Returns the absolute number of the value.

Parameters:

  • value (Numeric)

    number

Returns:

  • (Numeric)

    absolute number



1334
1335
1336
# File 'lib/processing/graphics_context.rb', line 1334

def abs(value)
  value.abs
end

#acos(value) ⇒ Numeric

Returns the inverse of cos().

Parameters:

  • value (Numeric)

    value for calculation

Returns:

  • (Numeric)

    the arc cosine



1633
1634
1635
# File 'lib/processing/graphics_context.rb', line 1633

def acos(value)
  Math.acos value
end

#alpha(color) ⇒ Numeric

Returns the red value of the color.

Parameters:

  • color (Numeric)

    color value

Returns:

  • (Numeric)

    the red value



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

def alpha(color)
  ((color >> 24) & 0xff) / 255.0 * @colorMaxes__[3]
end

#angleMode(mode = nil) ⇒ RADIANS, DEGREES

Sets angle mode.

Parameters:

Returns:



423
424
425
426
427
428
429
430
431
432
433
434
# File 'lib/processing/graphics_context.rb', line 423

def angleMode(mode = nil)
  if mode != nil
    @angleMode__  = mode
    @angleScale__ =
      case mode.downcase.to_sym
      when RADIANS then RAD2DEG__
      when DEGREES then 1.0
      else raise ArgumentError, "invalid angle mode: #{mode}"
      end
  end
  @angleMode__
end

#arc(a, b, c, d, start, stop) ⇒ nil Also known as: drawArc

Draws an arc.

The parameters a, b, c, and d are determined by ellipseMode().

Parameters:

  • a (Numeric)

    horizontal position of the shape, by default

  • b (Numeric)

    vertical position of the shape, by default

  • c (Numeric)

    width of the shape, by default

  • d (Numeric)

    height of the shape, by default

  • start (Numeric)

    angle to start the arc

  • stop (Numeric)

    angle to stop the arc

Returns:

  • (nil)

    nil



918
919
920
921
922
923
924
925
# File 'lib/processing/graphics_context.rb', line 918

def arc(a, b, c, d, start, stop)
  assertDrawing__
  x, y, w, h = toXYWH__ @ellipseMode__, a, b, c, d
  start      = toAngle__(-start)
  stop       = toAngle__(-stop)
  @painter__.ellipse x, y, w, h, from: start, to: stop
  nil
end

#asin(value) ⇒ Numeric

Returns the inverse of sin().

Parameters:

  • value (Numeric)

    value for calculation

Returns:

  • (Numeric)

    the arc sine



1623
1624
1625
# File 'lib/processing/graphics_context.rb', line 1623

def asin(value)
  Math.asin value
end

#atan(value) ⇒ Numeric

Returns the inverse of tan().

Parameters:

  • value (Numeric)

    value for valculation

Returns:

  • (Numeric)

    the arc tangent



1643
1644
1645
# File 'lib/processing/graphics_context.rb', line 1643

def atan(value)
  Math.atan value
end

#atan2(y, x) ⇒ Numeric

Returns the angle from a specified point.

Parameters:

  • y (Numeric)

    y of the point

  • x (Numeric)

    x of the point

Returns:

  • (Numeric)

    the angle in radians



1654
1655
1656
# File 'lib/processing/graphics_context.rb', line 1654

def atan2(y, x)
  Math.atan2 y, x
end

#background(str) ⇒ nil #background(str, alpha) ⇒ nil #background(gray) ⇒ nil #background(gray, alpha) ⇒ nil #background(r, g, b) ⇒ nil #background(r, g, b, alpha) ⇒ nil

Clears screen.

Parameters:

  • str (String)

    color code like ‘#00AAFF’

  • gray (Integer)

    gray value (0..255)

  • r (Integer)

    red value (0..255)

  • g (Integer)

    green value (0..255)

  • b (Integer)

    blue value (0..255)

  • alpha (Integer)

    alpha value (0..255)

Returns:

  • (nil)

    nil



792
793
794
795
796
797
798
799
800
801
802
803
# File 'lib/processing/graphics_context.rb', line 792

def background(*args)
  assertDrawing__
  rgba = toRGBA__(*args)
  if rgba[3] == 1
    @painter__.background(*rgba)
  else
    @painter__.push fill: rgba, stroke: :none do |_|
      @painter__.rect 0, 0, width, height
    end
  end
  nil
end

#bezier(x1, y1, cx1, cy1, cx2, cy2, x2, y2) ⇒ nil Also known as: drawBezier

Draws a Bezier spline curve.

Parameters:

  • x1 (Numeric)

    horizontal position of first point

  • y1 (Numeric)

    vertical position of first point

  • cx1 (Numeric)

    horizontal position of first control point

  • cy1 (Numeric)

    vertical position of first control point

  • cx2 (Numeric)

    horizontal position of second control point

  • cy2 (Numeric)

    vertical position of second control point

  • x2 (Numeric)

    horizontal position of second point

  • y2 (Numeric)

    vertical position of second point

Returns:

  • (nil)

    nil



1017
1018
1019
1020
1021
# File 'lib/processing/graphics_context.rb', line 1017

def bezier(x1, y1, cx1, cy1, cx2, cy2, x2, y2)
  assertDrawing__
  @painter__.bezier x1, y1, cx1, cy1, cx2, cy2, x2, y2
  nil
end

#blend(sx, sy, sw, sh, dx, dy, dw, dh, mode) ⇒ nil #blend(img, sx, sy, sw, sh, dx, dy, dw, dh, mode) ⇒ nil

Blends image.

Parameters:

  • img (Image) (defaults to: nil)

    image for blend source

  • sx (Numrtic)

    x position of source region

  • sy (Numrtic)

    y position of source region

  • sw (Numrtic)

    width of source region

  • sh (Numrtic)

    height of source region

  • dx (Numrtic)

    x position of destination region

  • dy (Numrtic)

    y position of destination region

  • dw (Numrtic)

    width of destination region

  • dh (Numrtic)

    height of destination region

  • mode (BLEND, ADD, SUBTRACT, LIGHTEST, DARKEST, EXCLUSION, MULTIPLY, SCREEN, REPLACE)

    blend mode

Returns:

  • (nil)

    nil



1130
1131
1132
1133
1134
1135
1136
1137
# File 'lib/processing/graphics_context.rb', line 1130

def blend(img = nil, sx, sy, sw, sh, dx, dy, dw, dh, mode)
  assertDrawing__
  tint  = @tint__ ? toRGBA__(*@tint__) : 1
  img ||= self
  img.drawImage__(
    @painter__, sx, sy, sw, sh, dx, dy, dw, dh,
    fill: tint, stroke: :none, blend_mode: mode)
end

#blendMode(mode = nil) ⇒ nil

Sets blend mode. Default is BLEND.

Parameters:

Returns:

  • (nil)

    nil



520
521
522
523
524
525
526
# File 'lib/processing/graphics_context.rb', line 520

def blendMode(mode = nil)
  if mode != nil
    @blendMode__          = mode
    @painter__.blend_mode = mode
  end
  @blendMode__
end

#blue(color) ⇒ Numeric

Returns the blue value of the color.

Parameters:

  • color (Numeric)

    color value

Returns:

  • (Numeric)

    the blue value



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

def blue(color)
  (color & 0xff) / 255.0 * @colorMaxes__[2]
end

#ceil(value) ⇒ Numeric

Returns the closest integer number greater than or equal to the value.

Parameters:

  • value (Numeric)

    number

Returns:

  • (Numeric)

    rounded up number



1344
1345
1346
# File 'lib/processing/graphics_context.rb', line 1344

def ceil(value)
  value.ceil
end

#circle(x, y, extent) ⇒ nil Also known as: drawCircle

Draws a circle.

Parameters:

  • x (Numeric)

    horizontal position of the shape

  • y (Numeric)

    vertical position of the shape

  • extent (Numeric)

    width and height of the shape

Returns:

  • (nil)

    nil



899
900
901
# File 'lib/processing/graphics_context.rb', line 899

def circle(x, y, extent)
  ellipse x, y, extent, extent
end

#clip(a, b, c, d) ⇒ nil

Limits the drawable rectangle.

The parameters a, b, c, and d are determined by rectMode().

Parameters:

  • a (Numeric)

    horizontal position of the drawable area, by default

  • b (Numeric)

    vertical position of the drawable area, by default

  • c (Numeric)

    width of the drawable area, by default

  • d (Numeric)

    height of the drawable area, by default

Returns:

  • (nil)

    nil



667
668
669
670
671
# File 'lib/processing/graphics_context.rb', line 667

def clip(a, b, c, d)
  x, y, w, h = toXYWH__ @imageMode__, a, b, c, d
  @painter__.clip x, y, w, h
  nil
end

#color(gray) ⇒ Integer #color(gray, alpha) ⇒ Integer #color(v1, v2, v3) ⇒ Integer #color(v1, v2, v3, alpha) ⇒ Integer

Creates color value.

Parameters:

  • gray (Numeric)

    the value for gray

  • alpha (Numeric)

    the value for alpha

  • v1 (Numeric)

    the value for red or hue

  • v2 (Numeric)

    the value for green or saturation

  • v3 (Numeric)

    the value for blue or brightness

Returns:

  • (Integer)

    the rgba color value



342
343
344
345
346
# File 'lib/processing/graphics_context.rb', line 342

def color(*args)
  toRGBA__(*args)
    .map {|n| (n * 255).to_i.clamp 0, 255}
    .then {|r, g, b, a| Image.toColor__ r, g, b, a}
end

#colorMode(mode) ⇒ RGB, HSB #colorMode(mode, max) ⇒ RGB, HSB #colorMode(mode, max1, max2, max3) ⇒ RGB, HSB #colorMode(mode, max1, max2, max3, maxA) ⇒ RGB, HSB

Sets color mode and max color values.

Parameters:

  • mode (RGB, HSB) (defaults to: nil)

    RGB or HSB

  • max (Numeric)

    max values for all color values

  • max1 (Numeric)

    max value for red or hue

  • max2 (Numeric)

    max value for green or saturation

  • max3 (Numeric)

    max value for blue or brightness

  • maxA (Numeric)

    max value for alpha

Returns:



311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
# File 'lib/processing/graphics_context.rb', line 311

def colorMode(mode = nil, *maxes)
  if mode != nil
    mode = mode.downcase.to_sym
    raise ArgumentError, "invalid color mode: #{mode}" unless [RGB, HSB].include?(mode)
    raise ArgumentError unless [0, 1, 3, 4].include?(maxes.size)

    @colorMode__ = mode
    @hsbColor__  = mode == HSB
    case maxes.size
    when 1    then @colorMaxes__                 = [maxes.first.to_f] * 4
    when 3, 4 then @colorMaxes__[0...maxes.size] = maxes.map &:to_f
    end
  end
  @colorMode__
end

#constrain(value, min, max) ⇒ Numeric

Constrains the number between min..max.

Parameters:

  • value (Numeric)

    number to be constrained

  • min (Numeric)

    lower bound of the range

  • max (Numeric)

    upper bound of the range

Returns:

  • (Numeric)

    constrained number



1563
1564
1565
# File 'lib/processing/graphics_context.rb', line 1563

def constrain(value, min, max)
  value < min ? min : (value > max ? max : value)
end

#copy(sx, sy, sw, sh, dx, dy, dw, dh) ⇒ nil #copy(img, sx, sy, sw, sh, dx, dy, dw, dh) ⇒ nil

Copies image.

Parameters:

  • img (Image) (defaults to: nil)

    image for copy source

  • sx (Numrtic)

    x position of source region

  • sy (Numrtic)

    y position of source region

  • sw (Numrtic)

    width of source region

  • sh (Numrtic)

    height of source region

  • dx (Numrtic)

    x position of destination region

  • dy (Numrtic)

    y position of destination region

  • dw (Numrtic)

    width of destination region

  • dh (Numrtic)

    height of destination region

Returns:

  • (nil)

    nil



1108
1109
1110
# File 'lib/processing/graphics_context.rb', line 1108

def copy(img = nil, sx, sy, sw, sh, dx, dy, dw, dh)
  blend img, sx, sy, sw, sh, dx, dy, dw, dh, BLEND
end

#cos(angle) ⇒ Numeric

Returns the cosine of an angle.

Parameters:

  • angle (Numeric)

    angle in radians

Returns:

  • (Numeric)

    the cosine



1603
1604
1605
# File 'lib/processing/graphics_context.rb', line 1603

def cos(angle)
  Math.cos angle
end

#createCapture(*args) ⇒ Capture

Creates a camera object as a video input device.

Returns:



1780
1781
1782
# File 'lib/processing/graphics_context.rb', line 1780

def createCapture(*args)
  Capture.new(*args)
end

#createGraphics(width, height, pixelDensity = 1) ⇒ Graphics

Creates a new off-screen graphics context object.

Parameters:

  • width (Numeric)

    width of graphics image

  • height (Numeric)

    height of graphics image

  • pixelDensity (Numeric) (defaults to: 1)

    pixel density of graphics image

Returns:



1734
1735
1736
# File 'lib/processing/graphics_context.rb', line 1734

def createGraphics(width, height, pixelDensity = 1)
  Graphics.new width, height, pixelDensity
end

#createImage(w, h) ⇒ Image #createImage(w, h, format) ⇒ Image

Creates a new image.

Parameters:

  • w (Numeric)

    width of new image

  • h (Numeric)

    height of new image

  • format (RGB, RGBA) (defaults to: RGBA)

    image format

Returns:

Raises:

  • (ArgumentError)


1720
1721
1722
1723
1724
# File 'lib/processing/graphics_context.rb', line 1720

def createImage(w, h, format = RGBA)
  colorspace = {RGB => Rays::RGB, RGBA => Rays::RGBA}[format]
  raise ArgumentError, "Unknown image format" unless colorspace
  Image.new Rays::Image.new(w, h, colorspace).paint {background 0, 0}
end

#createShader(vertPath, fragPath) ⇒ Shader #createShader(vertSource, fragSource) ⇒ Shader

Creates a shader object.

Passing nil for a vertex shader parameter causes the following default vertex shader to be used. “‘ attribute vec3 position; attribute vec3 texCoord; attribute vec4 color; varying vec4 vertPosition; varying vec4 vertTexCoord; varying vec4 vertColor; uniform mat4 transform; uniform mat4 texMatrix; void main ()

vec4 pos__   = vec4(position, 1.0);
vertPosition = pos__;
vertTexCoord = texMatrix * vec4(texCoord, 1.0);
vertColor    = color;
gl_Position  = transform * pos__;

“‘

Parameters:

  • vertPath (String)

    vertex shader file path

  • fragPath (String)

    fragment shader file path

  • vertSource (String)

    vertex shader source

  • fragSource (String)

    fragment shader source

Returns:



1770
1771
1772
1773
1774
# File 'lib/processing/graphics_context.rb', line 1770

def createShader(vert, frag)
  vert = File.read if vert && File.exist?(vert)
  frag = File.read if frag && File.exist?(frag)
  Shader.new vert, frag
end

#createVectorVector #createVector(x, y) ⇒ Vector #createVector(x, y, z) ⇒ Vector

Creates a new vector.

Parameters:

  • x (Numeric)

    x of new vector

  • y (Numeric)

    y of new vector

  • z (Numeric)

    z of new vector

Returns:



1705
1706
1707
# File 'lib/processing/graphics_context.rb', line 1705

def createVector(*args)
  Vector.new(*args, context: self)
end

#curve(cx1, cy1, x1, y1, x2, y2, cx2, cy2) ⇒ nil Also known as: drawCurve

Draws a Catmull-Rom spline curve.

Parameters:

  • cx1 (Numeric)

    horizontal position of beginning control point

  • cy1 (Numeric)

    vertical position of beginning control point

  • x1 (Numeric)

    horizontal position of first point

  • y1 (Numeric)

    vertical position of first point

  • x2 (Numeric)

    horizontal position of second point

  • y2 (Numeric)

    vertical position of second point

  • cx2 (Numeric)

    horizontal position of ending control point

  • cy2 (Numeric)

    vertical position of ending control point

Returns:

  • (nil)

    nil



996
997
998
999
1000
# File 'lib/processing/graphics_context.rb', line 996

def curve(cx1, cy1, x1, y1, x2, y2, cx2, cy2)
  assertDrawing__
  @painter__.curve cx1, cy1, x1, y1, x2, y2, cx2, cy2
  nil
end

#degrees(radian) ⇒ Numeric

Converts radian to degree.

Parameters:

  • radian (Numeric)

    radian to convert

Returns:

  • (Numeric)

    degree



1583
1584
1585
# File 'lib/processing/graphics_context.rb', line 1583

def degrees(radian)
  radian * RAD2DEG__
end

#dist(x1, y1, x2, y2) ⇒ Numeric #dist(x1, y1, z1, x2, y2, z2) ⇒ Numeric

Returns distance between 2 points.

Parameters:

  • x1 (Numeric)

    x of first point

  • y1 (Numeric)

    y of first point

  • z1 (Numeric)

    z of first point

  • x2 (Numeric)

    x of second point

  • y2 (Numeric)

    y of second point

  • z2 (Numeric)

    z of second point

Returns:

  • (Numeric)

    distance between 2 points



1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
# File 'lib/processing/graphics_context.rb', line 1453

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

#ellipse(a, b, c, d) ⇒ nil Also known as: drawEllipse

Draws an ellipse.

The parameters a, b, c, and d are determined by ellipseMode().

Parameters:

  • a (Numeric)

    horizontal position of the shape, by default

  • b (Numeric)

    vertical position of the shape, by default

  • c (Numeric)

    width of the shape, by default

  • d (Numeric)

    height of the shape, by default

Returns:

  • (nil)

    nil



882
883
884
885
886
887
# File 'lib/processing/graphics_context.rb', line 882

def ellipse(a, b, c, d)
  assertDrawing__
  x, y, w, h = toXYWH__ @ellipseMode__, a, b, c, d
  @painter__.ellipse x, y, w, h
  nil
end

#ellipseMode(mode) ⇒ nil

Sets ellipse mode. Default is CENTER.

CORNER -> ellipse(left, top, width, height) CORNERS -> ellipse(left, top, right, bottom) CENTER -> ellipse(center_x, center_y, width, height) RADIUS -> ellipse(center_x, center_y, radius_h, radius_v)

Parameters:

Returns:

  • (nil)

    nil



485
486
487
# File 'lib/processing/graphics_context.rb', line 485

def ellipseMode(mode)
  @ellipseMode__ = mode
end

#exp(n) ⇒ Numeric

Returns Euler’s number e raised to the power of value.

Parameters:

  • value (Numeric)

    number

Returns:

  • (Numeric)

    result number



1384
1385
1386
# File 'lib/processing/graphics_context.rb', line 1384

def exp(n)
  Math.exp n
end

#fill(rgb) ⇒ nil #fill(rgb, alpha) ⇒ nil #fill(gray) ⇒ nil #fill(gray, alpha) ⇒ nil #fill(r, g, b) ⇒ nil #fill(r, g, b, alpha) ⇒ nil

Sets fill color.

Parameters:

  • rgb (String)

    color code like ‘#00AAFF’

  • gray (Integer)

    gray value (0..255)

  • r (Integer)

    red value (0..255)

  • g (Integer)

    green value (0..255)

  • b (Integer)

    blue value (0..255)

  • alpha (Integer)

    alpha value (0..255)

Returns:

  • (nil)

    nil



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

def fill(*args)
  @painter__.fill(*toRGBA__(*args))
  nil
end

#filter(*args) ⇒ Object

Applies an image filter to screen.

overload filter(shader) overload filter(type) overload filter(type, param)

Parameters:



770
771
772
# File 'lib/processing/graphics_context.rb', line 770

def filter(*args)
  @filter__ = Shader.createFilter__(*args)
end

#floor(value) ⇒ Numeric

Returns the closest integer number less than or equal to the value.

Parameters:

  • value (Numeric)

    number

Returns:

  • (Numeric)

    rounded down number



1354
1355
1356
# File 'lib/processing/graphics_context.rb', line 1354

def floor(value)
  value.floor
end

#green(color) ⇒ Numeric

Returns the green value of the color.

Parameters:

  • color (Numeric)

    color value

Returns:

  • (Numeric)

    the green value



364
365
366
# File 'lib/processing/graphics_context.rb', line 364

def green(color)
  ((color >> 8) & 0xff) / 255.0 * @colorMaxes__[1]
end

#heightNumeric

Returns the height of the graphics object.

Returns:

  • (Numeric)

    height



267
268
269
# File 'lib/processing/graphics_context.rb', line 267

def height()
  @image__.height
end

#image(img, a, b) ⇒ nil #image(img, a, b, c, d) ⇒ nil Also known as: drawImage

Draws an image.

The parameters a, b, c, and d are determined by imageMode().

Parameters:

  • img (Image)

    image to draw

  • a (Numeric)

    horizontal position of the image, by default

  • b (Numeric)

    vertical position of the image, by default

  • c (Numeric) (defaults to: nil)

    width of the image, by default

  • d (Numeric) (defaults to: nil)

    height of the image, by default

Returns:

  • (nil)

    nil



1081
1082
1083
1084
1085
1086
1087
# File 'lib/processing/graphics_context.rb', line 1081

def image(img, a, b, c = nil, d = nil)
  assertDrawing__
  x, y, w, h = toXYWH__ @imageMode__, a, b, c || img.width, d || img.height
  tint       = @tint__ ? toRGBA__(*@tint__) : 1
  img.drawImage__ @painter__, x, y, w, h, fill: tint, stroke: :none
  nil
end

#imageMode(mode) ⇒ nil

Sets image mode. Default is CORNER.

CORNER -> image(img, left, top, width, height) CORNERS -> image(img, left, top, right, bottom) CENTER -> image(img, center_x, center_y, width, height)

Parameters:

Returns:

  • (nil)

    nil



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

def imageMode(mode)
  @imageMode__ = mode
end

#lerp(start, stop, amount) ⇒ Numeric

Returns the interpolated number between range start..stop.

Parameters:

  • start (Numeric)

    lower bound of the range

  • stop (Numeric)

    upper bound of the range

  • amount (Numeric)

    amount to interpolate

Returns:

  • (Numeric)

    interporated number



1487
1488
1489
# File 'lib/processing/graphics_context.rb', line 1487

def lerp(start, stop, amount)
  start + (stop - start) * amount
end

#lerpColor(color1, color2, amount) ⇒ Integer

Returns the interpolated color between color1 and color2.

Parameters:

  • color1 (Integer)

    the 1st color for interpolation

  • color2 (Integer)

    the 2nd color for interpolation

  • amount (Numeric)

    amount to interpolate

Returns:

  • (Integer)

    interporated color



1499
1500
1501
1502
1503
1504
1505
# File 'lib/processing/graphics_context.rb', line 1499

def lerpColor(color1, color2, amount)
  color(
    lerp(red(  color1), red(  color2), amount),
    lerp(green(color1), green(color2), amount),
    lerp(blue( color1), blue( color2), amount),
    lerp(alpha(color1), alpha(color2), amount))
end

#line(x1, y1, x2, y2) ⇒ nil Also known as: drawLine

Draws a line.

Parameters:

  • x1 (Numeric)

    horizontal position of first point

  • y1 (Numeric)

    vertical position of first point

  • x2 (Numeric)

    horizontal position of second point

  • y2 (Numeric)

    vertical position of second point

Returns:

  • (nil)

    nil



829
830
831
832
833
# File 'lib/processing/graphics_context.rb', line 829

def line(x1, y1, x2, y2)
  assertDrawing__
  @painter__.line x1, y1, x2, y2
  nil
end

#loadImage(filename, extension = nil) ⇒ Image

Loads image.

Parameters:

  • filename (String)

    file name to load image

  • extension (String) (defaults to: nil)

    type of image to load (ex. ‘png’)

Returns:

  • (Image)

    loaded image object



1791
1792
1793
1794
# File 'lib/processing/graphics_context.rb', line 1791

def loadImage(filename, extension = nil)
  filename = getImage__ filename, extension if filename =~ %r|^https?://|
  Image.new Rays::Image.load filename
end

#loadShader(fragPath) ⇒ Shader #loadShader(fragPath, vertPath) ⇒ Shader

Loads shader file.

Parameters:

  • fragPath (String)

    fragment shader file path

  • vertPath (String) (defaults to: nil)

    vertex shader file path

Returns:

  • (Shader)

    loaded shader object



1806
1807
1808
# File 'lib/processing/graphics_context.rb', line 1806

def loadShader(fragPath, vertPath = nil)
  createShader vertPath, fragPath
end

#log(n) ⇒ Numeric

Returns the natural logarithm (the base-e logarithm) of a number.

Parameters:

  • value (Numeric)

    number (> 0.0)

Returns:

  • (Numeric)

    result number



1374
1375
1376
# File 'lib/processing/graphics_context.rb', line 1374

def log(n)
  Math.log n
end

#mag(x, y) ⇒ Numeric #mag(x, y, z) ⇒ Numeric

Returns the magnitude (or length) of a vector.

Parameters:

  • x (Numeric)

    x of point

  • y (Numeric)

    y of point

  • z (Numeric)

    z of point

Returns:

  • (Numeric)

    magnitude



1430
1431
1432
1433
1434
1435
1436
1437
# File 'lib/processing/graphics_context.rb', line 1430

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.

Parameters:

  • value (Numeric)

    number to be mapped

  • start1 (Numeric)

    lower bound of the range1

  • stop1 (Numeric)

    upper bound of the range1

  • start2 (Numeric)

    lower bound of the range2

  • stop2 (Numeric)

    upper bound of the range2

Returns:

  • (Numeric)

    mapped number



1517
1518
1519
# File 'lib/processing/graphics_context.rb', line 1517

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.

Parameters:

  • a (Numeric)

    value to compare

  • b (Numeric)

    value to compare

  • c (Numeric)

    value to compare

  • array (Numeric)

    values to compare

Returns:

  • (Numeric)

    maximum value



1551
1552
1553
# File 'lib/processing/graphics_context.rb', line 1551

def max(*args)
  args.flatten.max
end

#min(a, b) ⇒ Numeric #min(a, b, c) ⇒ Numeric #min(array) ⇒ Numeric

Returns minimum value.

Parameters:

  • a (Numeric)

    value to compare

  • b (Numeric)

    value to compare

  • c (Numeric)

    value to compare

  • array (Numeric)

    values to compare

Returns:

  • (Numeric)

    minimum value



1534
1535
1536
# File 'lib/processing/graphics_context.rb', line 1534

def min(*args)
  args.flatten.min
end

#noClipnil

Disables clipping.

Returns:

  • (nil)

    nil



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

def noClip()
  @painter__.no_clip
  nil
end

#noFillnil

Disables filling.

Returns:

  • (nil)

    nil



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

def noFill()
  @painter__.fill nil
  nil
end

#noise(x) ⇒ Numeric #noise(x, y) ⇒ Numeric #noise(x, y, z) ⇒ Numeric

Returns the perlin noise value.

Parameters:

  • x (Numeric)

    horizontal point in noise space

  • y (Numeric) (defaults to: 0)

    vertical point in noise space

  • z (Numeric) (defaults to: 0)

    depth point in noise space

Returns:

  • (Numeric)

    noise value (0.0..1.0)



1670
1671
1672
# File 'lib/processing/graphics_context.rb', line 1670

def noise(x, y = 0, z = 0)
  Rays.perlin(x, y, z) / 2.0 + 0.5
end

#norm(value, start, stop) ⇒ Numeric

Normalize the value from range start..stop into 0..1.

Parameters:

  • value (Numeric)

    number to be normalized

  • start (Numeric)

    lower bound of the range

  • stop (Numeric)

    upper bound of the range

Returns:

  • (Numeric)

    normalized value between 0..1



1475
1476
1477
# File 'lib/processing/graphics_context.rb', line 1475

def norm(value, start, stop)
  (value.to_f - start.to_f) / (stop.to_f - start.to_f)
end

#noStrokenil

Disables drawing stroke.

Returns:

  • (nil)

    nil



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

def noStroke()
  @painter__.stroke nil
  nil
end

#noTintnil

Resets tint color.

Returns:

  • (nil)

    nil



652
653
654
# File 'lib/processing/graphics_context.rb', line 652

def noTint()
  @tint__ = nil
end

#pixelDensityNumeric

Returns the pixel density of the graphics object.

Returns:

  • (Numeric)

    pixel density



291
292
293
# File 'lib/processing/graphics_context.rb', line 291

def pixelDensity()
  @painter__.pixel_density
end

#pixelHeightNumeric

Returns the height of the graphics object in pixels.

Returns:

  • (Numeric)

    height



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

def pixelHeight()
  height * pixelDensity
end

#pixelWidthNumeric

Returns the width of the graphics object in pixels.

Returns:

  • (Numeric)

    width



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

def pixelWidth()
  width * pixelDensity
end

#point(x, y) ⇒ nil Also known as: drawPoint

Draws a point.

Parameters:

  • x (Numeric)

    horizontal position

  • y (Numeric)

    vertical position

Returns:

  • (nil)

    nil



812
813
814
815
816
# File 'lib/processing/graphics_context.rb', line 812

def point(x, y)
  assertDrawing__
  @painter__.line x, y, x, y
  nil
end

#popnil

Restore styles and transformations from stack.

Returns:

  • (nil)

    nil



1301
1302
1303
1304
# File 'lib/processing/graphics_context.rb', line 1301

def pop()
  popMatrix
  popStyle
end

#popMatrixnil

Pops the current transformation matrix from stack.

Returns:

  • (nil)

    nil



1209
1210
1211
1212
1213
1214
# File 'lib/processing/graphics_context.rb', line 1209

def popMatrix()
  assertDrawing__
  raise "matrix stack underflow" if @matrixStack__.empty?
  @painter__.matrix = @matrixStack__.pop
  nil
end

#popStylenil

Restore style values from the style stack.

Returns:

  • (nil)

    nil



1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
# File 'lib/processing/graphics_context.rb', line 1261

def popStyle()
  assertDrawing__
  raise "style stack underflow" if @styleStack__.empty?
  @painter__.fill,
  @painter__.stroke,
  @painter__.stroke_width,
  @painter__.stroke_cap,
  @painter__.stroke_join,
  @painter__.clip,
  @painter__.blend_mode,
  @painter__.font,
  @painter__.shader,
  @hsbColor__,
  @colorMaxes__,
  @angleScale__,
  @rectMode__,
  @ellipseMode__,
  @imageMode__,
  @textAlignH__,
  @textAlignV__,
  @tint__ = @styleStack__.pop
  nil
end

#pow(value, exponent) ⇒ Numeric

Returns value raised to the power of exponent.

Parameters:

  • value (Numeric)

    base number

  • exponent (Numeric)

    exponent number

Returns:

  • (Numeric)

    value ** exponent



1395
1396
1397
# File 'lib/processing/graphics_context.rb', line 1395

def pow(value, exponent)
  value ** exponent
end

#push(&block) ⇒ Object

Save current styles and transformations to stack.

Returns:

  • (Object)

    result of the expression at the end of the block



1289
1290
1291
1292
1293
1294
1295
# File 'lib/processing/graphics_context.rb', line 1289

def push(&block)
  pushMatrix
  pushStyle
  block.call if block
ensure
  pop if block
end

#pushMatrix(&block) ⇒ Object

Pushes the current transformation matrix to stack.

Returns:

  • (Object)

    result of the expression at the end of the block



1197
1198
1199
1200
1201
1202
1203
# File 'lib/processing/graphics_context.rb', line 1197

def pushMatrix(&block)
  assertDrawing__
  @matrixStack__.push @painter__.matrix
  block.call if block
ensure
  popMatrix if block
end

#pushStyle(&block) ⇒ Object

Save current style values to the style stack.

Returns:

  • (Object)

    result of the expression at the end of the block



1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
# File 'lib/processing/graphics_context.rb', line 1230

def pushStyle(&block)
  assertDrawing__
  @styleStack__.push [
    @painter__.fill,
    @painter__.stroke,
    @painter__.stroke_width,
    @painter__.stroke_cap,
    @painter__.stroke_join,
    @painter__.clip,
    @painter__.blend_mode,
    @painter__.font,
    @painter__.shader,
    @hsbColor__,
    @colorMaxes__,
    @angleScale__,
    @rectMode__,
    @ellipseMode__,
    @imageMode__,
    @textAlignH__,
    @textAlignV__,
    @tint__,
  ]
  block.call if block
ensure
  popStyle if block
end

#quad(x1, y1, x2, y2, x3, y3, x4, y4) ⇒ nil Also known as: drawQuad

Draws a quad.

Parameters:

  • x1 (Numeric)

    horizontal position of first point

  • y1 (Numeric)

    vertical position of first point

  • x2 (Numeric)

    horizontal position of second point

  • y2 (Numeric)

    vertical position of second point

  • x3 (Numeric)

    horizontal position of third point

  • y3 (Numeric)

    vertical position of third point

  • x4 (Numeric)

    horizontal position of fourth point

  • y4 (Numeric)

    vertical position of fourth point

Returns:

  • (nil)

    nil



975
976
977
978
979
# File 'lib/processing/graphics_context.rb', line 975

def quad(x1, y1, x2, y2, x3, y3, x4, y4)
  assertDrawing__
  @painter__.line x1, y1, x2, y2, x3, y3, x4, y4, loop: true
  nil
end

#radians(degree) ⇒ Numeric

Converts degree to radian.

Parameters:

  • degree (Numeric)

    degree to convert

Returns:

  • (Numeric)

    radian



1573
1574
1575
# File 'lib/processing/graphics_context.rb', line 1573

def radians(degree)
  degree * DEG2RAD__
end

#randomFloat #random(high) ⇒ Float #random(low, high) ⇒ Float #random(choices) ⇒ Float

Returns a random number in range low…high

Parameters:

  • low (Numeric)

    lower limit

  • high (Numeric)

    upper limit

  • choices (Array)

    array to choose from

Returns:

  • (Float)

    random number



1687
1688
1689
1690
1691
# File 'lib/processing/graphics_context.rb', line 1687

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

#rect(a, b, c, d) ⇒ nil #rect(a, b, c, d, r) ⇒ nil #rect(a, b, c, d, tl, tr, br, bl) ⇒ nil Also known as: drawRect

Draws a rectangle.

The parameters a, b, c, and d are determined by rectMode().

Parameters:

  • a (Numeric)

    horizontal position of the shape, by default

  • b (Numeric)

    vertical position of the shape, by default

  • c (Numeric)

    width of the shape, by default

  • d (Numeric)

    height of the shape, by default

  • r (Numeric)

    radius for all corners

  • tl (Numeric)

    radius for top-left corner

  • tr (Numeric)

    radius for top-right corner

  • br (Numeric)

    radius for bottom-right corner

  • bl (Numeric)

    radius for bottom-left corner

Returns:

  • (nil)

    nil



857
858
859
860
861
862
863
864
865
866
867
# File 'lib/processing/graphics_context.rb', line 857

def rect(a, b, c, d, *args)
  assertDrawing__
  x, y, w, h = toXYWH__ @rectMode__, a, b, c, d
  case args.size
  when 0 then @painter__.rect x, y, w, h
  when 1 then @painter__.rect x, y, w, h, round: args[0]
  when 4 then @painter__.rect x, y, w, h, lt: args[0], rt: args[1], rb: args[2], lb: args[3]
  else raise ArgumentError # ToDo: refine error message
  end
  nil
end

#rectMode(mode) ⇒ nil

Sets rect mode. Default is CORNER.

CORNER -> rect(left, top, width, height) CORNERS -> rect(left, top, right, bottom) CENTER -> rect(center_x, center_y, width, height) RADIUS -> rect(center_x, center_y, radius_h, radius_v)

Parameters:

Returns:

  • (nil)

    nil



470
471
472
# File 'lib/processing/graphics_context.rb', line 470

def rectMode(mode)
  @rectMode__ = mode
end

#red(color) ⇒ Numeric

Returns the red value of the color.

Parameters:

  • color (Numeric)

    color value

Returns:

  • (Numeric)

    the red value



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

def red(color)
  ((color >> 16) & 0xff) / 255.0 * @colorMaxes__[0]
end

#resetMatrixnil

Reset current transformation matrix with identity matrix.

Returns:

  • (nil)

    nil



1220
1221
1222
1223
1224
# File 'lib/processing/graphics_context.rb', line 1220

def resetMatrix()
  assertDrawing__
  @painter__.matrix = 1
  nil
end

#resetShadernil

Resets shader.

Returns:

  • (nil)

    nil



755
756
757
758
# File 'lib/processing/graphics_context.rb', line 755

def resetShader()
  @painter__.no_shader
  nil
end

#rotate(angle) ⇒ nil

Applies rotation matrix to current transformation matrix.

Parameters:

  • angle (Numeric)

    angle for rotation

Returns:

  • (nil)

    nil



1187
1188
1189
1190
1191
# File 'lib/processing/graphics_context.rb', line 1187

def rotate(angle)
  assertDrawing__
  @painter__.rotate toAngle__ angle
  nil
end

#round(value) ⇒ Numeric

Returns the closest integer number.

Parameters:

  • value (Numeric)

    number

Returns:

  • (Numeric)

    rounded number



1364
1365
1366
# File 'lib/processing/graphics_context.rb', line 1364

def round(value)
  value.round
end

#save(filename) ⇒ Object

Saves screen image to file.

Parameters:

  • filename (String)

    file name to save image



1143
1144
1145
# File 'lib/processing/graphics_context.rb', line 1143

def save(filename)
  @window__.canvas_image.save filename
end

#scale(s) ⇒ nil #scale(x, y) ⇒ nil

Applies scale matrix to current transformation matrix.

Parameters:

  • s (Numeric)

    horizontal and vertical scale

  • x (Numeric)

    horizontal scale

  • y (Numeric)

    vertical scale

Returns:

  • (nil)

    nil



1175
1176
1177
1178
1179
# File 'lib/processing/graphics_context.rb', line 1175

def scale(x, y)
  assertDrawing__
  @painter__.scale x, y
  nil
end

#shader(shader) ⇒ nil

Sets shader.

Parameters:

  • shader (Shader)

    a shader to apply

Returns:

  • (nil)

    nil



746
747
748
749
# File 'lib/processing/graphics_context.rb', line 746

def shader(shader)
  @painter__.shader shader&.getInternal__
  nil
end

#sin(angle) ⇒ Numeric

Returns the sine of an angle.

Parameters:

  • angle (Numeric)

    angle in radians

Returns:

  • (Numeric)

    the sine



1593
1594
1595
# File 'lib/processing/graphics_context.rb', line 1593

def sin(angle)
  Math.sin angle
end

#sq(value) ⇒ Numeric

Returns squared value.

Parameters:

  • value (Numeric)

    number

Returns:

  • (Numeric)

    squared value



1405
1406
1407
# File 'lib/processing/graphics_context.rb', line 1405

def sq(value)
  value * value
end

#sqrt(value) ⇒ Numeric

Returns squared value.

Parameters:

  • value (Numeric)

    number

Returns:

  • (Numeric)

    squared value



1415
1416
1417
# File 'lib/processing/graphics_context.rb', line 1415

def sqrt(value)
  Math.sqrt value
end

#square(x, y, extent) ⇒ nil Also known as: drawSquare

Draws a square.

Parameters:

  • x (Numeric)

    horizontal position of the shape

  • y (Numeric)

    vertical position of the shape

  • extent (Numeric)

    width and height of the shape

Returns:

  • (nil)

    nil



937
938
939
# File 'lib/processing/graphics_context.rb', line 937

def square(x, y, extent)
  rect x, y, extent, extent
end

#stroke(rgb) ⇒ nil #stroke(rgb, alpha) ⇒ nil #stroke(gray) ⇒ nil #stroke(gray, alpha) ⇒ nil #stroke(r, g, b) ⇒ nil #stroke(r, g, b, alpha) ⇒ nil

Sets stroke color.

Parameters:

  • rgb (String)

    color code like ‘#00AAFF’

  • gray (Integer)

    gray value (0..255)

  • r (Integer)

    red value (0..255)

  • g (Integer)

    green value (0..255)

  • b (Integer)

    blue value (0..255)

  • alpha (Integer)

    alpha value (0..255)

Returns:

  • (nil)

    nil



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

def stroke(*args)
  @painter__.stroke(*toRGBA__(*args))
  nil
end

#strokeCap(cap) ⇒ nil

Sets stroke cap mode.

Parameters:

Returns:

  • (nil)

    nil



609
610
611
612
# File 'lib/processing/graphics_context.rb', line 609

def strokeCap(cap)
  @painter__.stroke_cap cap
  nil
end

#strokeJoin(join) ⇒ nil

Sets stroke join mode.

Parameters:

Returns:

  • (nil)

    nil



620
621
622
623
# File 'lib/processing/graphics_context.rb', line 620

def strokeJoin(join)
  @painter__.stroke_join join
  nil
end

#strokeWeight(weight) ⇒ nil

Sets stroke weight.

Parameters:

  • weight (Numeric)

    width of stroke

Returns:

  • (nil)

    nil



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

def strokeWeight(weight)
  @painter__.stroke_width weight
  nil
end

#tan(angle) ⇒ Numeric

Returns the ratio of the sine and cosine of an angle.

Parameters:

  • angle (Numeric)

    angle in radians

Returns:

  • (Numeric)

    the tangent



1613
1614
1615
# File 'lib/processing/graphics_context.rb', line 1613

def tan(angle)
  Math.tan angle
end

#text(str) ⇒ nil #text(str, x, y) ⇒ nil #text(str, a, b, c, d) ⇒ nil Also known as: drawText

Draws a text.

The parameters a, b, c, and d are determined by rectMode().

Parameters:

  • str (String)

    text to draw

  • x (Numeric)

    horizontal position of the text

  • y (Numeric)

    vertical position of the text

  • a (Numeric)

    horizontal position of the text, by default

  • b (Numeric)

    vertical position of the text, by default

  • c (Numeric)

    width of the text, by default

  • d (Numeric)

    height of the text, by default

Returns:

  • (nil)

    nil



1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
# File 'lib/processing/graphics_context.rb', line 1043

def text(str, x, y, x2 = nil, y2 = nil)
  assertDrawing__
  if x2
    raise ArgumentError, "missing y2 parameter" unless y2
    x, y, w, h = toXYWH__ @rectMode__, x, y, x2, y2
    case @textAlignH__
    when RIGHT  then x +=  w - @painter__.font.width(str)
    when CENTER then x += (w - @painter__.font.width(str)) / 2
    end
    case @textAlignV__
    when BOTTOM then y +=  h - @painter__.font.height
    when CENTER then y += (h - @painter__.font.height) / 2
    else
    end
  else
    y -= @painter__.font.ascent
  end
  @painter__.text str, x, y
  nil
end

#textAlign(horizontal, vertical = BASELINE) ⇒ Object



723
724
725
726
# File 'lib/processing/graphics_context.rb', line 723

def textAlign(horizontal, vertical = BASELINE)
  @textAlignH__ = horizontal
  @textAlignV__ = vertical
end

#textAscentObject



715
716
717
# File 'lib/processing/graphics_context.rb', line 715

def textAscent()
  @painter__.font.ascent
end

#textDescentObject



719
720
721
# File 'lib/processing/graphics_context.rb', line 719

def textDescent()
  @painter__.font.descent
end

#textFont(font) ⇒ Font #textFont(name) ⇒ Font #textFont(font, size) ⇒ Font #textFont(name, size) ⇒ Font

Sets font.

Parameters:

  • font (Font) (defaults to: nil)

    font

  • name (String)

    font name

  • size (Numeric) (defaults to: nil)

    font size (max 256)

Returns:

  • (Font)

    current font



695
696
697
698
# File 'lib/processing/graphics_context.rb', line 695

def textFont(font = nil, size = nil)
  setFont__ font, size if font || size
  Font.new @painter__.font
end

#textSize(size) ⇒ nil

Sets text size.

Parameters:

  • size (Numeric)

    font size (max 256)

Returns:

  • (nil)

    nil



706
707
708
709
# File 'lib/processing/graphics_context.rb', line 706

def textSize(size)
  setFont__ nil, size
  nil
end

#textWidth(str) ⇒ Object



711
712
713
# File 'lib/processing/graphics_context.rb', line 711

def textWidth(str)
  @painter__.font.width str
end

#tint(rgb) ⇒ nil #tint(rgb, alpha) ⇒ nil #tint(gray) ⇒ nil #tint(gray, alpha) ⇒ nil #tint(r, g, b) ⇒ nil #tint(r, g, b, alpha) ⇒ nil

Sets fill color for drawing images.

Parameters:

  • rgb (String)

    color code like ‘#00AAFF’

  • gray (Integer)

    gray value (0..255)

  • r (Integer)

    red value (0..255)

  • g (Integer)

    green value (0..255)

  • b (Integer)

    blue value (0..255)

  • alpha (Integer)

    alpha value (0..255)

Returns:

  • (nil)

    nil



643
644
645
646
# File 'lib/processing/graphics_context.rb', line 643

def tint(*args)
  @tint__ = args
  nil
end

#translate(x, y) ⇒ nil #translate(x, y, z) ⇒ nil

Applies translation matrix to current transformation matrix.

Parameters:

  • x (Numeric)

    left/right translation

  • y (Numeric)

    up/down translation

  • y (Numeric)

    forward/backward translation

Returns:

  • (nil)

    nil



1158
1159
1160
1161
1162
# File 'lib/processing/graphics_context.rb', line 1158

def translate(x, y, z = 0)
  assertDrawing__
  @painter__.translate x, y, z
  nil
end

#triangle(x1, y1, x2, y2, x3, y3) ⇒ nil Also known as: drawTriangle

Draws a triangle.

Parameters:

  • x1 (Numeric)

    horizontal position of first point

  • y1 (Numeric)

    vertical position of first point

  • x2 (Numeric)

    horizontal position of second point

  • y2 (Numeric)

    vertical position of second point

  • x3 (Numeric)

    horizontal position of third point

  • y3 (Numeric)

    vertical position of third point

Returns:

  • (nil)

    nil



954
955
956
957
958
# File 'lib/processing/graphics_context.rb', line 954

def triangle(x1, y1, x2, y2, x3, y3)
  assertDrawing__
  @painter__.line x1, y1, x2, y2, x3, y3, loop: true
  nil
end

#widthNumeric

Returns the width of the graphics object.

Returns:

  • (Numeric)

    width



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

def width()
  @image__.width
end