gosu_more_drawables 0.2.0 → 0.3.1

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: e8a363874fb18dd5b045675f86bfa6f5f5912420e81aa284ca963415d177e3c1
4
- data.tar.gz: 8df53570385f951ab1750843c18d921e9cca6c018118ee8dbcf99187938fdd8c
3
+ metadata.gz: ff59071666b8d755c82ad42e815450e78db243832d0f0eb3e5867a8acacec56f
4
+ data.tar.gz: e3f8f3293dea739f3f36c83544ed81c4e42544e1200abd55455cd24956ca038e
5
5
  SHA512:
6
- metadata.gz: 264661a4ca1155914f874abb0b277a2ddbe80313fe0f0f016c037668d5bf4343098e1be1a1eec629c391e1288da941e2f37a671988c495ad434d84f400654b0f
7
- data.tar.gz: e704ea0d5ff1dabfdaf7835f7d118b48654363faa59d3997c6c9bc9bf57321cb45838afd12578783ceda44f5fafb2f43035ef5817ffe3cec87ece5c5ec05b59a
6
+ metadata.gz: 91ef4132f0bb1a23ee609636d5b1b11ef621af949f76b3b82d5d5f236bb53b0925c97f989c9f56ac394bbeb0e476f5cc914bdd062d2e1cfb43bee382927b935e
7
+ data.tar.gz: 3739156c1bd2cb5acb1bfda74f551b1addb7bb0f9f2c6a2f0d154714546ee3dd441aaa3bcfc299ae8809cb17fc0c37a9f1f5a89c2007089b1bc37955faff2f5b
data/.gitignore CHANGED
@@ -1,8 +1,8 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source "https://rubygems.org"
2
-
3
- # Specify your gem's dependencies in gosu_more_drawables.gemspec
4
- gemspec
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in gosu_more_drawables.gemspec
4
+ gemspec
@@ -1,21 +1,21 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2020 Cyberarm
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
13
- all 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
21
- THE SOFTWARE.
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Cyberarm
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -1,39 +1,55 @@
1
- # GosuMoreDrawables
2
-
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/gosu_more_drawables`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
6
-
7
- ## Installation
8
-
9
- Add this line to your application's Gemfile:
10
-
11
- ```ruby
12
- gem 'gosu_more_drawables'
13
- ```
14
-
15
- And then execute:
16
-
17
- $ bundle
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install gosu_more_drawables
22
-
23
- ## Usage
24
-
25
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
-
31
- 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
-
33
- ## Contributing
34
-
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/gosu_more_drawables.
36
-
37
- ## License
38
-
39
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
1
+ # GosuMoreDrawables
2
+
3
+ Adds `Gosu.draw_circle` and `Gosu.draw_arc` to the Gosu game library.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'gosu_more_drawables'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install gosu_more_drawables
20
+
21
+ ## Usage
22
+
23
+ ``` ruby
24
+ require "gosu"
25
+ require "gosu_more_drawables"
26
+
27
+ class DemoWindow < Gosu::Window
28
+ def initialize
29
+ super(500, 500, false)
30
+ end
31
+
32
+ def draw
33
+ Gosu.draw_circle(250, 250, 200, 128, Gosu::Color.rgb(0, 200, 0))
34
+ Gosu.draw_arc(250, 250, 200, 1.0, 128, 4, Gosu::Color.rgba(127, 64, 0, 100))
35
+ end
36
+ end
37
+
38
+ DemoWindow.new.show
39
+ ```
40
+
41
+ ![screenshot of example](https://raw.githubusercontent.com/cyberarm/gosu_more_drawables/master/media/screenshot.png)
42
+
43
+ ## Development
44
+
45
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
46
+
47
+ 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
48
+
49
+ ## Contributing
50
+
51
+ Bug reports and pull requests are welcome on GitHub at https://github.com/cyberarm/gosu_more_drawables.
52
+
53
+ ## License
54
+
55
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -1,10 +1,10 @@
1
- require "bundler/gem_tasks"
2
- require "rake/testtask"
3
-
4
- Rake::TestTask.new(:test) do |t|
5
- t.libs << "test"
6
- t.libs << "lib"
7
- t.test_files = FileList["test/**/*_test.rb"]
8
- end
9
-
10
- task :default => :test
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
@@ -1,14 +1,14 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "gosu_more_drawables"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "gosu_more_drawables"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup CHANGED
@@ -1,8 +1,8 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,15 @@
1
+ require "gosu"
2
+ require "gosu_more_drawables"
3
+
4
+ class DemoWindow < Gosu::Window
5
+ def initialize
6
+ super(500, 500, false)
7
+ end
8
+
9
+ def draw
10
+ Gosu.draw_circle(250, 250, 200, 128, Gosu::Color.rgb(0, 200, 0))
11
+ Gosu.draw_arc(250, 250, 200, 1.0, 128, 4, Gosu::Color.rgba(127, 64, 0, 100))
12
+ end
13
+ end
14
+
15
+ DemoWindow.new.show
@@ -0,0 +1,33 @@
1
+ require "gosu"
2
+ require "gosu_more_drawables"
3
+
4
+ class DemoWindow < Gosu::Window
5
+ def initialize
6
+ super(500, 500, false)
7
+
8
+ @nodes = []
9
+ end
10
+
11
+ def draw
12
+ sine = Math.sin(Gosu.milliseconds / 1000.0)
13
+ c = (255 * sine).to_i.clamp(10, 255)
14
+ color = Gosu::Color.rgb(c, 255, c / 2)
15
+
16
+ Gosu.draw_path(@nodes, color)
17
+
18
+ @nodes.each do |node|
19
+ Gosu.draw_circle(node.x, node.y, 4, 4, color)
20
+ end
21
+ end
22
+
23
+ def update
24
+ x = 20
25
+ @nodes.clear
26
+ 20.times do |i|
27
+ @nodes << Gosu::PathNode.new(x + i, Math.cos(Gosu.milliseconds / 100.0 + i.to_f) * 10 + self.height / 2)
28
+ x += 20
29
+ end
30
+ end
31
+ end
32
+
33
+ DemoWindow.new.show
@@ -1,33 +1,34 @@
1
- lib = File.expand_path("lib", __dir__)
2
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require "gosu_more_drawables/version"
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = "gosu_more_drawables"
7
- spec.version = GosuMoreDrawables::VERSION
8
- spec.authors = ["Cyberarm"]
9
- spec.email = ["matthewlikesrobots@gmail.com"]
10
-
11
- spec.summary = %q{Adds circles and arcs to Gosu}
12
- spec.description = %q{Adds Gosu.draw_circle and Gosu.draw_arc for Gosu}
13
- spec.homepage = "https://github.com/cyberarm/gosu_more_drawables"
14
- spec.license = "MIT"
15
-
16
- spec.metadata["allowed_push_host"] = "https://rubygems.org"
17
-
18
- spec.metadata["homepage_uri"] = spec.homepage
19
- spec.metadata["source_code_uri"] = "https://github.com/cyberarm/gosu_more_drawables"
20
-
21
- # Specify which files should be added to the gem when it is released.
22
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
- end
26
- spec.bindir = "exe"
27
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
- spec.require_paths = ["lib"]
29
-
30
- spec.add_development_dependency "bundler", "~> 2.0"
31
- spec.add_development_dependency "rake", "~> 10.0"
32
- spec.add_development_dependency "minitest", "~> 5.0"
33
- end
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "gosu_more_drawables/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "gosu_more_drawables"
7
+ spec.version = GosuMoreDrawables::VERSION
8
+ spec.authors = ["Cyberarm"]
9
+ spec.email = ["matthewlikesrobots@gmail.com"]
10
+
11
+ spec.summary = %q{Adds circles and arcs to Gosu}
12
+ spec.description = %q{Adds Gosu.draw_circle and Gosu.draw_arc for Gosu}
13
+ spec.homepage = "https://github.com/cyberarm/gosu_more_drawables"
14
+ spec.license = "MIT"
15
+
16
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
17
+
18
+ spec.metadata["homepage_uri"] = spec.homepage
19
+ spec.metadata["source_code_uri"] = "https://github.com/cyberarm/gosu_more_drawables"
20
+ spec.metadata["documentation_uri"] = "https://rubydoc.info/gems/gosu_more_drawables"
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
25
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ end
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ spec.add_development_dependency "bundler", "~> 2.0"
32
+ spec.add_development_dependency "rake", "~> 10.0"
33
+ spec.add_development_dependency "minitest", "~> 5.0"
34
+ end
@@ -1,3 +1,4 @@
1
- require_relative "gosu_more_drawables/draw_arc"
2
- require_relative "gosu_more_drawables/draw_circle"
3
- require_relative "gosu_more_drawables/version"
1
+ require_relative "gosu_more_drawables/draw_arc"
2
+ require_relative "gosu_more_drawables/draw_path"
3
+ require_relative "gosu_more_drawables/draw_circle"
4
+ require_relative "gosu_more_drawables/version"
@@ -1,95 +1,98 @@
1
- module Gosu
2
- # Draw an arc around the point x and y.
3
- #
4
- # Color accepts the following: *Gosu::Color*, *Array* (with 2 colors), or a *Hash* with keys: _from:_ and _to:_ both colors.
5
- #
6
- # With a *Gosu::Color* the arc will be painted with color
7
- #
8
- # With an *Array* the first *Gosu::Color* with be the innermost color and the last *Gosu::Color* with be the outermost color
9
- #
10
- # With a *Hash* the arc will smoothly transition from the start of the arc to the end
11
- # @example
12
- # # Using a Hash
13
- # Gosu.draw_arc(100, 100, 50, 0.5, 128, 4, {from: Gosu::Color::BLUE, to: Gosu::Color::GREEN}, 0, :default)
14
- #
15
- # # Using an Array
16
- # Gosu.draw_arc(100, 100, 50, 0.5, 128, 4, [Gosu::Color::BLUE, Gosu::Color::GREEN], 0, :default)
17
- #
18
- # # Using a Gosu::Color
19
- # Gosu.draw_arc(100, 100, 50, 0.5, 128, 4, Gosu::Color::BLUE, 0, :default)
20
- #
21
- #
22
- # @param x X position.
23
- # @param y Y position.
24
- # @param radius radius of arc, in pixels.
25
- # @param percentage how complete the segment is, __0.0 is 0% and _1.0_ is 100%.
26
- # @param segments how many segments for arc, more will appear smoother, less will appear jagged.
27
- # @param thickness how thick arc will be.
28
- # @param color [Gosu::Color, Array<Gosu::Color, Gosu::Color>, Hash{from: start_color, to: end_color}] color or colors to draw the arc with.
29
- # @param z Z position.
30
- # @param mode blend mode.
31
- #
32
- # @note _thickness_ is subtracted from radius, meaning that the arc will grow towards the origin, not away from it.
33
- #
34
- # @return [void]
35
- def self.draw_arc(x, y, radius, percentage = 1.0, segments = 128, thickness = 4, color = Gosu::Color::WHITE, z = 0, mode = :default)
36
- segments = 360.0 / segments
37
-
38
- return if percentage == 0.0
39
-
40
- 0.step((359 * percentage), segments) do |angle|
41
- angle2 = angle + segments
42
-
43
- point_a_left_x = x + Gosu.offset_x(angle, radius - thickness)
44
- point_a_left_y = y + Gosu.offset_y(angle, radius - thickness)
45
-
46
- point_a_right_x = x + Gosu.offset_x(angle2, radius - thickness)
47
- point_a_right_y = y + Gosu.offset_y(angle2, radius - thickness)
48
-
49
- point_b_left_x = x + Gosu.offset_x(angle, radius)
50
- point_b_left_y = y + Gosu.offset_y(angle, radius)
51
-
52
- point_b_right_x = x + Gosu.offset_x(angle2, radius)
53
- point_b_right_y = y + Gosu.offset_y(angle2, radius)
54
-
55
- if color.is_a?(Array)
56
- Gosu.draw_quad(
57
- point_a_left_x, point_a_left_y, color.first,
58
- point_b_left_x, point_b_left_y, color.last,
59
- point_a_right_x, point_a_right_y, color.first,
60
- point_b_right_x, point_b_right_y, color.last
61
- )
62
- elsif color.is_a?(Hash)
63
- start_color = color[:from]
64
- end_color = color[:to]
65
-
66
- color_a = Gosu::Color.rgba(
67
- (end_color.red - start_color.red) * (angle / 360.0) + start_color.red,
68
- (end_color.green - start_color.green) * (angle / 360.0) + start_color.green,
69
- (end_color.blue - start_color.blue) * (angle / 360.0) + start_color.blue,
70
- (end_color.alpha - start_color.alpha) * (angle / 360.0) + start_color.alpha,
71
- )
72
- color_b = Gosu::Color.rgba(
73
- (end_color.red - start_color.red) * (angle2 / 360.0) + start_color.red,
74
- (end_color.green - start_color.green) * (angle2 / 360.0) + start_color.green,
75
- (end_color.blue - start_color.blue) * (angle2 / 360.0) + start_color.blue,
76
- (end_color.alpha - start_color.alpha) * (angle2 / 360.0) + start_color.alpha,
77
- )
78
-
79
- Gosu.draw_quad(
80
- point_a_left_x, point_a_left_y, color_a,
81
- point_b_left_x, point_b_left_y, color_a,
82
- point_a_right_x, point_a_right_y, color_b,
83
- point_b_right_x, point_b_right_y, color_b
84
- )
85
- else
86
- Gosu.draw_quad(
87
- point_a_left_x, point_a_left_y, color,
88
- point_b_left_x, point_b_left_y, color,
89
- point_a_right_x, point_a_right_y, color,
90
- point_b_right_x, point_b_right_y, color
91
- )
92
- end
93
- end
94
- end
1
+ module Gosu
2
+ # Draw an arc around the point x and y.
3
+ #
4
+ # Color accepts the following: *Gosu::Color*, *Array* (with 2 colors), or a *Hash* with keys: _from:_ and _to:_ both colors.
5
+ #
6
+ # With a *Gosu::Color* the arc will be painted with color
7
+ #
8
+ # With an *Array* the first *Gosu::Color* with be the innermost color and the last *Gosu::Color* with be the outermost color
9
+ #
10
+ # With a *Hash* the arc will smoothly transition from the start of the arc to the end
11
+ # @example
12
+ # # Using a Hash
13
+ # Gosu.draw_arc(100, 100, 50, 0.5, 128, 4, {from: Gosu::Color::BLUE, to: Gosu::Color::GREEN}, 0, :default)
14
+ #
15
+ # # Using an Array
16
+ # Gosu.draw_arc(100, 100, 50, 0.5, 128, 4, [Gosu::Color::BLUE, Gosu::Color::GREEN], 0, :default)
17
+ #
18
+ # # Using a Gosu::Color
19
+ # Gosu.draw_arc(100, 100, 50, 0.5, 128, 4, Gosu::Color::BLUE, 0, :default)
20
+ #
21
+ #
22
+ # @param x X position.
23
+ # @param y Y position.
24
+ # @param radius radius of arc, in pixels.
25
+ # @param percentage how complete the segment is, _0.0_ is 0% and _1.0_ is 100%.
26
+ # @param segments how many segments for arc, more will appear smoother, less will appear jagged.
27
+ # @param thickness how thick arc will be.
28
+ # @param color [Gosu::Color, Array<Gosu::Color, Gosu::Color>, Hash{from: start_color, to: end_color}] color or colors to draw the arc with.
29
+ # @param z Z position.
30
+ # @param mode blend mode.
31
+ #
32
+ # @note _thickness_ is subtracted from radius, meaning that the arc will grow towards the origin, not away from it.
33
+ #
34
+ # @return [void]
35
+ def self.draw_arc(x, y, radius, percentage = 1.0, segments = 128, thickness = 4, color = Gosu::Color::WHITE, z = 0, mode = :default)
36
+ segments = 360.0 / segments
37
+
38
+ return if percentage == 0.0
39
+
40
+ 0.step((359 * percentage), percentage > 0 ? segments : -segments) do |angle|
41
+ angle2 = angle + segments
42
+
43
+ point_a_left_x = x + Gosu.offset_x(angle, radius - thickness)
44
+ point_a_left_y = y + Gosu.offset_y(angle, radius - thickness)
45
+
46
+ point_a_right_x = x + Gosu.offset_x(angle2, radius - thickness)
47
+ point_a_right_y = y + Gosu.offset_y(angle2, radius - thickness)
48
+
49
+ point_b_left_x = x + Gosu.offset_x(angle, radius)
50
+ point_b_left_y = y + Gosu.offset_y(angle, radius)
51
+
52
+ point_b_right_x = x + Gosu.offset_x(angle2, radius)
53
+ point_b_right_y = y + Gosu.offset_y(angle2, radius)
54
+
55
+ if color.is_a?(Array)
56
+ Gosu.draw_quad(
57
+ point_a_left_x, point_a_left_y, color.first,
58
+ point_b_left_x, point_b_left_y, color.last,
59
+ point_a_right_x, point_a_right_y, color.first,
60
+ point_b_right_x, point_b_right_y, color.last,
61
+ z, mode
62
+ )
63
+ elsif color.is_a?(Hash)
64
+ start_color = color[:from]
65
+ end_color = color[:to]
66
+
67
+ color_a = Gosu::Color.rgba(
68
+ (end_color.red - start_color.red) * (angle / 360.0) + start_color.red,
69
+ (end_color.green - start_color.green) * (angle / 360.0) + start_color.green,
70
+ (end_color.blue - start_color.blue) * (angle / 360.0) + start_color.blue,
71
+ (end_color.alpha - start_color.alpha) * (angle / 360.0) + start_color.alpha,
72
+ )
73
+ color_b = Gosu::Color.rgba(
74
+ (end_color.red - start_color.red) * (angle2 / 360.0) + start_color.red,
75
+ (end_color.green - start_color.green) * (angle2 / 360.0) + start_color.green,
76
+ (end_color.blue - start_color.blue) * (angle2 / 360.0) + start_color.blue,
77
+ (end_color.alpha - start_color.alpha) * (angle2 / 360.0) + start_color.alpha,
78
+ )
79
+
80
+ Gosu.draw_quad(
81
+ point_a_left_x, point_a_left_y, color_a,
82
+ point_b_left_x, point_b_left_y, color_a,
83
+ point_a_right_x, point_a_right_y, color_b,
84
+ point_b_right_x, point_b_right_y, color_b,
85
+ z, mode
86
+ )
87
+ else
88
+ Gosu.draw_quad(
89
+ point_a_left_x, point_a_left_y, color,
90
+ point_b_left_x, point_b_left_y, color,
91
+ point_a_right_x, point_a_right_y, color,
92
+ point_b_right_x, point_b_right_y, color,
93
+ z, mode
94
+ )
95
+ end
96
+ end
97
+ end
95
98
  end
@@ -1,31 +1,31 @@
1
- module Gosu
2
- ##
3
- # Draw a filled circled around point X and Y.
4
- #
5
- # @param x X position.
6
- # @param y Y position.
7
- # @param radius radius of circle, in pixels.
8
- # @param step_size resolution of circle, more steps will apear smoother, less will appear jagged.
9
- # @param color color to draw circle with.
10
- # @param mode blend mode.
11
- #
12
- # @return [void]
13
- def self.draw_circle(x, y, radius, step_size = 36, color = Gosu::Color::WHITE, z = 0, mode = :default)
14
- step_size = (360.0 / step_size).floor
15
-
16
- 0.step(359, step_size) do |angle|
17
- angle2 = angle + step_size
18
-
19
- point_lx = x + Gosu.offset_x(angle, radius)
20
- point_ly = y + Gosu.offset_y(angle, radius)
21
- point_rx = x + Gosu.offset_x(angle2, radius)
22
- point_ry = y + Gosu.offset_y(angle2, radius)
23
-
24
- Gosu.draw_triangle(
25
- point_lx, point_ly, color,
26
- point_rx, point_ry, color,
27
- x, y, color, z, mode
28
- )
29
- end
30
- end
1
+ module Gosu
2
+ ##
3
+ # Draw a filled circled around point X and Y.
4
+ #
5
+ # @param x X position.
6
+ # @param y Y position.
7
+ # @param radius radius of circle, in pixels.
8
+ # @param step_size resolution of circle, more steps will apear smoother, less will appear jagged.
9
+ # @param color color to draw circle with.
10
+ # @param mode blend mode.
11
+ #
12
+ # @return [void]
13
+ def self.draw_circle(x, y, radius, step_size = 36, color = Gosu::Color::WHITE, z = 0, mode = :default)
14
+ step_size = (360.0 / step_size).floor
15
+
16
+ 0.step(359, step_size) do |angle|
17
+ angle2 = angle + step_size
18
+
19
+ point_lx = x + Gosu.offset_x(angle, radius)
20
+ point_ly = y + Gosu.offset_y(angle, radius)
21
+ point_rx = x + Gosu.offset_x(angle2, radius)
22
+ point_ry = y + Gosu.offset_y(angle2, radius)
23
+
24
+ Gosu.draw_triangle(
25
+ point_lx, point_ly, color,
26
+ point_rx, point_ry, color,
27
+ x, y, color, z, mode
28
+ )
29
+ end
30
+ end
31
31
  end
@@ -0,0 +1,17 @@
1
+ module Gosu
2
+ PathNode = Struct.new(:x, :y)
3
+
4
+ def self.draw_path(nodes, color = Gosu::Color::WHITE, z = 0, mode = :default)
5
+ last_node = nodes.first
6
+
7
+ nodes[1..nodes.size - 1].each do |current_node|
8
+ Gosu.draw_line(
9
+ last_node.x, last_node.y, color,
10
+ current_node.x, current_node.y, color,
11
+ z, mode
12
+ )
13
+
14
+ last_node = current_node
15
+ end
16
+ end
17
+ end
@@ -1,3 +1,3 @@
1
- module GosuMoreDrawables
2
- VERSION = "0.2.0"
3
- end
1
+ module GosuMoreDrawables
2
+ VERSION = "0.3.1"
3
+ end
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gosu_more_drawables
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cyberarm
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-26 00:00:00.000000000 Z
11
+ date: 2020-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,11 +66,15 @@ files:
66
66
  - Rakefile
67
67
  - bin/console
68
68
  - bin/setup
69
+ - examples/circle_with_arc_border.rb
70
+ - examples/path_with_circles.rb
69
71
  - gosu_more_drawables.gemspec
70
72
  - lib/gosu_more_drawables.rb
71
73
  - lib/gosu_more_drawables/draw_arc.rb
72
74
  - lib/gosu_more_drawables/draw_circle.rb
75
+ - lib/gosu_more_drawables/draw_path.rb
73
76
  - lib/gosu_more_drawables/version.rb
77
+ - media/screenshot.png
74
78
  homepage: https://github.com/cyberarm/gosu_more_drawables
75
79
  licenses:
76
80
  - MIT
@@ -78,7 +82,8 @@ metadata:
78
82
  allowed_push_host: https://rubygems.org
79
83
  homepage_uri: https://github.com/cyberarm/gosu_more_drawables
80
84
  source_code_uri: https://github.com/cyberarm/gosu_more_drawables
81
- post_install_message:
85
+ documentation_uri: https://rubydoc.info/gems/gosu_more_drawables
86
+ post_install_message:
82
87
  rdoc_options: []
83
88
  require_paths:
84
89
  - lib
@@ -94,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
99
  version: '0'
95
100
  requirements: []
96
101
  rubygems_version: 3.1.2
97
- signing_key:
102
+ signing_key:
98
103
  specification_version: 4
99
104
  summary: Adds circles and arcs to Gosu
100
105
  test_files: []