mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2025-12-16 05:02:34 +00:00
Update Gosu.draw_arc to support partial segments
This commit is contained in:
@@ -33,12 +33,23 @@ module Gosu
|
|||||||
#
|
#
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def self.draw_arc(x, y, radius, percentage = 1.0, segments = 128, thickness = 4, color = Gosu::Color::WHITE, z = 0, mode = :default)
|
def self.draw_arc(x, y, radius, percentage = 1.0, segments = 128, thickness = 4, color = Gosu::Color::WHITE, z = 0, mode = :default)
|
||||||
segments = 360.0 / segments
|
|
||||||
|
|
||||||
return if percentage == 0.0
|
return if percentage == 0.0
|
||||||
|
|
||||||
0.step((359 * percentage), percentage > 0 ? segments : -segments) do |angle|
|
angle_per_segment = 360.0 / segments
|
||||||
angle2 = angle + segments
|
arc_completion = 360 * percentage
|
||||||
|
next_segment_angle = angle_per_segment
|
||||||
|
|
||||||
|
angle = 0
|
||||||
|
loop do
|
||||||
|
break if angle >= arc_completion
|
||||||
|
|
||||||
|
if angle + angle_per_segment > arc_completion
|
||||||
|
next_segment_angle = arc_completion - angle
|
||||||
|
else
|
||||||
|
next_segment_angle = angle_per_segment
|
||||||
|
end
|
||||||
|
|
||||||
|
angle2 = angle + next_segment_angle
|
||||||
|
|
||||||
point_a_left_x = x + Gosu.offset_x(angle, radius - thickness)
|
point_a_left_x = x + Gosu.offset_x(angle, radius - thickness)
|
||||||
point_a_left_y = y + Gosu.offset_y(angle, radius - thickness)
|
point_a_left_y = y + Gosu.offset_y(angle, radius - thickness)
|
||||||
@@ -93,6 +104,8 @@ module Gosu
|
|||||||
z, mode
|
z, mode
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
angle += next_segment_angle
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Reference in New Issue
Block a user