Class: PacPdf
- Inherits:
-
Object
- Object
- PacPdf
- Defined in:
- lib/pacpdf.rb,
lib/pacpdf/version.rb
Constant Summary collapse
- GAME_DOTS =
{ 150 => {circles: [{x: 250, r: 20}, 300, 350, 400, 450]}, 200 => {ellipse: 300, circles: [350, 400, 450]}, 250 => {circles: [300, 350, 400, 450]}, 300 => {ellipse: 400, circles: [450]}, 350 => {circles: [400, 450]}, }
- VERSION =
"0.0.3"
Instance Attribute Summary collapse
-
#pdf ⇒ Object
Returns the value of attribute pdf.
Instance Method Summary collapse
- #draw_background(ghost = true) ⇒ Object
- #draw_dots_for(step) ⇒ Object
- #draw_game(count = 1) ⇒ Object
- #draw_pacman_at(x, mouth_open) ⇒ Object
-
#initialize ⇒ PacPdf
constructor
A new instance of PacPdf.
- #save(name = 'pacman.pdf') ⇒ Object
Constructor Details
#initialize ⇒ PacPdf
Returns a new instance of PacPdf.
27 28 29 |
# File 'lib/pacpdf.rb', line 27 def initialize @pdf = PDF::Writer.new(:orientation => :landscape) end |
Instance Attribute Details
#pdf ⇒ Object
Returns the value of attribute pdf.
17 18 19 |
# File 'lib/pacpdf.rb', line 17 def pdf @pdf end |
Instance Method Details
#draw_background(ghost = true) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/pacpdf.rb', line 31 def draw_background(ghost = true) # fill pdf.fill_color Color::RGB::Black pdf.rectangle(0, 0, pdf.page_width, pdf.page_height).fill # Wall pdf.fill_color Color::RGB::Magenta pdf.stroke_color Color::RGB::Cyan pdf.rounded_rectangle(20, 500, 750, 20, 10).close_fill_stroke pdf.rounded_rectangle(20, 200, 750, 20, 10).close_fill_stroke # Ghost if ghost pdf.fill_color Color::RGB::Blue pdf.stroke_color Color::RGB::Cyan pdf.move_to(500, 250) pdf.line_to(500, 425) pdf.curve_to(550, 475, 600, 475, 650, 425) pdf.line_to(650, 250) pdf.line_to(625, 275) pdf.line_to(600, 250) pdf.line_to(575, 275) pdf.line_to(550, 250) pdf.line_to(525, 275) pdf.line_to(500, 250).fill_stroke pdf.fill_color Color::RGB::White pdf.rectangle(525, 375, 25, 25).fill pdf.rectangle(575, 375, 25, 25).fill pdf.fill_color Color::RGB::Black pdf.rectangle(525, 375, 10, 10).fill pdf.rectangle(575, 375, 10, 10).fill end end |
#draw_dots_for(step) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/pacpdf.rb', line 74 def draw_dots_for(step) unless GAME_DOTS[step].nil? pdf.fill_color Color::RGB::Yellow GAME_DOTS[step][:circles].each do |opts| unless opts.is_a?(Hash) opts = {x: opts, r: 10} end pdf.circle_at(opts[:x], 350, opts[:r]).fill_stroke end unless GAME_DOTS[step][:ellipse].nil? pdf.ellipse2_at(GAME_DOTS[step][:ellipse], 350, 10, 10, 95, -95) end end end |
#draw_game(count = 1) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/pacpdf.rb', line 89 def draw_game(count = 1) count.times do |inc| pdf.start_new_page unless inc == 0 mouth_open = true (150..600).step(50) do |x| pdf.start_new_page unless x == 150 draw_background((x < 550)) draw_pacman_at(x, mouth_open) draw_dots_for(x) mouth_open = !mouth_open end end self end |
#draw_pacman_at(x, mouth_open) ⇒ Object
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/pacpdf.rb', line 63 def draw_pacman_at(x, mouth_open) # Body pdf.fill_color Color::RGB::Yellow pdf.stroke_color Color::RGB::Black pdf.circle_at(x, 350, 100).fill_stroke if mouth_open == true pdf.fill_color Color::RGB::Black pdf.segment_at(x, 350, 100, 100, 30, -30).close_fill_stroke end end |
#save(name = 'pacman.pdf') ⇒ Object
104 105 106 |
# File 'lib/pacpdf.rb', line 104 def save(name = 'pacman.pdf') pdf.save_as(name) end |