Module: D_Circle
- Included in:
- Dinraal
- Defined in:
- app/lib/dinraal/circle.rb
Instance Method Summary collapse
-
#circle(options = {}) ⇒ Array
Create a filled
circle. -
#circle_outline(options = {}) ⇒ Array
Creates the outline of a
circle.
Instance Method Details
#circle(options = {}) ⇒ Array
Create a filled circle.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/lib/dinraal/circle.rb', line 14 def circle( = {}) x = [:x] y = [:y] radius = [:radius] diameter = radius * 2 r = [:r].nil? ? 0 : [:r] g = [:g].nil? ? 0 : [:g] b = [:b].nil? ? 0 : [:b] a = [:a].nil? ? 255 : [:a] lines = [] diameter.times do |i| h = i - radius l = Math.sqrt((radius * radius) - (h * h)) lines << { x: x + i, y: y + radius - l, x2: x + i, y2: y + radius + l }.line!(r: r, g: g, b: b, a: a) end lines end |
#circle_outline(options = {}) ⇒ Array
Creates the outline of a circle .
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/lib/dinraal/circle.rb', line 46 def circle_outline( = {}) x = [:x] y = [:y] radius = [:radius] r = [:r] g = [:g] b = [:b] a = [:a] pixels = [] angle = 0 while angle < 360 new_pixel = point_at_distance_angle(point: { x: x, y: y }, distance: radius, angle: angle) new_pixel[:x] = new_pixel[:x].floor new_pixel[:y] = new_pixel[:y].floor possible_pixel = { x: new_pixel[:x], y: new_pixel[:y], w: 1, h: 1, r: r, g: g, b: b, a: a }.solid! pixels << possible_pixel unless pixels.include?(possible_pixel) angle += 1 end pixels end |