Module: RubySketch::Processing::GraphicsContext

Included in:
Context, Graphics
Defined in:
lib/rubysketch/processing.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
RGB =

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
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
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
BUTT =

Mode for strokeCap().

:butt
MITER =

Mode for strokeJoin().

:miter
ROUND =

Mode for strokeCap() and strokeJoin().

:round
SQUARE =

Mode for strokeCap() and strokeJoin().

:square

Instance Method Summary collapse

Instance Method Details

#angleMode(mode) ⇒ nil

Sets angle mode.

Parameters:

Returns:

  • (nil)

    nil



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

def 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
  nil
end

#arc(a, b, c, d, start, stop) ⇒ nil

Draws an arc.

Parameters:

  • a (Numeric)

    horizontal position of the shape

  • b (Numeric)

    vertical position of the shape

  • c (Numeric)

    width of the shape

  • d (Numeric)

    height of the shape

  • start (Numeric)

    angle to start the arc

  • stop (Numeric)

    angle to stop the arc

Returns:

  • (nil)

    nil



1422
1423
1424
1425
1426
1427
1428
1429
# File 'lib/rubysketch/processing.rb', line 1422

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

#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



1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
# File 'lib/rubysketch/processing.rb', line 1310

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

#bezier(x1, y1, cx1, cy1, cx2, cy2, x2, y2) ⇒ nil

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



1511
1512
1513
1514
1515
# File 'lib/rubysketch/processing.rb', line 1511

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

#circle(x, y, extent) ⇒ nil

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



1407
1408
1409
# File 'lib/rubysketch/processing.rb', line 1407

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

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

Sets color mode and max color values.

Parameters:

  • mode (RGB, HSB)

    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:

  • (nil)

    nil

Raises:

  • (ArgumentError)


1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
# File 'lib/rubysketch/processing.rb', line 1032

def colorMode(mode, *maxes)
  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)

  @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
  nil
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



1592
1593
1594
1595
1596
# File 'lib/rubysketch/processing.rb', line 1592

def copy(img = nil, sx, sy, sw, sh, dx, dy, dw, dh)
  assertDrawing__
  src = img&.getInternal__ || @window__.canvas_image
  @painter__.image src, sx, sy, sw, sh, dx, dy, dw, dh
end

#curve(cx1, cy1, x1, y1, x2, y2, cx2, cy2) ⇒ nil

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



1492
1493
1494
1495
1496
# File 'lib/rubysketch/processing.rb', line 1492

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

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

Draws an ellipse.

Parameters:

  • a (Numeric)

    horizontal position of the shape

  • b (Numeric)

    vertical position of the shape

  • c (Numeric)

    width of the shape

  • d (Numeric)

    height of the shape

Returns:

  • (nil)

    nil



1392
1393
1394
1395
1396
1397
# File 'lib/rubysketch/processing.rb', line 1392

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



1120
1121
1122
# File 'lib/rubysketch/processing.rb', line 1120

def ellipseMode(mode)
  @ellipseMode__ = mode
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



1167
1168
1169
1170
# File 'lib/rubysketch/processing.rb', line 1167

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

#heightObject



1012
1013
1014
# File 'lib/rubysketch/processing.rb', line 1012

def height()
  @image__.height
end

#image(img, a, b) ⇒ nil #image(img, a, b, c, d) ⇒ nil

Draws an image.

Parameters:

  • img (Image)

    image to draw

  • a (Numeric)

    horizontal position of the image

  • b (Numeric)

    vertical position of the image

  • c (Numeric) (defaults to: nil)

    width of the image

  • d (Numeric) (defaults to: nil)

    height of the image

Returns:

  • (nil)

    nil



1567
1568
1569
1570
1571
1572
1573
# File 'lib/rubysketch/processing.rb', line 1567

def image(img, a, b, c = nil, d = nil)
  assertDrawing__
  i = img.getInternal__
  x, y, w, h = toXYWH__ @imageMode__, a, b, c || i.width, d || i.height
  @painter__.image i, x, y, w, h
  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



1134
1135
1136
# File 'lib/rubysketch/processing.rb', line 1134

def imageMode(mode)
  @imageMode__ = mode
end

#init__(image, painter) ⇒ Object



965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
# File 'lib/rubysketch/processing.rb', line 965

def init__(image, painter)
  @drawing__     = false
  @hsbColor__    = false
  @colorMaxes__  = [1.0] * 4
  @angleScale__  = 1.0
  @rectMode__    = nil
  @ellipseMode__ = nil
  @imageMode__   = nil
  @textAlignH__  = nil
  @textAlignV__  = nil
  @matrixStack__ = []
  @styleStack__  = []

  updateCanvas__ image, painter

  colorMode   RGB, 255
  angleMode   RADIANS
  rectMode    CORNER
  ellipseMode CENTER
  imageMode   CORNER
  textAlign   LEFT

  fill 255
  stroke 0
  strokeWeight 1
end

#line(x1, y1, x2, y2) ⇒ nil

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



1347
1348
1349
1350
1351
# File 'lib/rubysketch/processing.rb', line 1347

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

#noFillnil

Disables filling.

Returns:

  • (nil)

    nil



1232
1233
1234
1235
# File 'lib/rubysketch/processing.rb', line 1232

def noFill()
  @painter__.fill nil
  nil
end

#noStrokenil

Disables drawing stroke.

Returns:

  • (nil)

    nil



1241
1242
1243
1244
# File 'lib/rubysketch/processing.rb', line 1241

def noStroke()
  @painter__.stroke nil
  nil
end

#point(x, y) ⇒ nil

Draws a point.

Parameters:

  • x (Numeric)

    horizontal position

  • y (Numeric)

    vertical position

Returns:

  • (nil)

    nil



1330
1331
1332
1333
1334
1335
1336
# File 'lib/rubysketch/processing.rb', line 1330

def point(x, y)
  assertDrawing__
  w = @painter__.stroke_width
  w = 1 if w == 0
  @painter__.ellipse x - (w / 2.0), y - (w / 2.0), w, w
  nil
end

#popnil

Restore styles and transformations from stack.

Returns:

  • (nil)

    nil



1741
1742
1743
1744
# File 'lib/rubysketch/processing.rb', line 1741

def pop()
  popMatrix
  popStyle
end

#popMatrixnil

Pops the current transformation matrix from stack.

Returns:

  • (nil)

    nil



1658
1659
1660
1661
1662
1663
# File 'lib/rubysketch/processing.rb', line 1658

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



1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
# File 'lib/rubysketch/processing.rb', line 1706

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

#push(&block) ⇒ nil

Save current styles and transformations to stack.

Returns:

  • (nil)

    nil



1728
1729
1730
1731
1732
1733
1734
1735
# File 'lib/rubysketch/processing.rb', line 1728

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

#pushMatrix(&block) ⇒ nil

Pushes the current transformation matrix to stack.

Returns:

  • (nil)

    nil



1644
1645
1646
1647
1648
1649
1650
1651
1652
# File 'lib/rubysketch/processing.rb', line 1644

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

#pushStyle(&block) ⇒ nil

Save current style values to the style stack.

Returns:

  • (nil)

    nil



1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
# File 'lib/rubysketch/processing.rb', line 1679

def pushStyle(&block)
  assertDrawing__
  @styleStack__.push [
    @painter__.fill,
    @painter__.stroke,
    @painter__.stroke_width,
    @painter__.stroke_cap,
    @painter__.stroke_join,
    @painter__.font,
    @hsbColor__,
    @colorMaxes__,
    @angleScale__,
    @rectMode__,
    @ellipseMode__,
    @imageMode__
  ]
  if block
    block.call
    popStyle
  end
  nil
end

#quad(x1, y1, x2, y2, x3, y3, x4, y4) ⇒ nil

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



1473
1474
1475
1476
1477
# File 'lib/rubysketch/processing.rb', line 1473

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

#rect(a, b, c, d) ⇒ nil #rect(a, b, c, d, r) ⇒ nil #rect(a, b, c, d, tl, tr, br, bl) ⇒ nil

Draws a rectangle.

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



1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
# File 'lib/rubysketch/processing.rb', line 1371

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



1105
1106
1107
# File 'lib/rubysketch/processing.rb', line 1105

def rectMode(mode)
  @rectMode__ = mode
end

#resetMatrixnil

Reset current transformation matrix with identity matrix.

Returns:

  • (nil)

    nil



1669
1670
1671
1672
1673
# File 'lib/rubysketch/processing.rb', line 1669

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

#rotate(angle) ⇒ nil

Applies rotation matrix to current transformation matrix.

Parameters:

  • angle (Numeric)

    angle for rotation

Returns:

  • (nil)

    nil



1634
1635
1636
1637
1638
# File 'lib/rubysketch/processing.rb', line 1634

def rotate(angle)
  assertDrawing__
  @painter__.rotate toAngle__ angle
  nil
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



1622
1623
1624
1625
1626
# File 'lib/rubysketch/processing.rb', line 1622

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

#square(x, y, extent) ⇒ nil

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



1439
1440
1441
# File 'lib/rubysketch/processing.rb', line 1439

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



1190
1191
1192
1193
# File 'lib/rubysketch/processing.rb', line 1190

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

#strokeCap(cap) ⇒ nil

Sets stroke cap mode.

Parameters:

Returns:

  • (nil)

    nil



1212
1213
1214
1215
# File 'lib/rubysketch/processing.rb', line 1212

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

#strokeJoin(join) ⇒ nil

Sets stroke join mode.

Parameters:

Returns:

  • (nil)

    nil



1223
1224
1225
1226
# File 'lib/rubysketch/processing.rb', line 1223

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

#strokeWeight(weight) ⇒ nil

Sets stroke weight.

Parameters:

  • weight (Numeric)

    width of stroke

Returns:

  • (nil)

    nil



1201
1202
1203
1204
# File 'lib/rubysketch/processing.rb', line 1201

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

#text(str) ⇒ nil #text(str, x, y) ⇒ nil #text(str, a, b, c, d) ⇒ nil

Draws a text.

Parameters:

  • str (String)

    text to draw

  • x (Numeric)

    horizontal position of the text

  • y (Numeric)

    vertical position of the text

  • a (Numeric)

    equivalent to parameters of the rect(), see rectMode()

  • b (Numeric)

    equivalent to parameters of the rect(), see rectMode()

  • c (Numeric)

    equivalent to parameters of the rect(), see rectMode()

  • d (Numeric)

    equivalent to parameters of the rect(), see rectMode()

Returns:

  • (nil)

    nil



1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
# File 'lib/rubysketch/processing.rb', line 1533

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



1281
1282
1283
1284
# File 'lib/rubysketch/processing.rb', line 1281

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

#textAscentObject



1273
1274
1275
# File 'lib/rubysketch/processing.rb', line 1273

def textAscent()
  @painter__.font.ascent
end

#textDescentObject



1277
1278
1279
# File 'lib/rubysketch/processing.rb', line 1277

def textDescent()
  @painter__.font.descent
end

#textFont(name = nil, size = nil) ⇒ Font

Sets font.

Parameters:

  • name (String) (defaults to: nil)

    font name

  • size (Numeric) (defaults to: nil)

    font size (max 256)

Returns:

  • (Font)

    current font



1253
1254
1255
1256
# File 'lib/rubysketch/processing.rb', line 1253

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

#textSize(size) ⇒ nil

Sets text size.

Parameters:

  • size (Numeric)

    font size (max 256)

Returns:

  • (nil)

    nil



1264
1265
1266
1267
# File 'lib/rubysketch/processing.rb', line 1264

def textSize(size)
  setFont__ @painter__.font.name, size
  nil
end

#textWidth(str) ⇒ Object



1269
1270
1271
# File 'lib/rubysketch/processing.rb', line 1269

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

#translate(x, y) ⇒ nil

Applies translation matrix to current transformation matrix.

Parameters:

  • x (Numeric)

    horizontal transformation

  • y (Numeric)

    vertical transformation

Returns:

  • (nil)

    nil



1605
1606
1607
1608
1609
# File 'lib/rubysketch/processing.rb', line 1605

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

#triangle(x1, y1, x2, y2, x3, y3) ⇒ nil

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



1454
1455
1456
1457
1458
# File 'lib/rubysketch/processing.rb', line 1454

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

#updateCanvas__(image, painter) ⇒ Object



992
993
994
# File 'lib/rubysketch/processing.rb', line 992

def updateCanvas__(image, painter)
  @image__, @painter__ = image, painter
end

#widthObject



1008
1009
1010
# File 'lib/rubysketch/processing.rb', line 1008

def width()
  @image__.width
end