rubysketch 0.3.4 → 0.3.5

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: e9914f7b869e2dfeb80a8ba58a8c6678c0a995a974124b2b88974e477af3fdd8
4
- data.tar.gz: 2b7d45e918f60be716bc9edc8f5bfbb7ceb800954965af32163431e681709250
3
+ metadata.gz: 0df24de4fc3eabd1c7880d51ff34ef8389b44bef43a8159c75e9e6c651953c0d
4
+ data.tar.gz: cf03a57e9ecbf8a63f0b089c4588c0cd041ef93e2b92c69a580b8aa1f013659e
5
5
  SHA512:
6
- metadata.gz: 5f1192007cfb3a80c6335dd8a881358a9fa2b9dac8b6a0931836f295f2658ac0d4723b9a9d51800e6923ccfcc625f6fd92fd9444732339a338773681d6921299
7
- data.tar.gz: afefa27c322e08e0be3c1c6099b3ef3a3c86d0fadfc3140e4ec4c26c4686573d1a733ce0791f94241a4e73a67cda5998029fcfd4ebc6e7f3a1de6c8994ecdb0e
6
+ metadata.gz: 953e09a5b8da7f8798186e3f0a4e4b9ca636a5c7a34cdd1eca26da30f09221ac31fe3c5ed9ebc8e498060f84b88de4bb14738ef8054e30544c38ca664522f050
7
+ data.tar.gz: 4c4ae42689cfda821c84617c2925fc48b6af3ad3672d8dd1c603b999427762b5439cbf7c879a06fdf8830f83632d5e01bd9197d1cf528f6ae948a38728063a2a
@@ -1,6 +1,14 @@
1
1
  # RubySketch ChangeLog
2
2
 
3
3
 
4
+ ## [0.3.5] - 2020-08-02
5
+
6
+ - add random()
7
+ - add sin(), cos(), tan(), asin(), acos(), atan() and atan2()
8
+ - make Vector class accessible from user script context
9
+ - fix error on calling rotate()
10
+
11
+
4
12
  ## [0.3.4] - 2020-08-02
5
13
 
6
14
  - delete Utility module
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.4
1
+ 0.3.5
@@ -141,9 +141,9 @@ module RubySketch
141
141
  #
142
142
  def lerp (*args, amount)
143
143
  v = toVector__ *args
144
- self.x = x + (v.x - x) * amount
145
- self.y = y + (v.y - y) * amount
146
- self.z = z + (v.z - z) * amount
144
+ self.x = Context.lerp x, v.x, amount
145
+ self.y = Context.lerp y, v.y, amount
146
+ self.z = Context.lerp z, v.z, amount
147
147
  self
148
148
  end
149
149
 
@@ -732,6 +732,8 @@ module RubySketch
732
732
  #
733
733
  module GraphicsContext
734
734
 
735
+ Vector = Processing::Vector
736
+
735
737
  # PI / 2
736
738
  #
737
739
  HALF_PI = Math::PI / 2
@@ -930,7 +932,7 @@ module RubySketch
930
932
  end
931
933
 
932
934
  # @private
933
- protected def toAngle__ (angle)
935
+ def toAngle__ (angle)
934
936
  angle * @angleScale__
935
937
  end
936
938
 
@@ -1863,29 +1865,7 @@ module RubySketch
1863
1865
  @redraw__ = true
1864
1866
  end
1865
1867
 
1866
- #
1867
- # Utility functions
1868
- #
1869
-
1870
- # Converts degree to radian.
1871
- #
1872
- # @param degree [Numeric] degree to convert
1873
- #
1874
- # @return [Numeric] radian
1875
- #
1876
- def radians (degree)
1877
- degree * DEG2RAD__
1878
- end
1879
-
1880
- # Converts radian to degree.
1881
- #
1882
- # @param radian [Numeric] radian to convert
1883
- #
1884
- # @return [Numeric] degree
1885
- #
1886
- def degrees (radian)
1887
- radian * RAD2DEG__
1888
- end
1868
+ module_function
1889
1869
 
1890
1870
  # Returns the absolute number of the value.
1891
1871
  #
@@ -2080,6 +2060,97 @@ module RubySketch
2080
2060
  value < min ? min : (value > max ? max : value)
2081
2061
  end
2082
2062
 
2063
+ # Converts degree to radian.
2064
+ #
2065
+ # @param degree [Numeric] degree to convert
2066
+ #
2067
+ # @return [Numeric] radian
2068
+ #
2069
+ def radians (degree)
2070
+ degree * DEG2RAD__
2071
+ end
2072
+
2073
+ # Converts radian to degree.
2074
+ #
2075
+ # @param radian [Numeric] radian to convert
2076
+ #
2077
+ # @return [Numeric] degree
2078
+ #
2079
+ def degrees (radian)
2080
+ radian * RAD2DEG__
2081
+ end
2082
+
2083
+ # Returns the sine of an angle.
2084
+ #
2085
+ # @param angle [Numeric] angle in radians
2086
+ #
2087
+ # @return [Numeric] the sine
2088
+ #
2089
+ def sin (angle)
2090
+ Math.sin angle
2091
+ end
2092
+
2093
+ # Returns the cosine of an angle.
2094
+ #
2095
+ # @param angle [Numeric] angle in radians
2096
+ #
2097
+ # @return [Numeric] the cosine
2098
+ #
2099
+ def cos (angle)
2100
+ Math.cos angle
2101
+ end
2102
+
2103
+ # Returns the ratio of the sine and cosine of an angle.
2104
+ #
2105
+ # @param angle [Numeric] angle in radians
2106
+ #
2107
+ # @return [Numeric] the tangent
2108
+ #
2109
+ def tan (angle)
2110
+ Math.tan angle
2111
+ end
2112
+
2113
+ # Returns the inverse of sin().
2114
+ #
2115
+ # @param value [Numeric] value for calculation
2116
+ #
2117
+ # @return [Numeric] the arc sine
2118
+ #
2119
+ def asin (value)
2120
+ Math.asin value
2121
+ end
2122
+
2123
+ # Returns the inverse of cos().
2124
+ #
2125
+ # @param value [Numeric] value for calculation
2126
+ #
2127
+ # @return [Numeric] the arc cosine
2128
+ #
2129
+ def acos (value)
2130
+ Math.acos value
2131
+ end
2132
+
2133
+ # Returns the inverse of tan().
2134
+ #
2135
+ # @param value [Numeric] value for valculation
2136
+ #
2137
+ # @return [Numeric] the arc tangent
2138
+ #
2139
+ def atan (value)
2140
+ Math.atan value
2141
+ end
2142
+
2143
+ # Returns the angle from a specified point.
2144
+ #
2145
+ # @param y [Numeric] y of the point
2146
+ # @param x [Numeric] x of the point
2147
+ #
2148
+ # @return [Numeric] the angle in radians
2149
+ #
2150
+ def atan2 (y, x)
2151
+ Math.atan2 y, x
2152
+ end
2153
+
2083
2154
  # Returns the perlin noise value.
2084
2155
  #
2085
2156
  # @overload noise(x)
@@ -2096,6 +2167,20 @@ module RubySketch
2096
2167
  Rays.perlin(x, y, z) / 2.0 + 0.5
2097
2168
  end
2098
2169
 
2170
+ # Returns a random number in range low...high
2171
+ #
2172
+ # @overload random(high)
2173
+ # @overload random(low, high)
2174
+ #
2175
+ # @param low [Numeric] lower limit
2176
+ # @param high [Numeric] upper limit
2177
+ #
2178
+ # @return [Float] random number
2179
+ #
2180
+ def random (low = nil, high)
2181
+ rand (low || 0).to_f...high.to_f
2182
+ end
2183
+
2099
2184
  # Creates a new vector.
2100
2185
  #
2101
2186
  # @overload createVector()
@@ -0,0 +1,29 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ require_relative '../helper'
5
+
6
+
7
+ class TestProcessingUtility < Test::Unit::TestCase
8
+
9
+ C = RubySketch::Processing::Context
10
+
11
+ def setup ()
12
+
13
+ end
14
+
15
+ def test_random ()
16
+ assert_equal Float, C.random(1).class
17
+ assert_equal Float, C.random(1.0).class
18
+ assert_not_equal C.random(1), C.random(1)
19
+
20
+ 10000.times do
21
+ n = C.random 1
22
+ assert 0 <= n && n < 1
23
+
24
+ n = C.random 1, 2
25
+ assert 1.0 <= n && n < 2.0
26
+ end
27
+ end
28
+
29
+ end# TestProcessingUtility
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubysketch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - xordog
@@ -121,6 +121,7 @@ files:
121
121
  - lib/rubysketch/window.rb
122
122
  - rubysketch.gemspec
123
123
  - test/helper.rb
124
+ - test/processing/test_utility.rb
124
125
  - test/processing/test_vector.rb
125
126
  homepage: https://github.com/xord/rubysketch
126
127
  licenses: []
@@ -146,4 +147,5 @@ specification_version: 4
146
147
  summary: Processing like Creative Coding Framework.
147
148
  test_files:
148
149
  - test/helper.rb
150
+ - test/processing/test_utility.rb
149
151
  - test/processing/test_vector.rb