rubysketch 0.2.1 → 0.2.2

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: 7b5455321365a6f09ff9b1b2fc60610475a1d5393a41b276d433e1030503a1dc
4
- data.tar.gz: 159b3ec3b99acf5d95e0d833ccbddc8df382ae7b09c77e1b6e4058ef16d29b9f
3
+ metadata.gz: cb7fa5f9cc69b67a9339f9f7170c8901999d0007e6b6e74de7d7b55b36bc09d3
4
+ data.tar.gz: c5158bda3a8ac90ec2255c3bfda5f8c3dbb8e9815bd74b9d5df0f8bfa601024e
5
5
  SHA512:
6
- metadata.gz: e85a61ae56932d886029b57ab86085c8db14fa817527da37983822a0d37469352f53b53cdbe103fe3c92de31f6424b0ba44c5eee29605976a0756dea89307fea
7
- data.tar.gz: 1d6d641becbe81d1a692f2a0fcf016c1f15ac743699e97d0e3bb9f1e0078f6883f3613b0aafb027fba922ceacfee718e768739a7e9a1ecb1aaca38a5141b22a6
6
+ metadata.gz: b691e41b1e7ba08ad1a732f81333febe97cc68e30244ad7f8aea76b7660b7af5b47ae60542610f797340cc25bf9bc6f673dc893a19dd27e0b83583a19a8c99d8
7
+ data.tar.gz: 969de4e7e4f840c590c0758af55a53bb28838b05cf63a84d9c389bd99b5493df23cb06a5020f25c8531a906d67be4da014b5e888929e4734c83f18d6f47a87e0
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.2.2
@@ -5,7 +5,7 @@
5
5
  require 'rubysketch-processing'
6
6
 
7
7
 
8
- icon = loadImage 'rubysketch.png'
8
+ icon = loadImage 'https://xord.org/rubysketch/rubysketch.png'
9
9
 
10
10
  draw do
11
11
  background 0, 10
@@ -1,3 +1,8 @@
1
+ require 'digest/sha1'
2
+ require 'pathname'
3
+ require 'tmpdir'
4
+ require 'open-uri'
5
+
1
6
  require 'reflex'
2
7
  require 'rubysketch/module'
3
8
  require 'rubysketch/starter'
@@ -487,7 +487,7 @@ module RubySketch
487
487
  # @return [nil] nil
488
488
  #
489
489
  def colorMode (mode, *maxes)
490
- raise ArgumentError, "Invalid color mode: #{mode}" unless [RGB, HSB].include?(mode)
490
+ raise ArgumentError, "invalid color mode: #{mode}" unless [RGB, HSB].include?(mode)
491
491
  raise ArgumentError unless [0, 1, 3, 4].include?(maxes.size)
492
492
 
493
493
  @hsbColor__ = mode.upcase == HSB
@@ -499,9 +499,9 @@ module RubySketch
499
499
  end
500
500
 
501
501
  # @private
502
- private def to_rgba__ (*args)
502
+ private def toRGBA__ (*args)
503
503
  a, b, c, d = args
504
- return parse_color__(a, b || alphaMax__) if a.kind_of?(String)
504
+ return parseColor__(a, b || alphaMax__) if a.kind_of?(String)
505
505
 
506
506
  rgba = case args.size
507
507
  when 1, 2 then [a, a, a, b || alphaMax__]
@@ -514,9 +514,9 @@ module RubySketch
514
514
  end
515
515
 
516
516
  # @private
517
- private def parse_color__ (str, alpha)
517
+ private def parseColor__ (str, alpha)
518
518
  result = str.match /^\s*##{'([0-9a-f]{2})' * 3}\s*$/i
519
- raise ArgumentError, "Invalid color code: '#{str}'" unless result
519
+ raise ArgumentError, "invalid color code: '#{str}'" unless result
520
520
 
521
521
  rgb = result[1..3].map.with_index {|hex, i| hex.to_i(16) / 255.0}
522
522
  return *rgb, (alpha / alphaMax__)
@@ -537,13 +537,13 @@ module RubySketch
537
537
  @angleScale__ = case mode
538
538
  when RADIANS then RAD2DEG__
539
539
  when DEGREES then 1.0
540
- else raise ArgumentError, "Invalid angle mode: #{mode}"
540
+ else raise ArgumentError, "invalid angle mode: #{mode}"
541
541
  end
542
542
  nil
543
543
  end
544
544
 
545
545
  # @private
546
- private def to_angle__ (angle)
546
+ private def toAngle__ (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
- private def to_xywh__ (mode, a, b, c, d)
581
+ private def toXYWH__ (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]
@@ -607,7 +607,7 @@ module RubySketch
607
607
  # @return [nil] nil
608
608
  #
609
609
  def background (*args)
610
- rgba = to_rgba__ *args
610
+ rgba = toRGBA__ *args
611
611
  if rgba[3] == 1
612
612
  @painter__.background *rgba
613
613
  else
@@ -637,7 +637,7 @@ module RubySketch
637
637
  # @return [nil] nil
638
638
  #
639
639
  def fill (*args)
640
- @painter__.fill(*to_rgba__(*args))
640
+ @painter__.fill(*toRGBA__(*args))
641
641
  nil
642
642
  end
643
643
 
@@ -660,7 +660,7 @@ module RubySketch
660
660
  # @return [nil] nil
661
661
  #
662
662
  def stroke (*args)
663
- @painter__.stroke(*to_rgba__(*args))
663
+ @painter__.stroke(*toRGBA__(*args))
664
664
  nil
665
665
  end
666
666
 
@@ -763,7 +763,7 @@ module RubySketch
763
763
  # @return [nil] nil
764
764
  #
765
765
  def rect (a, b, c, d, *args)
766
- x, y, w, h = to_xywh__ @rectMode__, a, b, c, d
766
+ x, y, w, h = toXYWH__ @rectMode__, a, b, c, d
767
767
  case args.size
768
768
  when 0 then @painter__.rect x, y, w, h
769
769
  when 1 then @painter__.rect x, y, w, h, round: args[0]
@@ -783,7 +783,7 @@ module RubySketch
783
783
  # @return [nil] nil
784
784
  #
785
785
  def ellipse (a, b, c, d)
786
- x, y, w, h = to_xywh__ @ellipseMode__, a, b, c, d
786
+ x, y, w, h = toXYWH__ @ellipseMode__, a, b, c, d
787
787
  @painter__.ellipse x, y, w, h
788
788
  nil
789
789
  end
@@ -812,9 +812,9 @@ module RubySketch
812
812
  # @return [nil] nil
813
813
  #
814
814
  def arc (a, b, c, d, start, stop)
815
- x, y, w, h = to_xywh__ @ellipseMode__, a, b, c, d
816
- start = to_angle__ start
817
- stop = to_angle__ stop
815
+ x, y, w, h = toXYWH__ @ellipseMode__, a, b, c, d
816
+ start = toAngle__ start
817
+ stop = toAngle__ stop
818
818
  @painter__.ellipse x, y, w, h, from: start, to: stop
819
819
  nil
820
820
  end
@@ -936,7 +936,7 @@ module RubySketch
936
936
  # @return [nil] nil
937
937
  #
938
938
  def rotate (angle)
939
- @painter__.rotate to_angle__ angle
939
+ @painter__.rotate toAngle__ angle
940
940
  nil
941
941
  end
942
942
 
@@ -954,7 +954,7 @@ module RubySketch
954
954
  # @return [nil] nil
955
955
  #
956
956
  def popMatrix ()
957
- raise "Matrix stack underflow" if @matrixStack__.empty?
957
+ raise "matrix stack underflow" if @matrixStack__.empty?
958
958
  @painter__.matrix = @matrixStack__.pop
959
959
  nil
960
960
  end
@@ -992,7 +992,7 @@ module RubySketch
992
992
  # @return [nil] nil
993
993
  #
994
994
  def popStyle ()
995
- raise "Style stack underflow" if @styleStack__.empty?
995
+ raise "style stack underflow" if @styleStack__.empty?
996
996
  @painter__.fill,
997
997
  @painter__.stroke,
998
998
  @painter__.stroke_width,
@@ -1039,12 +1039,34 @@ module RubySketch
1039
1039
 
1040
1040
  # Loads image.
1041
1041
  #
1042
- # @param filename [String] file name to load image
1042
+ # @param filename [String] file name to load image
1043
+ # @param extension [String] type of image to load (ex. 'png')
1043
1044
  #
1044
- def loadImage (filename)
1045
+ def loadImage (filename, extension = nil)
1046
+ filename = getImage__ filename, extension if filename =~ %r|^https?://|
1045
1047
  Image.new Rays::Image.load filename
1046
1048
  end
1047
1049
 
1050
+ # @private
1051
+ private def getImage__ (uri, ext)
1052
+ ext ||= File.extname uri
1053
+ raise "unsupported image type" unless ext =~ /^\.?(png)$/i
1054
+
1055
+ tmpdir = Pathname(Dir.tmpdir) + Digest::SHA1.hexdigest(self.class.name)
1056
+ path = tmpdir + Digest::SHA1.hexdigest(uri)
1057
+ path = path.sub_ext ext
1058
+
1059
+ URI.open uri do |input|
1060
+ tmpdir.mkdir unless tmpdir.directory?
1061
+ path.open('w') do |output|
1062
+ while buf = input.read(2 ** 16)
1063
+ output.write buf
1064
+ end
1065
+ end
1066
+ end
1067
+ path.to_s
1068
+ end
1069
+
1048
1070
  end# Processing
1049
1071
 
1050
1072
 
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.1
4
+ version: 0.2.2
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-26 00:00:00.000000000 Z
11
+ date: 2020-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yard
@@ -111,7 +111,6 @@ files:
111
111
  - examples/glsl.rb
112
112
  - examples/hello.rb
113
113
  - examples/image.rb
114
- - examples/rubysketch.png
115
114
  - examples/shapes.rb
116
115
  - lib/rubysketch-processing.rb
117
116
  - lib/rubysketch.rb
Binary file