particlefx2d 0.3.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 +7 -0
- data/.gitignore +14 -0
- data/.rspec +3 -0
- data/.rubocop.yml +21 -0
- data/.ruby-version +1 -0
- data/.yardopts +1 -0
- data/CHANGELOG.md +25 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +67 -0
- data/LICENSE.txt +21 -0
- data/README.md +174 -0
- data/Rakefile +19 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/example/images/fx_blue_swirling_smoke.png +0 -0
- data/example/images/fx_square_burst.png +0 -0
- data/example/images/fx_white_red_smoke.png +0 -0
- data/example/ruby2d/fx_blue_swirling_smoke.rb +39 -0
- data/example/ruby2d/fx_square_burst.rb +41 -0
- data/example/ruby2d/fx_white_red_smoke.rb +37 -0
- data/lib/particlefx2d/emitter.rb +163 -0
- data/lib/particlefx2d/images/particle.png +0 -0
- data/lib/particlefx2d/particle.rb +173 -0
- data/lib/particlefx2d/private/color.rb +88 -0
- data/lib/particlefx2d/private/vector2.rb +85 -0
- data/lib/particlefx2d/renderer.rb +34 -0
- data/lib/particlefx2d/renderer_factory.rb +37 -0
- data/lib/particlefx2d/ruby2d/canvas_renderer_factory.rb +63 -0
- data/lib/particlefx2d/ruby2d/particle_circle.rb +38 -0
- data/lib/particlefx2d/ruby2d/particle_image.rb +45 -0
- data/lib/particlefx2d/ruby2d/shape_renderer.rb +52 -0
- data/lib/particlefx2d/ruby2d/shape_renderer_factory.rb +30 -0
- data/lib/particlefx2d/version.rb +6 -0
- data/lib/particlefx2d.rb +9 -0
- data/lib/particlefx_ruby2d.rb +14 -0
- data/particlefx2d.gemspec +32 -0
- data/sig/particlefx2d.rbs +4 -0
- data/spec/spec_helper.rb +15 -0
- data/spec/unit/particlefx2d_spec.rb +7 -0
- metadata +170 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cb24e46327d94431dae7018d29abc79159b71fbae358cccd270dc4aa2a16db7d
|
4
|
+
data.tar.gz: 7286c7ce9812eb236765129b30c5755876917ceb0fd456d0a108cec8f9a164d3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 52260a8afa4d7fead08320e9726dc3d33a032a4e9af8d70e6ba9936388e0296048479f1053eb924d874f4aaf038d1a85f5d40e19e4115a7750677e0d847ef039
|
7
|
+
data.tar.gz: cd55c2e8c789b9a026c5fae7408ecf2b95b0ed07e7048a34d7602b2b9d290eafd411f32854d1dcc48ff3abe63b70c2a48e6984bca61f773723ce0556cbc80dcd
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.7
|
3
|
+
NewCops: enable
|
4
|
+
|
5
|
+
Style/StringLiteralsInInterpolation:
|
6
|
+
Enabled: true
|
7
|
+
EnforcedStyle: double_quotes
|
8
|
+
|
9
|
+
Naming/MethodParameterName:
|
10
|
+
inherit_mode:
|
11
|
+
override:
|
12
|
+
- Include
|
13
|
+
AllowedNames:
|
14
|
+
- x
|
15
|
+
- y
|
16
|
+
|
17
|
+
Metrics/ClassLength:
|
18
|
+
Max: 128
|
19
|
+
|
20
|
+
Metrics/MethodLength:
|
21
|
+
Max: 32
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.7
|
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--no-private
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# ParticleFX2D Change Log
|
2
|
+
|
3
|
+
## [Unreleased]
|
4
|
+
|
5
|
+
- None so far
|
6
|
+
|
7
|
+
## [0.3.0]
|
8
|
+
|
9
|
+
- Defined `Renderer` and `RendererFactory` modules to define how particles are displayed
|
10
|
+
- Refactors the Ruby2D renderers to define to factories
|
11
|
+
- `ShapeRendererFactory` which can be supplied a renderer class (viz. `ParticleCircle` and `ParticleShape`) to generate renderers
|
12
|
+
- Preview `CanvasRendererFactory` which can be given a `Ruby2D::Canvas` into which the particle effects are drawn. Consider this _alpha_ because Canvas in Ruby2D is in its early days and currently only support rectangles.
|
13
|
+
- The existing examples use the `ShapeRendererFactory`
|
14
|
+
- Added an example [fx_square_burst](example/ruby2d/fx_square_burst.rb) that uses the `CanvasRendererFactory`
|
15
|
+
|
16
|
+
## [0.2.0]
|
17
|
+
|
18
|
+
- Added some usage documentation to README
|
19
|
+
- Requiring `particlefx_ruby2d` now automatically brings in `particlefx2d`
|
20
|
+
- `Particle` properly handles colour arrays as input
|
21
|
+
- Cleaned up examples
|
22
|
+
|
23
|
+
## [0.1.0]
|
24
|
+
|
25
|
+
- Initial release
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at nogginly@icloud.com. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
particlefx2d (0.3.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.2)
|
10
|
+
diff-lcs (1.5.0)
|
11
|
+
parallel (1.22.1)
|
12
|
+
parser (3.1.2.0)
|
13
|
+
ast (~> 2.4.1)
|
14
|
+
rainbow (3.1.1)
|
15
|
+
rake (13.0.6)
|
16
|
+
regexp_parser (2.3.0)
|
17
|
+
rexml (3.2.5)
|
18
|
+
rspec (3.11.0)
|
19
|
+
rspec-core (~> 3.11.0)
|
20
|
+
rspec-expectations (~> 3.11.0)
|
21
|
+
rspec-mocks (~> 3.11.0)
|
22
|
+
rspec-core (3.11.0)
|
23
|
+
rspec-support (~> 3.11.0)
|
24
|
+
rspec-expectations (3.11.0)
|
25
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
26
|
+
rspec-support (~> 3.11.0)
|
27
|
+
rspec-mocks (3.11.1)
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
+
rspec-support (~> 3.11.0)
|
30
|
+
rspec-support (3.11.0)
|
31
|
+
rubocop (1.27.0)
|
32
|
+
parallel (~> 1.10)
|
33
|
+
parser (>= 3.1.0.0)
|
34
|
+
rainbow (>= 2.2.2, < 4.0)
|
35
|
+
regexp_parser (>= 1.8, < 3.0)
|
36
|
+
rexml
|
37
|
+
rubocop-ast (>= 1.16.0, < 2.0)
|
38
|
+
ruby-progressbar (~> 1.7)
|
39
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
40
|
+
rubocop-ast (1.17.0)
|
41
|
+
parser (>= 3.1.1.0)
|
42
|
+
rubocop-rake (0.6.0)
|
43
|
+
rubocop (~> 1.0)
|
44
|
+
rubocop-rspec (2.9.0)
|
45
|
+
rubocop (~> 1.19)
|
46
|
+
ruby-progressbar (1.11.0)
|
47
|
+
ruby2d (0.11.3)
|
48
|
+
unicode-display_width (2.1.0)
|
49
|
+
webrick (1.7.0)
|
50
|
+
yard (0.9.27)
|
51
|
+
webrick (~> 1.7.0)
|
52
|
+
|
53
|
+
PLATFORMS
|
54
|
+
arm64-darwin-21
|
55
|
+
|
56
|
+
DEPENDENCIES
|
57
|
+
particlefx2d!
|
58
|
+
rake
|
59
|
+
rspec (~> 3.0)
|
60
|
+
rubocop
|
61
|
+
rubocop-rake
|
62
|
+
rubocop-rspec
|
63
|
+
ruby2d (~> 0.11.3)
|
64
|
+
yard
|
65
|
+
|
66
|
+
BUNDLED WITH
|
67
|
+
2.3.7
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2022 Kumanan Yogaratnam
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,174 @@
|
|
1
|
+
# ParticleFX2D
|
2
|
+
|
3
|
+
This is a 2D particle effects API for use with any Ruby graphics API.
|
4
|
+
|
5
|
+
> **Caution**
|
6
|
+
>
|
7
|
+
> Most of the functionality is fairly stable and any changes will likely be additive. However portions identified as "preview" are likely to experience API changes.
|
8
|
+
|
9
|
+
- [Installation](#installation)
|
10
|
+
- [Usage](#usage)
|
11
|
+
- [Setting up an Emitter](#setting-up-an-emitter)
|
12
|
+
- [Using Ruby2D](#using-ruby2d)
|
13
|
+
- [Examples](#examples)
|
14
|
+
- [Knobs & Dials](#knobs--dials)
|
15
|
+
- [Emitter Controls](#emitter-controls)
|
16
|
+
- [Particle Controls](#particle-controls)
|
17
|
+
- [Development](#development)
|
18
|
+
- [Contributing](#contributing)
|
19
|
+
- [License](#license)
|
20
|
+
- [Code of Conduct](#code-of-conduct)
|
21
|
+
|
22
|
+
## Installation
|
23
|
+
|
24
|
+
Add this line to your application's Gemfile:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
gem 'particlefx2d'
|
28
|
+
```
|
29
|
+
|
30
|
+
And then execute:
|
31
|
+
|
32
|
+
$ bundle install
|
33
|
+
|
34
|
+
Or install it yourself as:
|
35
|
+
|
36
|
+
$ gem install particlefx2d
|
37
|
+
|
38
|
+
## Usage
|
39
|
+
|
40
|
+
After the gem has been installed, using `ParticleFX2D` involves the following steps:
|
41
|
+
|
42
|
+
1. Define an emitter
|
43
|
+
2. Define a particle renderer factory and renderer (or use the ones included if you're using [Ruby2D](https://www.ruby2d.com/))
|
44
|
+
3. Call the emitter's `#update` method from your app's animation loop
|
45
|
+
|
46
|
+
### Setting up an Emitter
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
require 'particlefx2d'
|
50
|
+
|
51
|
+
fx = ParticleFX2D::Emitter.new(
|
52
|
+
renderer_factory: <<RENDERER_FACTORY>>, # particle renderer factory
|
53
|
+
quantity: 100, # max no. of particles
|
54
|
+
emission_rate: 15, # emit particles/sec
|
55
|
+
particle_config: {
|
56
|
+
x: 300, x_range: -1.0..1.0, # x emission origin
|
57
|
+
y: 300, y_range: 0, # y emission origin
|
58
|
+
start_color: [1, 1, 1, 1], # start colour array [r, g, b, a]
|
59
|
+
end_color: [1, 0, 0, 0], # end colour
|
60
|
+
start_scale: 1, end_scale: 2, # start and end size scaling
|
61
|
+
angle: 90, angle_range: -30.0...30.0, # emission angle and range
|
62
|
+
size: 32, size_range: 0, # emission size and range
|
63
|
+
speed: 40, speed_range: 0..15, # emission speed and range
|
64
|
+
gravity_y: 10, gravity_x: -6, # gravity in pixels/sec squared
|
65
|
+
life_time: 5, life_time_range: 0..2.0 # life of particle
|
66
|
+
}
|
67
|
+
)
|
68
|
+
```
|
69
|
+
|
70
|
+
### Using Ruby2D
|
71
|
+
|
72
|
+
The gem includes a couple of pre-defined particle renderer factories for Ruby2D:
|
73
|
+
* `ParticleFX2D::Ruby2D::`
|
74
|
+
* `ShapeRendererFactory` which can be instantiated by supplying it an object that implements `ShapeRenderer` methods, such as the following pre-defined renderers:
|
75
|
+
* `ParticleImage`
|
76
|
+
* Use a particle blob via `Ruby2D::Image` as texture to render a particle
|
77
|
+
* `ParticleCircle`
|
78
|
+
* Use a `Ruby2D::Circle` to render a particle
|
79
|
+
* `CanvasRendererFactory` which can be instantiated with a `Ruby2D::Canvas` into which the particles are drawn as squares.
|
80
|
+
* The Canvas in Ruby2D is in its early days so consider this factory a preview _with many changes expected_.
|
81
|
+
|
82
|
+
#### Examples
|
83
|
+
|
84
|
+
| `ShapeRendererFactory` | `CanvasRendererFactory` |
|
85
|
+
| --------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
|
86
|
+
| [fx_white_red_smoke](example/ruby2d/fx_white_red_smoke.rb)  | [fx_square_burst](example/ruby2d/fx_square_burst.rb)  |
|
87
|
+
| [fx_blue_swirling_smoke](example/ruby2d/fx_blue_swirling_smoke.rb)  |
|
88
|
+
|
89
|
+
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
|
+
|
91
|
+
```ruby
|
92
|
+
require 'ruby2d'
|
93
|
+
require 'particlefx_ruby2d'
|
94
|
+
|
95
|
+
fx = ParticleFX2D::Emitter.new(
|
96
|
+
renderer_factory: ParticleFX2D::Ruby2D::ShapeRendererFactory.new(ParticleFX2D::Ruby2D::ParticleImage),
|
97
|
+
quantity: 100, # max no. of particles
|
98
|
+
emission_rate: 15, # emit particles/sec
|
99
|
+
particle_config: {
|
100
|
+
x: 300, x_range: -1.0..1.0, # x emission origin
|
101
|
+
y: 300, y_range: 0, # y emission origin
|
102
|
+
start_color: [1, 1, 1, 1], # start colour array [r, g, b, a]
|
103
|
+
end_color: [1, 0, 0, 0], # end colour
|
104
|
+
start_scale: 1, end_scale: 2, # start and end size scaling
|
105
|
+
angle: 90, angle_range: -30.0...30.0, # emission angle and range
|
106
|
+
size: 32, size_range: 0, # emission size and range
|
107
|
+
speed: 40, speed_range: 0..15, # emission speed and range
|
108
|
+
gravity_y: 10, gravity_x: -6, # gravity in pixels/sec squared
|
109
|
+
life_time: 5, life_time_range: 0..2.0 # life of particle
|
110
|
+
}
|
111
|
+
)
|
112
|
+
update do
|
113
|
+
fx.update (1.0 / get(:fps))
|
114
|
+
end
|
115
|
+
show
|
116
|
+
|
117
|
+
```
|
118
|
+
|
119
|
+
### Knobs & Dials
|
120
|
+
|
121
|
+
It's all about the _knobs and dials_, every control can be tweaked to get a wide variety of effects.
|
122
|
+
|
123
|
+
#### Emitter Controls
|
124
|
+
|
125
|
+
| Emitter Config | Description |
|
126
|
+
| ----------------- | ---------------------------------------------------------------- |
|
127
|
+
| `quantity` | Number of total particles in the emitter's pool |
|
128
|
+
| `emission_rate` | Number of particles to emit per second |
|
129
|
+
| `particle_config` | Configure each particle when it is emitted. See the table below. |
|
130
|
+
|
131
|
+
#### Particle Controls
|
132
|
+
|
133
|
+
| Particle Config | Description |
|
134
|
+
| ------------------------- | ----------------------------------------------------------------------------------------------- |
|
135
|
+
| `x` | Initial x-axis position of emission |
|
136
|
+
| `x_range` | optional range from which a random value is chosen to add to the initial `x`; default is 0 |
|
137
|
+
| `y` | Initial y-axis position of emission |
|
138
|
+
| `y_range` | optional range from which a random value is chosen to add to the initial `y`; default is 0 |
|
139
|
+
| `start_color` | optional initial colour of the emitted particle. See `Particle` for default |
|
140
|
+
| `end_color` | optional end colour of the particle by the end of its life. See `Particle` for default |
|
141
|
+
| `start_scale` | optional initial size scale factor of the emitted particle relative to its `size`; default is 1 |
|
142
|
+
| `end_scale` | optional end size scale factor of the particle by the end of its life; default is 1 |
|
143
|
+
| `angle` | optional angle at which the particle is emitted, in degrees. See `Particle` for default |
|
144
|
+
| `angle_range` | optional range from which a random value is chosen to add to the `angle`; default is 0 |
|
145
|
+
| `speed` | optional speed at which the particle is emitted, in pixels/s. See `Particle` for default |
|
146
|
+
| `speed_range` | optional range from which a random value is chosen to add to the `speed`; default is 0 |
|
147
|
+
| `size` | optional size of the particle when emitted, in pixels. See `Particle` for default |
|
148
|
+
| `size_range` | optional range from which a random value is chosen to add to the `size`; default is 0 |
|
149
|
+
| `gravity_x` | optional linear acceleration in pixels/second squared along the x axis, default is 0 |
|
150
|
+
| `gravity_y` | optional linear acceleration in pixels/second squared along the y axis, default is 0 |
|
151
|
+
| `radial_acceleration` | optional radial accelation in pixel/seconds squared, default is 0 |
|
152
|
+
| `tangential_acceleration` | optional tangential accelation in pixel/seconds squared, default is 0 |
|
153
|
+
| `life_time` | of each particle in seconds. See `Particle` for default |
|
154
|
+
| `life_time_range` | optional range from which a random value is chosen to add to the `life_time`; default is 0 |
|
155
|
+
|
156
|
+
## Development
|
157
|
+
|
158
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
159
|
+
|
160
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
161
|
+
|
162
|
+
## Contributing
|
163
|
+
|
164
|
+
Bug reports and sugestions are welcome. Otherwise, at this time, this project is closed for code changes and pull requests. I appreciate your understanding.
|
165
|
+
|
166
|
+
This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/nogginly/particlefx2d/blob/main/CODE_OF_CONDUCT.md).
|
167
|
+
|
168
|
+
## License
|
169
|
+
|
170
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
171
|
+
|
172
|
+
## Code of Conduct
|
173
|
+
|
174
|
+
Everyone interacting in the `ParticleFX2D` project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/nogginly/particlefx2d/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
7
|
+
|
8
|
+
require 'rubocop/rake_task'
|
9
|
+
|
10
|
+
require 'yard'
|
11
|
+
|
12
|
+
YARD::Rake::YardocTask.new do |t|
|
13
|
+
t.files = ['lib/**/*.rb']
|
14
|
+
t.stats_options = ['--list-undoc']
|
15
|
+
end
|
16
|
+
|
17
|
+
RuboCop::RakeTask.new
|
18
|
+
|
19
|
+
task default: %i[spec rubocop]
|
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'particlefx2d'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ruby2d'
|
4
|
+
require 'particlefx_ruby2d'
|
5
|
+
require 'particlefx2d'
|
6
|
+
|
7
|
+
# Test particle effect using Ruby2D
|
8
|
+
class BlueSwirlingSmokeFX
|
9
|
+
def self.new_emitter
|
10
|
+
ParticleFX2D::Emitter.new(
|
11
|
+
renderer_factory: ParticleFX2D::Ruby2D::ShapeRendererFactory.new(ParticleFX2D::Ruby2D::ParticleImage),
|
12
|
+
quantity: 200,
|
13
|
+
emission_rate: 200,
|
14
|
+
particle_config: {
|
15
|
+
x: Window.width / 2, x_range: -10.0..10.0,
|
16
|
+
y: Window.height / 2, y_range: -5.0..5.0,
|
17
|
+
start_color: [0.5, 0.5, 1, 1],
|
18
|
+
end_color: [0, 0, 0, 1],
|
19
|
+
angle: 0, angle_range: 0.0..360.0,
|
20
|
+
size: 32, size_range: 4,
|
21
|
+
start_scale: 0.5, end_scale: 1.5,
|
22
|
+
speed: 10, speed_range: 0..5,
|
23
|
+
radial_acceleration: -3,
|
24
|
+
tangential_acceleration: 6,
|
25
|
+
life_time: 6, life_time_range: 0..2.0
|
26
|
+
}
|
27
|
+
)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
emitter = BlueSwirlingSmokeFX.new_emitter
|
32
|
+
tick = 0
|
33
|
+
update do
|
34
|
+
frame_time = 1.0 / get(:fps)
|
35
|
+
emitter.update frame_time
|
36
|
+
tick += 1
|
37
|
+
puts emitter.stats if (tick % 60).zero?
|
38
|
+
end
|
39
|
+
show
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ruby2d'
|
4
|
+
require 'particlefx_ruby2d'
|
5
|
+
|
6
|
+
# Test particle effect using Ruby2D
|
7
|
+
class WhiteRedSmokeFX
|
8
|
+
def self.new_emitter
|
9
|
+
ParticleFX2D::Emitter.new(
|
10
|
+
renderer_factory: ParticleFX2D::Ruby2D::CanvasRendererFactory.new(
|
11
|
+
Canvas.new(x: 10, y: 10, width: Window.width - 20, height: Window.height - 20, update: false)
|
12
|
+
),
|
13
|
+
quantity: 200,
|
14
|
+
emission_rate: 60,
|
15
|
+
particle_config: {
|
16
|
+
x: Window.width / 2, x_range: -3.0..3.0,
|
17
|
+
y: Window.height - (Window.height / 3), y_range: 0,
|
18
|
+
start_color: Color.new([1, 0, 1, 1]),
|
19
|
+
end_color: Color.new([1, 1, 1, 0]),
|
20
|
+
start_scale: 0.5, end_scale: 3,
|
21
|
+
angle: 90, angle_range: -35.0..10.0,
|
22
|
+
size: 4.0, size_range: 0,
|
23
|
+
speed: 90, speed_range: -10.0..10.0,
|
24
|
+
gravity_y: 20, # gravity_x: -6,
|
25
|
+
radial_acceleration: -2,
|
26
|
+
tangential_acceleration: 10,
|
27
|
+
life_time: 7, life_time_range: -1.0..1.0
|
28
|
+
}
|
29
|
+
)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
emitter = WhiteRedSmokeFX.new_emitter
|
34
|
+
tick = 0
|
35
|
+
update do
|
36
|
+
frame_time = 1.0 / get(:fps)
|
37
|
+
emitter.update frame_time
|
38
|
+
tick += 1
|
39
|
+
puts emitter.stats if (tick % 60).zero?
|
40
|
+
end
|
41
|
+
show
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ruby2d'
|
4
|
+
require 'particlefx_ruby2d'
|
5
|
+
|
6
|
+
# Test particle effect using Ruby2D
|
7
|
+
class WhiteRedSmokeFX
|
8
|
+
def self.new_emitter
|
9
|
+
ParticleFX2D::Emitter.new(
|
10
|
+
renderer_factory: ParticleFX2D::Ruby2D::ShapeRendererFactory.new(ParticleFX2D::Ruby2D::ParticleImage),
|
11
|
+
quantity: 100,
|
12
|
+
emission_rate: 15,
|
13
|
+
particle_config: {
|
14
|
+
x: Window.width / 2, x_range: -1.0..1.0,
|
15
|
+
y: Window.height - (Window.height / 4), y_range: 0,
|
16
|
+
start_color: Color.new([1, 1, 1, 1]),
|
17
|
+
end_color: Color.new([1, 0, 0, 0]),
|
18
|
+
start_scale: 1, end_scale: 2,
|
19
|
+
angle: 90, angle_range: -30.0...30.0,
|
20
|
+
size: 32, size_range: 0,
|
21
|
+
speed: 40, speed_range: 0..15,
|
22
|
+
gravity_y: 10, gravity_x: -6,
|
23
|
+
life_time: 5, life_time_range: 0..2.0
|
24
|
+
}
|
25
|
+
)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
emitter = WhiteRedSmokeFX.new_emitter
|
30
|
+
tick = 0
|
31
|
+
update do
|
32
|
+
frame_time = 1.0 / get(:fps)
|
33
|
+
emitter.update frame_time
|
34
|
+
tick += 1
|
35
|
+
puts emitter.stats if (tick % 60).zero?
|
36
|
+
end
|
37
|
+
show
|