rubysketch 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8c2d5e6b27dba3d165c946db3fc7cbe09630be01a5dd86238433e6e3b7126138
4
- data.tar.gz: b0565c883e6821f133d64428507fc7d39eaf06f5a11fb634a1a205b25856d77b
3
+ metadata.gz: 7b5455321365a6f09ff9b1b2fc60610475a1d5393a41b276d433e1030503a1dc
4
+ data.tar.gz: 159b3ec3b99acf5d95e0d833ccbddc8df382ae7b09c77e1b6e4058ef16d29b9f
5
5
  SHA512:
6
- metadata.gz: 63553c43e5fd2433e7b395aae2b57415b9cc7091a8cbe07934fddede1569383161e73822f6614daa479dde3ef1606d33c545b067ceefbd66ce0c7133149f0ac1
7
- data.tar.gz: be2980a7909244174e52f619ec1e80a77a85483501837e59a5ddea84652792b3718402d1ca9a1201058847770dca9a34e315fbdf58ec2033794bd6438100a12e
6
+ metadata.gz: e85a61ae56932d886029b57ab86085c8db14fa817527da37983822a0d37469352f53b53cdbe103fe3c92de31f6424b0ba44c5eee29605976a0756dea89307fea
7
+ data.tar.gz: 1d6d641becbe81d1a692f2a0fcf016c1f15ac743699e97d0e3bb9f1e0078f6883f3613b0aafb027fba922ceacfee718e768739a7e9a1ecb1aaca38a5141b22a6
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -0,0 +1,13 @@
1
+ %w[xot rays reflex rubysketch]
2
+ .map {|s| File.expand_path "../../#{s}/lib", __dir__}
3
+ .each {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}
4
+
5
+ require 'rubysketch-processing'
6
+
7
+
8
+ icon = loadImage 'rubysketch.png'
9
+
10
+ draw do
11
+ background 0, 10
12
+ image icon, mouseX, mouseY, icon.width / 10, icon.height / 10
13
+ end
Binary file
@@ -294,7 +294,7 @@ module RubySketch
294
294
  end
295
295
 
296
296
  # @private
297
- def setupDrawBlock__ ()
297
+ private def setupDrawBlock__ ()
298
298
  @window__.draw = proc do |e, painter|
299
299
  @painter__ = painter
300
300
  @matrixStack__.clear
@@ -323,7 +323,7 @@ module RubySketch
323
323
  end
324
324
 
325
325
  # @private
326
- def setupMousePressedBlock__ ()
326
+ private def setupMousePressedBlock__ ()
327
327
  @window__.pointer_down = proc do |e|
328
328
  updateMouseState__ e.x, e.y, true
329
329
  @mousePressedBlock__.call e if @mousePressedBlock__
@@ -336,7 +336,7 @@ module RubySketch
336
336
  end
337
337
 
338
338
  # @private
339
- def setupMouseReleasedBlock__ ()
339
+ private def setupMouseReleasedBlock__ ()
340
340
  @window__.pointer_up = proc do |e|
341
341
  updateMouseState__ e.x, e.y, false
342
342
  @mouseReleasedBlock__.call e if @mouseReleasedBlock__
@@ -349,7 +349,7 @@ module RubySketch
349
349
  end
350
350
 
351
351
  # @private
352
- def setupMouseMovedBlock__ ()
352
+ private def setupMouseMovedBlock__ ()
353
353
  @window__.pointer_move = proc do |e|
354
354
  updateMouseState__ e.x, e.y
355
355
  @mouseMovedBlock__.call e if @mouseMovedBlock__
@@ -362,7 +362,7 @@ module RubySketch
362
362
  end
363
363
 
364
364
  # @private
365
- def setupMouseDraggedBlock__ ()
365
+ private def setupMouseDraggedBlock__ ()
366
366
  @window__.pointer_drag = proc do |e|
367
367
  updateMouseState__ e.x, e.y
368
368
  @mouseDraggedBlock__.call e if @mouseDraggedBlock__
@@ -375,20 +375,20 @@ module RubySketch
375
375
  end
376
376
 
377
377
  # @private
378
- def updateMouseState__ (x, y, pressed = nil)
378
+ private def updateMouseState__ (x, y, pressed = nil)
379
379
  @mouseX__ = x
380
380
  @mouseY__ = y
381
381
  @mousePressed__ = pressed if pressed != nil
382
382
  end
383
383
 
384
384
  # @private
385
- def updateMousePrevPos__ ()
385
+ private def updateMousePrevPos__ ()
386
386
  @mousePrevX__ = @mouseX__
387
387
  @mousePrevY__ = @mouseY__
388
388
  end
389
389
 
390
390
  # @private
391
- def size__ (width, height)
391
+ private def size__ (width, height)
392
392
  raise 'size() must be called on startup or setup block' if @started__
393
393
 
394
394
  @painter__.send :end_paint
@@ -499,7 +499,7 @@ module RubySketch
499
499
  end
500
500
 
501
501
  # @private
502
- def to_rgba__ (*args)
502
+ private def to_rgba__ (*args)
503
503
  a, b, c, d = args
504
504
  return parse_color__(a, b || alphaMax__) if a.kind_of?(String)
505
505
 
@@ -514,7 +514,7 @@ module RubySketch
514
514
  end
515
515
 
516
516
  # @private
517
- def parse_color__ (str, alpha)
517
+ private def parse_color__ (str, alpha)
518
518
  result = str.match /^\s*##{'([0-9a-f]{2})' * 3}\s*$/i
519
519
  raise ArgumentError, "Invalid color code: '#{str}'" unless result
520
520
 
@@ -523,7 +523,7 @@ module RubySketch
523
523
  end
524
524
 
525
525
  # @private
526
- def alphaMax__ ()
526
+ private def alphaMax__ ()
527
527
  @colorMaxes__[3]
528
528
  end
529
529
 
@@ -543,7 +543,7 @@ module RubySketch
543
543
  end
544
544
 
545
545
  # @private
546
- def to_angle__ (angle)
546
+ private def to_angle__ (angle)
547
547
  angle * @angleScale__
548
548
  end
549
549
 
@@ -578,7 +578,7 @@ module RubySketch
578
578
  end
579
579
 
580
580
  # @private
581
- def to_xywh__ (mode, a, b, c, d)
581
+ private def to_xywh__ (mode, a, b, c, d)
582
582
  case mode
583
583
  when CORNER then [a, b, c, d]
584
584
  when CORNERS then [a, b, c - a, d - b]
@@ -881,6 +881,26 @@ module RubySketch
881
881
  nil
882
882
  end
883
883
 
884
+ # Draws an image.
885
+ #
886
+ # @overload image(img, x, y)
887
+ # @overload image(img, x, y, w, h)
888
+ #
889
+ # @param img [Image] image to draw
890
+ # @param x [Numeric] horizontal position of the image
891
+ # @param y [Numeric] vertical position of the image
892
+ # @param w [Numeric] width of the image
893
+ # @param h [Numeric] height of the image
894
+ #
895
+ # @return [nil] nil
896
+ #
897
+ def image (img, x, y, w = nil, h = nil)
898
+ w ||= img.width
899
+ h ||= img.height
900
+ @painter__.image img.internal, x, y, w, h
901
+ nil
902
+ end
903
+
884
904
  # Applies translation matrix to current transformation matrix.
885
905
  #
886
906
  # @param x [Numeric] horizontal transformation
@@ -1017,9 +1037,59 @@ module RubySketch
1017
1037
  Rays.perlin(x, y) / 2.0 + 1.0
1018
1038
  end
1019
1039
 
1040
+ # Loads image.
1041
+ #
1042
+ # @param filename [String] file name to load image
1043
+ #
1044
+ def loadImage (filename)
1045
+ Image.new Rays::Image.load filename
1046
+ end
1047
+
1020
1048
  end# Processing
1021
1049
 
1022
1050
 
1051
+ # Image object.
1052
+ #
1053
+ class Processing::Image
1054
+
1055
+ # Initialize image.
1056
+ #
1057
+ def initialize (image)
1058
+ @image = image
1059
+ end
1060
+
1061
+ # Gets width of image.
1062
+ #
1063
+ # @return [Numeric] width of image
1064
+ #
1065
+ def width ()
1066
+ @image.width
1067
+ end
1068
+
1069
+ # Gets height of image.
1070
+ #
1071
+ # @return [Numeric] height of image
1072
+ #
1073
+ def height ()
1074
+ @image.height
1075
+ end
1076
+
1077
+ # Saves image to file.
1078
+ #
1079
+ # @param filename [String] file name to save image
1080
+ #
1081
+ def save (filename)
1082
+ @image.save filename
1083
+ end
1084
+
1085
+ # @private
1086
+ def internal ()
1087
+ @image
1088
+ end
1089
+
1090
+ end# Processing::Image
1091
+
1092
+
1023
1093
  # Font object.
1024
1094
  #
1025
1095
  class Processing::Font
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubysketch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - xordog
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-05 00:00:00.000000000 Z
11
+ date: 2020-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yard
@@ -110,6 +110,8 @@ files:
110
110
  - examples/clock.rb
111
111
  - examples/glsl.rb
112
112
  - examples/hello.rb
113
+ - examples/image.rb
114
+ - examples/rubysketch.png
113
115
  - examples/shapes.rb
114
116
  - lib/rubysketch-processing.rb
115
117
  - lib/rubysketch.rb