Class: RubySketch::Processing1
- Inherits:
-
Object
- Object
- RubySketch::Processing1
- Extended by:
- Starter
- Includes:
- Math
- Defined in:
- lib/rubysketch/processing.rb
Overview
Processing compatible API v1
Defined Under Namespace
Classes: Font
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
Instance Method Summary collapse
-
#abs(value) ⇒ Numeric
Returns the absolute number of the value.
-
#angleMode(mode) ⇒ nil
Sets angle mode.
-
#arc(x, y, w, h, start, stop) ⇒ nil
Draws an arc.
-
#background(*args) ⇒ nil
Clears screen.
-
#ceil(value) ⇒ Numeric
Returns the closest integer number greater than or equal to the value.
-
#circle(x, y, extent) ⇒ nil
Draws a circle.
-
#colorMode(mode, *maxes) ⇒ nil
Sets color mode and max color values.
-
#constrain(value, min, max) ⇒ Numeric
Constrains the number between min..max.
-
#degrees(radian) ⇒ Numeric
Converts radian to degree.
-
#displayDensity ⇒ Numeric
Returns pixel density.
-
#dist(*args) ⇒ Numeric
Returns distance between 2 points.
- #draw(&block) ⇒ Object
-
#ellipse(x, y, w, h = w) ⇒ nil
Draws a ellipse.
-
#fill(*args) ⇒ nil
Sets fill color.
-
#floor(value) ⇒ Numeric
Returns the closest integer number less than or equal to the value.
-
#frameCount ⇒ Integer
Returns number of frames since program started.
-
#frameRate ⇒ Float
Returns number of frames per second.
- #height ⇒ Object
- #key(&block) ⇒ Object
-
#lerp(start, stop, amount) ⇒ Numeric
Returns the interpolated number between range start..stop.
-
#line(x1, y1, x2, y2) ⇒ nil
Draws a line.
-
#mag(*args) ⇒ Numeric
Returns the magnitude (or length) of a vector.
-
#map(value, start1, stop1, start2, stop2) ⇒ Numeric
Maps a number from range start1..stop1 to range start2..stop2.
-
#max(*args) ⇒ Numeric
Returns maximum value.
-
#min(*args) ⇒ Numeric
Returns minimum value.
- #mouseDragged(&block) ⇒ Object
- #mouseMoved(&block) ⇒ Object
- #mousePressed(&block) ⇒ Object
- #mouseReleased(&block) ⇒ Object
-
#mouseX ⇒ Numeric
Returns mouse x position.
-
#mouseY ⇒ Numeric
Returns mouse y position.
-
#noFill ⇒ nil
Disables filling.
-
#noise(x, y = 0) ⇒ Numeric
Returns the perlin noise value.
-
#norm(value, start, stop) ⇒ Numeric
Normalize the value from range start..stop into 0..1.
-
#noStroke ⇒ nil
Disables drawing stroke.
-
#pmouseX ⇒ Numeric
Returns mouse x position in previous frame.
-
#pmouseY ⇒ Numeric
Returns mouse y position in previous frame.
-
#point(x, y) ⇒ nil
Draws a point.
-
#popMatrix ⇒ nil
Pops the current transformation matrix from stack.
-
#pow(value, exponent) ⇒ Numeric
Returns value raised to the power of exponent.
-
#pushMatrix ⇒ nil
Pushes the current transformation matrix to stack.
-
#radians(degree) ⇒ Numeric
Converts degree to radian.
-
#rect(x, y, w, h, *args) ⇒ nil
Draws a rectangle.
-
#resetMatrix ⇒ nil
Reset current transformation matrix with identity matrix.
-
#rotate(angle) ⇒ nil
Applies rotation matrix to current transformation matrix.
-
#round(value) ⇒ Numeric
Returns the closest integer number.
-
#scale(x, y) ⇒ nil
Applies scale matrix to current transformation matrix.
- #setup(&block) ⇒ Object
-
#sq(value) ⇒ Numeric
Returns squared value.
-
#stroke(*args) ⇒ nil
Sets stroke color.
-
#strokeWeight(weight) ⇒ nil
Sets stroke weight.
-
#text(str, x = 0, y = 0) ⇒ nil
Draws a text.
-
#textFont(name = nil, size = nil) ⇒ Font
Sets font.
-
#textSize(size) ⇒ nil
Sets text size.
-
#translate(x, y) ⇒ nil
Applies translation matrix to current transformation matrix.
- #width ⇒ Object
- #windowHeight ⇒ Object
- #windowWidth ⇒ Object
Methods included from Starter
Instance Method Details
#abs(value) ⇒ Numeric
Returns the absolute number of the value.
73 74 75 |
# File 'lib/rubysketch/processing.rb', line 73 def abs (value) value.abs end |
#angleMode(mode) ⇒ nil
Sets angle mode.
516 517 518 519 520 521 522 |
# File 'lib/rubysketch/processing.rb', line 516 def angleMode (mode) @angleScale__ = case mode when RADIANS then RAD2DEG__ when DEGREES then 1.0 else raise ArgumentError, "Invalid angle mode: #{mode}" end end |
#arc(x, y, w, h, start, stop) ⇒ nil
Draws an arc.
729 730 731 732 733 734 |
# File 'lib/rubysketch/processing.rb', line 729 def arc (x, y, w, h, start, stop) start = to_angle__ start stop = to_angle__ stop @painter__.ellipse x - w / 2, y - h / 2, 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.
547 548 549 550 |
# File 'lib/rubysketch/processing.rb', line 547 def background (*args) @painter__.background(*to_rgba__(*args)) nil end |
#ceil(value) ⇒ Numeric
Returns the closest integer number greater than or equal to the value.
83 84 85 |
# File 'lib/rubysketch/processing.rb', line 83 def ceil (value) value.ceil end |
#circle(x, y, extent) ⇒ nil
Draws a circle.
714 715 716 |
# File 'lib/rubysketch/processing.rb', line 714 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.
469 470 471 472 473 474 475 476 477 478 479 |
# File 'lib/rubysketch/processing.rb', line 469 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.
256 257 258 |
# File 'lib/rubysketch/processing.rb', line 256 def constrain (value, min, max) value < min ? min : (value > max ? max : value) end |
#degrees(radian) ⇒ Numeric
Converts radian to degree.
276 277 278 |
# File 'lib/rubysketch/processing.rb', line 276 def degrees (radian) radian * RAD2DEG__ end |
#displayDensity ⇒ Numeric
Returns pixel density
417 418 419 |
# File 'lib/rubysketch/processing.rb', line 417 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.
162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/rubysketch/processing.rb', line 162 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
295 296 297 298 |
# File 'lib/rubysketch/processing.rb', line 295 def draw (&block) @drawBlock__ = block if block nil end |
#ellipse(x, y, w, h = w) ⇒ nil
Draws a ellipse.
701 702 703 704 |
# File 'lib/rubysketch/processing.rb', line 701 def ellipse (x, y, w, h = w) @painter__.ellipse (x - w / 2.0), (y - h / 2.0), w, h nil 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.
570 571 572 573 |
# File 'lib/rubysketch/processing.rb', line 570 def fill (*args) @painter__.fill(*to_rgba__(*args)) nil end |
#floor(value) ⇒ Numeric
Returns the closest integer number less than or equal to the value.
93 94 95 |
# File 'lib/rubysketch/processing.rb', line 93 def floor (value) value.floor end |
#frameCount ⇒ Integer
Returns number of frames since program started.
401 402 403 |
# File 'lib/rubysketch/processing.rb', line 401 def frameCount () @frameCount__ end |
#frameRate ⇒ Float
Returns number of frames per second.
409 410 411 |
# File 'lib/rubysketch/processing.rb', line 409 def frameRate () @window__.event.fps end |
#height ⇒ Object
385 386 387 |
# File 'lib/rubysketch/processing.rb', line 385 def height () @window__.canvas.height end |
#key(&block) ⇒ Object
300 301 302 303 |
# File 'lib/rubysketch/processing.rb', line 300 def key (&block) @window__.key = block nil end |
#lerp(start, stop, amount) ⇒ Numeric
Returns the interpolated number between range start..stop.
196 197 198 |
# File 'lib/rubysketch/processing.rb', line 196 def lerp (start, stop, amount) start + (stop - start) * amount end |
#line(x1, y1, x2, y2) ⇒ nil
Draws a line.
659 660 661 662 |
# File 'lib/rubysketch/processing.rb', line 659 def line (x1, y1, x2, y2) @painter__.line x1, y1, x2, y2 nil end |
#mag(x, y) ⇒ Numeric #mag(x, y, z) ⇒ Numeric
Returns the magnitude (or length) of a vector.
139 140 141 142 143 144 145 146 |
# File 'lib/rubysketch/processing.rb', line 139 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.
210 211 212 |
# File 'lib/rubysketch/processing.rb', line 210 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.
244 245 246 |
# File 'lib/rubysketch/processing.rb', line 244 def max (*args) args.flatten.max end |
#min(a, b) ⇒ Numeric #min(a, b, c) ⇒ Numeric #min(array) ⇒ Numeric
Returns minimum value.
227 228 229 |
# File 'lib/rubysketch/processing.rb', line 227 def min (*args) args.flatten.min end |
#mouseDragged(&block) ⇒ Object
352 353 354 355 |
# File 'lib/rubysketch/processing.rb', line 352 def mouseDragged (&block) @mouseDraggedBlock__ = block if block nil end |
#mouseMoved(&block) ⇒ Object
339 340 341 342 |
# File 'lib/rubysketch/processing.rb', line 339 def mouseMoved (&block) @mouseMovedBlock__ = block if block nil end |
#mousePressed(&block) ⇒ Object
313 314 315 316 |
# File 'lib/rubysketch/processing.rb', line 313 def mousePressed (&block) @mousePressedBlock__ = block if block @mousePressed__ end |
#mouseReleased(&block) ⇒ Object
326 327 328 329 |
# File 'lib/rubysketch/processing.rb', line 326 def mouseReleased (&block) @mouseReleasedBlock__ = block if block nil end |
#mouseX ⇒ Numeric
Returns mouse x position
425 426 427 |
# File 'lib/rubysketch/processing.rb', line 425 def mouseX () @mouseX__ end |
#mouseY ⇒ Numeric
Returns mouse y position
433 434 435 |
# File 'lib/rubysketch/processing.rb', line 433 def mouseY () @mouseY__ end |
#noFill ⇒ nil
Disables filling.
613 614 615 616 |
# File 'lib/rubysketch/processing.rb', line 613 def noFill () @painter__.fill nil nil end |
#noise(x) ⇒ Numeric #noise(x, y) ⇒ Numeric
Returns the perlin noise value.
840 841 842 |
# File 'lib/rubysketch/processing.rb', line 840 def noise (x, y = 0) Rays.perlin(x, y) / 2.0 + 1.0 end |
#norm(value, start, stop) ⇒ Numeric
Normalize the value from range start..stop into 0..1.
184 185 186 |
# File 'lib/rubysketch/processing.rb', line 184 def norm (value, start, stop) (value.to_f - start.to_f) / (stop.to_f - start.to_f) end |
#noStroke ⇒ nil
Disables drawing stroke.
622 623 624 625 |
# File 'lib/rubysketch/processing.rb', line 622 def noStroke () @painter__.stroke nil nil end |
#pmouseX ⇒ Numeric
Returns mouse x position in previous frame
441 442 443 |
# File 'lib/rubysketch/processing.rb', line 441 def pmouseX () @mousePrevX__ end |
#pmouseY ⇒ Numeric
Returns mouse y position in previous frame
449 450 451 |
# File 'lib/rubysketch/processing.rb', line 449 def pmouseY () @mousePrevY__ end |
#point(x, y) ⇒ nil
Draws a point.
743 744 745 746 |
# File 'lib/rubysketch/processing.rb', line 743 def point (x, y) @painter__.rect x - 0.5, y - 0.5, 1, 1 nil end |
#popMatrix ⇒ nil
Pops the current transformation matrix from stack.
816 817 818 819 |
# File 'lib/rubysketch/processing.rb', line 816 def popMatrix () @painter__.pop_matrix nil end |
#pow(value, exponent) ⇒ Numeric
Returns value raised to the power of exponent.
114 115 116 |
# File 'lib/rubysketch/processing.rb', line 114 def pow (value, exponent) value ** exponent end |
#pushMatrix ⇒ nil
Pushes the current transformation matrix to stack.
807 808 809 810 |
# File 'lib/rubysketch/processing.rb', line 807 def pushMatrix () @painter__.push_matrix nil end |
#radians(degree) ⇒ Numeric
Converts degree to radian.
266 267 268 |
# File 'lib/rubysketch/processing.rb', line 266 def radians (degree) degree * DEG2RAD__ end |
#rect(x, y, w, h) ⇒ nil #rect(x, y, w, h, r) ⇒ nil #rect(x, y, w, h, tl, tr, br, bl) ⇒ nil
Draws a rectangle.
682 683 684 685 686 687 688 689 690 |
# File 'lib/rubysketch/processing.rb', line 682 def rect (x, y, w, h, *args) 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 |
#resetMatrix ⇒ nil
Reset current transformation matrix with identity matrix.
825 826 827 828 |
# File 'lib/rubysketch/processing.rb', line 825 def resetMatrix () @painter__.matrix = 1 nil end |
#rotate(angle) ⇒ nil
Applies rotation matrix to current transformation matrix.
798 799 800 801 |
# File 'lib/rubysketch/processing.rb', line 798 def rotate (angle) @painter__.rotate to_angle__ angle nil end |
#round(value) ⇒ Numeric
Returns the closest integer number.
103 104 105 |
# File 'lib/rubysketch/processing.rb', line 103 def round (value) value.round end |
#scale(s) ⇒ nil #scale(x, y) ⇒ nil
Applies scale matrix to current transformation matrix.
787 788 789 790 |
# File 'lib/rubysketch/processing.rb', line 787 def scale (x, y) @painter__.scale x, y nil end |
#setup(&block) ⇒ Object
280 281 282 283 |
# File 'lib/rubysketch/processing.rb', line 280 def setup (&block) @window__.setup = block nil end |
#sq(value) ⇒ Numeric
Returns squared value.
124 125 126 |
# File 'lib/rubysketch/processing.rb', line 124 def sq (value) value * value 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.
593 594 595 596 |
# File 'lib/rubysketch/processing.rb', line 593 def stroke (*args) @painter__.stroke(*to_rgba__(*args)) nil end |
#strokeWeight(weight) ⇒ nil
Sets stroke weight.
604 605 606 607 |
# File 'lib/rubysketch/processing.rb', line 604 def strokeWeight (weight) @painter__.stroke_width weight nil end |
#text(str) ⇒ nil #text(str, x, y) ⇒ nil
Draws a text.
759 760 761 762 |
# File 'lib/rubysketch/processing.rb', line 759 def text (str, x = 0, y = 0) @painter__.text str, x, y nil end |
#textFont(name = nil, size = nil) ⇒ Font
Sets font.
634 635 636 637 |
# File 'lib/rubysketch/processing.rb', line 634 def textFont (name = nil, size = nil) @painter__.font name, size if name || size Font.new @painter__.font end |
#textSize(size) ⇒ nil
Sets text size.
645 646 647 648 |
# File 'lib/rubysketch/processing.rb', line 645 def textSize (size) @painter__.font @painter__.font.name, size nil end |
#translate(x, y) ⇒ nil
Applies translation matrix to current transformation matrix.
771 772 773 774 |
# File 'lib/rubysketch/processing.rb', line 771 def translate (x, y) @painter__.translate x, y nil end |
#width ⇒ Object
381 382 383 |
# File 'lib/rubysketch/processing.rb', line 381 def width () @window__.canvas.width end |
#windowHeight ⇒ Object
393 394 395 |
# File 'lib/rubysketch/processing.rb', line 393 def windowHeight () @window__.height end |
#windowWidth ⇒ Object
389 390 391 |
# File 'lib/rubysketch/processing.rb', line 389 def windowWidth () @window__.width end |