Class: RubySketch::Processing

Inherits:
Object
  • Object
show all
Extended by:
Starter
Includes:
Math
Defined in:
lib/rubysketch/processing.rb

Overview

Processing compatible API

Defined Under Namespace

Classes: Font, Image, TextBounds

Constant Summary collapse

HALF_PI =
PI / 2
QUARTER_PI =
PI / 4
TWO_PI =
PI * 2
TAU =
PI * 2
RGB =

RGB mode for colorMode() function.

:RGB
HSB =

HSB mode for colorMode() function.

:HSB
RADIANS =

Radian mode for angleMode() function.

:RADIANS
DEGREES =

Degree mode for angleMode() function.

:DEGREES
CORNER =
:CORNER
CORNERS =
:CORNERS
CENTER =
:CENTER
RADIUS =
:RADIUS

Instance Method Summary collapse

Methods included from Starter

start

Instance Method Details

#abs(value) ⇒ Numeric

Returns the absolute number of the value.

Parameters:

  • value (Numeric)

    number

Returns:

  • (Numeric)

    absolute number



82
83
84
# File 'lib/rubysketch/processing.rb', line 82

def abs (value)
  value.abs
end

#angleMode(mode) ⇒ nil

Sets angle mode.

Parameters:

Returns:

  • (nil)

    nil



536
537
538
539
540
541
542
543
# File 'lib/rubysketch/processing.rb', line 536

def angleMode (mode)
  @angleScale__ = case mode
    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



814
815
816
817
818
819
820
# File 'lib/rubysketch/processing.rb', line 814

def arc (a, b, c, d, start, stop)
  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



609
610
611
612
613
614
615
616
617
618
619
# File 'lib/rubysketch/processing.rb', line 609

def background (*args)
  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

#ceil(value) ⇒ Numeric

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

Parameters:

  • value (Numeric)

    number

Returns:

  • (Numeric)

    rounded up number



92
93
94
# File 'lib/rubysketch/processing.rb', line 92

def ceil (value)
  value.ceil
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



799
800
801
# File 'lib/rubysketch/processing.rb', line 799

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)


489
490
491
492
493
494
495
496
497
498
499
# File 'lib/rubysketch/processing.rb', line 489

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

  @hsbColor__ = mode.upcase == 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

#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



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

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

#degrees(radian) ⇒ Numeric

Converts radian to degree.

Parameters:

  • radian (Numeric)

    radian to convert

Returns:

  • (Numeric)

    degree



285
286
287
# File 'lib/rubysketch/processing.rb', line 285

def degrees (radian)
  radian * RAD2DEG__
end

#displayDensityNumeric

Returns pixel density

Returns:

  • (Numeric)

    pixel density



437
438
439
# File 'lib/rubysketch/processing.rb', line 437

def displayDensity ()
  @painter__.pixel_density
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



171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/rubysketch/processing.rb', line 171

def dist (*args)
  case args.size
    when 4
      x1, y1, x2, y2 = *args
      xx, yy = x2 - x1, y2 - y1
      sqrt xx * xx + yy * yy
    when 3
      x1, y1, z1, x2, y2, z2 = *args
      xx, yy, zz = x2 - x1, y2 - y1, z2 - z1
      sqrt xx * xx + yy * yy + zz * zz
    else raise ArgumentError
  end
end

#draw(&block) ⇒ Object

Define draw block.



315
316
317
318
# File 'lib/rubysketch/processing.rb', line 315

def draw (&block)
  @drawBlock__ = block if block
  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



785
786
787
788
789
# File 'lib/rubysketch/processing.rb', line 785

def ellipse (a, b, c, d)
  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



576
577
578
# File 'lib/rubysketch/processing.rb', line 576

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



639
640
641
642
# File 'lib/rubysketch/processing.rb', line 639

def fill (*args)
  @painter__.fill(*toRGBA__(*args))
  nil
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



102
103
104
# File 'lib/rubysketch/processing.rb', line 102

def floor (value)
  value.floor
end

#frameCountInteger

Returns number of frames since program started.

Returns:

  • (Integer)

    total number of frames



421
422
423
# File 'lib/rubysketch/processing.rb', line 421

def frameCount ()
  @frameCount__
end

#frameRateFloat

Returns number of frames per second.

Returns:

  • (Float)

    frames per second



429
430
431
# File 'lib/rubysketch/processing.rb', line 429

def frameRate ()
  @window__.event.fps
end

#heightObject



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

def height ()
  @window__.canvas.height
end

#image(img, x, y) ⇒ nil #image(img, x, y, w, h) ⇒ nil

Draws an image.

Parameters:

  • img (Image)

    image to draw

  • x (Numeric)

    horizontal position of the image

  • y (Numeric)

    vertical position of the image

  • w (Numeric) (defaults to: nil)

    width of the image

  • h (Numeric) (defaults to: nil)

    height of the image

Returns:

  • (nil)

    nil



897
898
899
900
901
902
# File 'lib/rubysketch/processing.rb', line 897

def image (img, x, y, w = nil, h = nil)
  w ||= img.width
  h ||= img.height
  @painter__.image img.internal, x, y, w, h
  nil
end

#key(&block) ⇒ Object



320
321
322
323
# File 'lib/rubysketch/processing.rb', line 320

def key (&block)
  @window__.key = block
  nil
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



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

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

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

Draws a line.

Parameters:

  • x1 (Numeric)

    horizontal position for first point

  • y1 (Numeric)

    vertical position for first point

  • x2 (Numeric)

    horizontal position for second point

  • y2 (Numeric)

    vertical position for second point

Returns:

  • (nil)

    nil



742
743
744
745
# File 'lib/rubysketch/processing.rb', line 742

def line (x1, y1, x2, y2)
  @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



1049
1050
1051
1052
# File 'lib/rubysketch/processing.rb', line 1049

def loadImage (filename, extension = nil)
  filename = getImage__ filename, extension if filename =~ %r|^https?://|
  Image.new Rays::Image.load filename
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



148
149
150
151
152
153
154
155
# File 'lib/rubysketch/processing.rb', line 148

def mag (*args)
  x, y, z = *args
  case args.size
    when 2 then sqrt x * x + y * y
    when 3 then 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



219
220
221
# File 'lib/rubysketch/processing.rb', line 219

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



253
254
255
# File 'lib/rubysketch/processing.rb', line 253

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



236
237
238
# File 'lib/rubysketch/processing.rb', line 236

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

#mouseDragged(&block) ⇒ Object



372
373
374
375
# File 'lib/rubysketch/processing.rb', line 372

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

#mouseMoved(&block) ⇒ Object



359
360
361
362
# File 'lib/rubysketch/processing.rb', line 359

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

#mousePressed(&block) ⇒ Object



333
334
335
336
# File 'lib/rubysketch/processing.rb', line 333

def mousePressed (&block)
  @mousePressedBlock__ = block if block
  @mousePressed__
end

#mouseReleased(&block) ⇒ Object



346
347
348
349
# File 'lib/rubysketch/processing.rb', line 346

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

#mouseXNumeric

Returns mouse x position

Returns:

  • (Numeric)

    horizontal position of mouse



445
446
447
# File 'lib/rubysketch/processing.rb', line 445

def mouseX ()
  @mouseX__
end

#mouseYNumeric

Returns mouse y position

Returns:

  • (Numeric)

    vertical position of mouse



453
454
455
# File 'lib/rubysketch/processing.rb', line 453

def mouseY ()
  @mouseY__
end

#noFillnil

Disables filling.

Returns:

  • (nil)

    nil



682
683
684
685
# File 'lib/rubysketch/processing.rb', line 682

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)



1038
1039
1040
# File 'lib/rubysketch/processing.rb', line 1038

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



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

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



691
692
693
694
# File 'lib/rubysketch/processing.rb', line 691

def noStroke ()
  @painter__.stroke nil
  nil
end

#pmouseXNumeric

Returns mouse x position in previous frame

Returns:

  • (Numeric)

    horizontal position of mouse



461
462
463
# File 'lib/rubysketch/processing.rb', line 461

def pmouseX ()
  @mousePrevX__
end

#pmouseYNumeric

Returns mouse y position in previous frame

Returns:

  • (Numeric)

    vertical position of mouse



469
470
471
# File 'lib/rubysketch/processing.rb', line 469

def pmouseY ()
  @mousePrevY__
end

#point(x, y) ⇒ nil

Draws a point.

Parameters:

  • x (Numeric)

    horizontal position

  • y (Numeric)

    vertical position

Returns:

  • (nil)

    nil



726
727
728
729
730
731
# File 'lib/rubysketch/processing.rb', line 726

def point (x, y)
  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



1021
1022
1023
1024
# File 'lib/rubysketch/processing.rb', line 1021

def pop ()
  popMatrix
  popStyle
end

#popMatrixnil

Pops the current transformation matrix from stack.

Returns:

  • (nil)

    nil



956
957
958
959
960
# File 'lib/rubysketch/processing.rb', line 956

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

#popStylenil

Restore style values from the style stack.

Returns:

  • (nil)

    nil



994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
# File 'lib/rubysketch/processing.rb', line 994

def popStyle ()
  raise "style stack underflow" if @styleStack__.empty?
  @painter__.fill,
  @painter__.stroke,
  @painter__.stroke_width,
  @painter__.font,
  @hsbColor__,
  @colorMaxes__,
  @angleScale__,
  @rectMode__,
  @ellipseMode__ = @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



123
124
125
# File 'lib/rubysketch/processing.rb', line 123

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

#pushnil

Save current styles and transformations to stack.

Returns:

  • (nil)

    nil



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

def push ()
  pushMatrix
  pushStyle
end

#pushMatrixnil

Pushes the current transformation matrix to stack.

Returns:

  • (nil)

    nil



947
948
949
950
# File 'lib/rubysketch/processing.rb', line 947

def pushMatrix ()
  @matrixStack__.push @painter__.matrix
  nil
end

#pushStylenil

Save current style values to the style stack.

Returns:

  • (nil)

    nil



975
976
977
978
979
980
981
982
983
984
985
986
987
988
# File 'lib/rubysketch/processing.rb', line 975

def pushStyle ()
  @styleStack__.push [
    @painter__.fill,
    @painter__.stroke,
    @painter__.stroke_width,
    @painter__.font,
    @hsbColor__,
    @colorMaxes__,
    @angleScale__,
    @rectMode__,
    @ellipseMode__
  ]
  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



863
864
865
866
# File 'lib/rubysketch/processing.rb', line 863

def quad (x1, y1, x2, y2, x3, y3, x4, y4)
  @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



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

def radians (degree)
  degree * DEG2RAD__
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



765
766
767
768
769
770
771
772
773
774
# File 'lib/rubysketch/processing.rb', line 765

def rect (a, b, c, d, *args)
  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



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

def rectMode (mode)
  @rectMode__ = mode
end

#resetMatrixnil

Reset current transformation matrix with identity matrix.

Returns:

  • (nil)

    nil



966
967
968
969
# File 'lib/rubysketch/processing.rb', line 966

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

#rotate(angle) ⇒ nil

Applies rotation matrix to current transformation matrix.

Parameters:

  • angle (Numeric)

    angle for rotation

Returns:

  • (nil)

    nil



938
939
940
941
# File 'lib/rubysketch/processing.rb', line 938

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

#round(value) ⇒ Numeric

Returns the closest integer number.

Parameters:

  • value (Numeric)

    number

Returns:

  • (Numeric)

    rounded number



112
113
114
# File 'lib/rubysketch/processing.rb', line 112

def round (value)
  value.round
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



927
928
929
930
# File 'lib/rubysketch/processing.rb', line 927

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

#setup(&block) ⇒ Object

Define setup block.



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

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

#sq(value) ⇒ Numeric

Returns squared value.

Parameters:

  • value (Numeric)

    number

Returns:

  • (Numeric)

    squared value



133
134
135
# File 'lib/rubysketch/processing.rb', line 133

def sq (value)
  value * value
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



830
831
832
# File 'lib/rubysketch/processing.rb', line 830

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



662
663
664
665
# File 'lib/rubysketch/processing.rb', line 662

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

#strokeWeight(weight) ⇒ nil

Sets stroke weight.

Parameters:

  • weight (Numeric)

    width of stroke

Returns:

  • (nil)

    nil



673
674
675
676
# File 'lib/rubysketch/processing.rb', line 673

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

#text(str) ⇒ nil #text(str, x, y) ⇒ nil

Draws a text.

Parameters:

  • str (String)

    text to draw

  • x (Numeric)

    horizontal position of the text

  • y (Numeric)

    vertical position of the text

Returns:

  • (nil)

    nil



879
880
881
882
# File 'lib/rubysketch/processing.rb', line 879

def text (str, x, y)
  @painter__.text str, x, y
  nil
end

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

Sets font.

Parameters:

  • name (String) (defaults to: nil)

    font name

  • size (Numeric) (defaults to: nil)

    font size

Returns:

  • (Font)

    current font



703
704
705
706
# File 'lib/rubysketch/processing.rb', line 703

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

#textSize(size) ⇒ nil

Sets text size.

Parameters:

  • size (Numeric)

    font size

Returns:

  • (nil)

    nil



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

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

#translate(x, y) ⇒ nil

Applies translation matrix to current transformation matrix.

Parameters:

  • x (Numeric)

    horizontal transformation

  • y (Numeric)

    vertical transformation

Returns:

  • (nil)

    nil



911
912
913
914
# File 'lib/rubysketch/processing.rb', line 911

def translate (x, y)
  @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



845
846
847
848
# File 'lib/rubysketch/processing.rb', line 845

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

#widthObject



401
402
403
# File 'lib/rubysketch/processing.rb', line 401

def width ()
  @window__.canvas.width
end

#windowHeightObject



413
414
415
# File 'lib/rubysketch/processing.rb', line 413

def windowHeight ()
  @window__.height
end

#windowWidthObject



409
410
411
# File 'lib/rubysketch/processing.rb', line 409

def windowWidth ()
  @window__.width
end