particlefx2d 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cb24e46327d94431dae7018d29abc79159b71fbae358cccd270dc4aa2a16db7d
4
- data.tar.gz: 7286c7ce9812eb236765129b30c5755876917ceb0fd456d0a108cec8f9a164d3
3
+ metadata.gz: 1a4c412bb853340b776b082712a935a838b2625da52865bb3a057d2f1c143f70
4
+ data.tar.gz: dc8ee5d7b28a1ecc8604edfde8a5669b2beb717bd06be3cece36f197f11f51ba
5
5
  SHA512:
6
- metadata.gz: 52260a8afa4d7fead08320e9726dc3d33a032a4e9af8d70e6ba9936388e0296048479f1053eb924d874f4aaf038d1a85f5d40e19e4115a7750677e0d847ef039
7
- data.tar.gz: cd55c2e8c789b9a026c5fae7408ecf2b95b0ed07e7048a34d7602b2b9d290eafd411f32854d1dcc48ff3abe63b70c2a48e6984bca61f773723ce0556cbc80dcd
6
+ metadata.gz: f7ff0578c86b82b90f4542913c147b4b5c6a639aaf995083a1d7364b9ab164786901781a7cb12325821971cdc46d6cfdb0a09cbef558f00d56d7dad0c62561ae
7
+ data.tar.gz: 757f4ed5a8be932bdcddd2a3b4e2bfc7611f43d4d7505f08237d7e2dc8bd02d50a595336d239c9a32b457b3c075ab7b7bda50b16ba91fbac86059095994ff1eb
data/CHANGELOG.md CHANGED
@@ -4,6 +4,11 @@
4
4
 
5
5
  - None so far
6
6
 
7
+ ## [0.4.0]
8
+
9
+ - Added [Math2D](https://github.com/UalaceCafe/math2d) runtime dependency for vector maths
10
+ - Tweaked `CanvasRendererFactory` to detect `fill_rectangle` if present
11
+
7
12
  ## [0.3.0]
8
13
 
9
14
  - Defined `Renderer` and `RendererFactory` modules to define how particles are displayed
data/Gemfile CHANGED
@@ -4,5 +4,3 @@ source 'https://rubygems.org'
4
4
 
5
5
  # Specify your gem's dependencies in particlefx2d.gemspec
6
6
  gemspec
7
-
8
- gem 'ruby2d', '~> 0.11.3'
data/Gemfile.lock CHANGED
@@ -1,13 +1,15 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- particlefx2d (0.3.0)
4
+ particlefx2d (0.4.0)
5
+ math2d (~> 1.4, >= 1.4.1)
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
8
9
  specs:
9
10
  ast (2.4.2)
10
11
  diff-lcs (1.5.0)
12
+ math2d (1.4.1)
11
13
  parallel (1.22.1)
12
14
  parser (3.1.2.0)
13
15
  ast (~> 2.4.1)
@@ -44,7 +46,6 @@ GEM
44
46
  rubocop-rspec (2.9.0)
45
47
  rubocop (~> 1.19)
46
48
  ruby-progressbar (1.11.0)
47
- ruby2d (0.11.3)
48
49
  unicode-display_width (2.1.0)
49
50
  webrick (1.7.0)
50
51
  yard (0.9.27)
@@ -60,7 +61,6 @@ DEPENDENCIES
60
61
  rubocop
61
62
  rubocop-rake
62
63
  rubocop-rspec
63
- ruby2d (~> 0.11.3)
64
64
  yard
65
65
 
66
66
  BUNDLED WITH
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # ParticleFX2D
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/particlefx2d.svg)](https://badge.fury.io/rb/particlefx2d)
4
+
3
5
  This is a 2D particle effects API for use with any Ruby graphics API.
4
6
 
5
7
  > **Caution**
@@ -83,8 +85,8 @@ The gem includes a couple of pre-defined particle renderer factories for Ruby2D:
83
85
 
84
86
  | `ShapeRendererFactory` | `CanvasRendererFactory` |
85
87
  | --------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
86
- | [fx_white_red_smoke](example/ruby2d/fx_white_red_smoke.rb) ![white red smoke](example/images/fx_white_red_smoke.png) | [fx_square_burst](example/ruby2d/fx_square_burst.rb) ![fx_square_burst](example/images/fx_square_burst.png) |
87
- | [fx_blue_swirling_smoke](example/ruby2d/fx_blue_swirling_smoke.rb) ![fx_blue_swirling_smoke](example/images/fx_blue_swirling_smoke.png) |
88
+ | [fx_white_red_smoke](example/ruby2d/fx_white_red_smoke.rb) ![white red smoke](example/images/fx_white_red_smoke.gif) | [fx_square_burst](example/ruby2d/fx_square_burst.rb) ![fx_square_burst](example/images/fx_square_burst.gif) |
89
+ | [fx_blue_swirling_smoke](example/ruby2d/fx_blue_swirling_smoke.rb) ![fx_blue_swirling_smoke](example/images/fx_blue_swirling_smoke.gif) |
88
90
 
89
91
  The above are screenshots from running the various examples included. The first one with the red-white smoke is implemented in the complete example below.
90
92
 
data/Rakefile CHANGED
@@ -16,4 +16,10 @@ end
16
16
 
17
17
  RuboCop::RakeTask.new
18
18
 
19
+ desc 'Uninstall gem'
20
+ task :uninstall do
21
+ puts 'Uninstalling'
22
+ system 'gem uninstall particlefx2d --executables'
23
+ end
24
+
19
25
  task default: %i[spec rubocop]
Binary file
@@ -4,7 +4,7 @@ require 'ruby2d'
4
4
  require 'particlefx_ruby2d'
5
5
 
6
6
  # Test particle effect using Ruby2D
7
- class WhiteRedSmokeFX
7
+ class SquareBurstFX
8
8
  def self.new_emitter
9
9
  ParticleFX2D::Emitter.new(
10
10
  renderer_factory: ParticleFX2D::Ruby2D::CanvasRendererFactory.new(
@@ -30,7 +30,7 @@ class WhiteRedSmokeFX
30
30
  end
31
31
  end
32
32
 
33
- emitter = WhiteRedSmokeFX.new_emitter
33
+ emitter = SquareBurstFX.new_emitter
34
34
  tick = 0
35
35
  update do
36
36
  frame_time = 1.0 / get(:fps)
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'private/vector2'
4
3
  require_relative 'private/color'
4
+ require 'math2d'
5
5
 
6
6
  module ParticleFX2D
7
7
  #
@@ -42,8 +42,8 @@ module ParticleFX2D
42
42
  def reset!(opts = {})
43
43
  @initial_life = @life = value_from(opts, :life_time, default: 100).to_f
44
44
  @initial_size = @size = value_from(opts, :size, default: 5)
45
- @gravity = Private::Vector2.new value_from(opts, :gravity_x, default: 0),
46
- value_from(opts, :gravity_y, default: 0)
45
+ @gravity = Vector2D.new value_from(opts, :gravity_x, default: 0),
46
+ value_from(opts, :gravity_y, default: 0)
47
47
  # following may depend on initial life and size
48
48
  reset_forces opts
49
49
  reset_scale_from opts
@@ -99,17 +99,17 @@ module ParticleFX2D
99
99
  # Update the force of acceleration based on configured gravity, radial accel and
100
100
  # tangential accel if applicable.
101
101
  def update_forces
102
- @forces.copy! @gravity
102
+ @forces.replace! @gravity
103
103
  return @forces if (@radial_accel.zero? && @tangent_accel.zero?) || (@x == @initial_x && @y == @initial_y)
104
104
 
105
- @radial.set!(@x, @y)
105
+ @radial.set(@x, @y)
106
106
  .subtract!(@initial_x, @initial_y)
107
107
  .normalize!
108
- @tangential.copy!(@radial)
109
- .cross!
108
+ @tangential.replace!(@radial)
109
+ .perp!
110
110
  .times!(@tangent_accel)
111
- @forces.add_vector!(@radial.times!(@radial_accel))
112
- .add_vector!(@tangential)
111
+ @forces.plus!(@radial.times!(@radial_accel))
112
+ .plus!(@tangential)
113
113
  end
114
114
 
115
115
  # Update the motion for a frame of animation based on the updated forces and velocity
@@ -117,7 +117,7 @@ module ParticleFX2D
117
117
  @forces.times!(frame_time)
118
118
  @x += accelerated_velocity @velocity.x * frame_time, @forces.x
119
119
  @y += accelerated_velocity @velocity.y * frame_time, @forces.y
120
- @velocity.add_vector! @forces
120
+ @velocity.plus! @forces
121
121
  end
122
122
 
123
123
  # Initialize position from configuration options
@@ -155,17 +155,17 @@ module ParticleFX2D
155
155
  @angle = value_from(opts, :angle, default: 0).to_f
156
156
  @angle_in_radians = nil
157
157
  @speed = value_from(opts, :speed, default: 100).to_f
158
- @velocity ||= Private::Vector2.new
158
+ @velocity ||= Vector2D.new
159
159
  angle_rad = @angle * Math::PI / 180
160
- @velocity.set! @speed * Math.cos(angle_rad),
161
- -@speed * Math.sin(angle_rad)
160
+ @velocity.set @speed * Math.cos(angle_rad),
161
+ -@speed * Math.sin(angle_rad)
162
162
  end
163
163
 
164
164
  # Initialize forces from configuration options
165
165
  def reset_forces(opts)
166
- @radial ||= Private::Vector2.new
167
- @tangential ||= Private::Vector2.new
168
- @forces ||= Private::Vector2.new
166
+ @radial ||= Vector2D.new
167
+ @tangential ||= Vector2D.new
168
+ @forces ||= Vector2D.new
169
169
  @radial_accel = value_from(opts, :radial_acceleration, default: 0)
170
170
  @tangent_accel = value_from(opts, :tangential_acceleration, default: 0)
171
171
  end
@@ -20,6 +20,7 @@ module ParticleFX2D
20
20
  # the Canvas so that each attempt to draw into it will not cause a texture update.
21
21
  def initialize(canvas)
22
22
  @canvas = canvas
23
+ @fill_method = canvas.class.method_defined?(:fill_rectangle, true)
23
24
  end
24
25
 
25
26
  # Return a particle renderer.
@@ -31,9 +32,7 @@ module ParticleFX2D
31
32
 
32
33
  # Clear the canvas before the next update cycle
33
34
  def on_update_start
34
- @canvas.draw_rectangle(x: 0, y: 0,
35
- width: @canvas.width, height: @canvas.height,
36
- color: [0, 0, 0, 0])
35
+ fill_rect(0, 0, @canvas.width, @canvas.height, [0, 0, 0, 0])
37
36
  end
38
37
 
39
38
  # Update the canvas at the end of the next update cycle
@@ -54,9 +53,21 @@ module ParticleFX2D
54
53
  size = particle.size
55
54
  x = particle.x - (size / 2)
56
55
  y = particle.y - (size / 2)
57
- @canvas.draw_rectangle(x: x, y: y,
58
- width: size, height: size,
59
- color: particle.color.to_a)
56
+ fill_rect(x, y, size, size, particle.color.to_a)
57
+ end
58
+
59
+ private
60
+
61
+ def fill_rect(x, y, width, height, color)
62
+ if @fill_method
63
+ @canvas.fill_rectangle(x: x, y: y,
64
+ width: width, height: height,
65
+ color: color)
66
+ else
67
+ @canvas.draw_rectangle(x: x, y: y,
68
+ width: width, height: height,
69
+ color: color)
70
+ end
60
71
  end
61
72
  end
62
73
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module ParticleFX2D
4
4
  # Current version.
5
- VERSION = '0.3.0'
5
+ VERSION = '0.4.0'
6
6
  end
data/particlefx2d.gemspec CHANGED
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.metadata['rubygems_mfa_required'] = 'true'
22
22
 
23
23
  # no deployment dependencies
24
+ spec.add_runtime_dependency 'math2d', '~> 1.4', '>= 1.4.1'
24
25
 
25
26
  # development
26
27
  spec.add_development_dependency 'rake'
metadata CHANGED
@@ -1,15 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: particlefx2d
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - nogginly
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-15 00:00:00.000000000 Z
11
+ date: 2022-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: math2d
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.4'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.4.1
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.4'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.4.1
13
33
  - !ruby/object:Gem::Dependency
14
34
  name: rake
15
35
  requirement: !ruby/object:Gem::Requirement
@@ -115,8 +135,11 @@ files:
115
135
  - Rakefile
116
136
  - bin/console
117
137
  - bin/setup
138
+ - example/images/fx_blue_swirling_smoke.gif
118
139
  - example/images/fx_blue_swirling_smoke.png
140
+ - example/images/fx_square_burst.gif
119
141
  - example/images/fx_square_burst.png
142
+ - example/images/fx_white_red_smoke.gif
120
143
  - example/images/fx_white_red_smoke.png
121
144
  - example/ruby2d/fx_blue_swirling_smoke.rb
122
145
  - example/ruby2d/fx_square_burst.rb
@@ -126,7 +149,6 @@ files:
126
149
  - lib/particlefx2d/images/particle.png
127
150
  - lib/particlefx2d/particle.rb
128
151
  - lib/particlefx2d/private/color.rb
129
- - lib/particlefx2d/private/vector2.rb
130
152
  - lib/particlefx2d/renderer.rb
131
153
  - lib/particlefx2d/renderer_factory.rb
132
154
  - lib/particlefx2d/ruby2d/canvas_renderer_factory.rb
@@ -1,85 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ParticleFX2D
4
- # @!visibility private
5
- module Private
6
- # @!visibility private
7
- #
8
- # A 2D vector, for internal use only
9
- #
10
- class Vector2
11
- attr_reader :x, :y
12
-
13
- def self.copy(vector)
14
- Vector.new(vector.x, vector.y)
15
- end
16
-
17
- def initialize(x = 0, y = 0)
18
- @x = x
19
- @y = y
20
- end
21
-
22
- def set!(x, y)
23
- @x = x
24
- @y = y
25
- self
26
- end
27
-
28
- def copy!(other)
29
- @x = other.x
30
- @y = other.y
31
- self
32
- end
33
-
34
- def add!(x, y)
35
- @x += x
36
- @y += y
37
- self
38
- end
39
-
40
- def subtract!(x, y)
41
- @x -= x
42
- @y -= y
43
- self
44
- end
45
-
46
- def times!(value)
47
- @x *= value
48
- @y *= value
49
- self
50
- end
51
-
52
- def divide_by!(value)
53
- @x /= value
54
- @y /= value
55
- self
56
- end
57
-
58
- def add_vector!(other)
59
- @x += other.x
60
- @y += other.y
61
- self
62
- end
63
-
64
- def minus_vector!(other)
65
- @x -= other.x
66
- @y -= other.y
67
- self
68
- end
69
-
70
- def magnitude
71
- Math.sqrt(@x.abs2 + @y.abs2)
72
- end
73
-
74
- def cross!
75
- set! @y, -@x
76
- end
77
-
78
- def normalize!
79
- mag = magnitude
80
- mag = Float::INFINITY if mag.zero?
81
- divide_by! mag
82
- end
83
- end
84
- end
85
- end