Module: RQRCode::Export::Gerber
- Defined in:
- lib/rqrcode/export/gerber.rb
Instance Attribute Summary collapse
-
#mirrored ⇒ Object
Returns the value of attribute mirrored.
-
#pixel_width ⇒ Object
Returns the value of attribute pixel_width.
-
#positive ⇒ Object
Returns the value of attribute positive.
-
#precision ⇒ Object
Returns the value of attribute precision.
-
#quiet_zone_size ⇒ Object
Returns the value of attribute quiet_zone_size.
-
#x_origin ⇒ Object
Returns the value of attribute x_origin.
-
#y_origin ⇒ Object
Returns the value of attribute y_origin.
Instance Method Summary collapse
- #as_gerber(options = {}) ⇒ Object
-
#flash(x, y) ⇒ Object
Returns a string of the QR code as characters writen with ANSI background set.
- #is_light(x, y) ⇒ Object
Instance Attribute Details
#mirrored ⇒ Object
Returns the value of attribute mirrored.
4 5 6 |
# File 'lib/rqrcode/export/gerber.rb', line 4 def mirrored @mirrored end |
#pixel_width ⇒ Object
Returns the value of attribute pixel_width.
4 5 6 |
# File 'lib/rqrcode/export/gerber.rb', line 4 def pixel_width @pixel_width end |
#positive ⇒ Object
Returns the value of attribute positive.
4 5 6 |
# File 'lib/rqrcode/export/gerber.rb', line 4 def positive @positive end |
#precision ⇒ Object
Returns the value of attribute precision.
4 5 6 |
# File 'lib/rqrcode/export/gerber.rb', line 4 def precision @precision end |
#quiet_zone_size ⇒ Object
Returns the value of attribute quiet_zone_size.
4 5 6 |
# File 'lib/rqrcode/export/gerber.rb', line 4 def quiet_zone_size @quiet_zone_size end |
#x_origin ⇒ Object
Returns the value of attribute x_origin.
4 5 6 |
# File 'lib/rqrcode/export/gerber.rb', line 4 def x_origin @x_origin end |
#y_origin ⇒ Object
Returns the value of attribute y_origin.
4 5 6 |
# File 'lib/rqrcode/export/gerber.rb', line 4 def y_origin @y_origin end |
Instance Method Details
#as_gerber(options = {}) ⇒ Object
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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/rqrcode/export/gerber.rb', line 37 def as_gerber(={}) = { precision: 6, pixel_width: 0.010, # inches x_origin: 0.000, # inches y_origin: 0.000, # inches quiet_zone_size: 1, mirrored: false }.merge() @x_origin = .fetch(:x_origin) @y_origin = .fetch(:y_origin) @precision = .fetch(:precision) @pixel_width = .fetch(:pixel_width) @quiet_zone_size = .fetch(:quiet_zone_size) @mirrored = .fetch(:mirrored) @p_mult = 10**[:precision] output="G04 This is an RQRCode Generated gerber file.*\nG04 --End of header info--*\n%MOIN*%\n%FSLAX3\#{options[:precision]}Y3\#{options[:precision]}*%\n%IPPOS*%\n%ADD10R,\#{options[:pixel_width]}X\#{options[:pixel_width]}*%\nG04 --Start main section--*\nG54D10*\n EOF\n\n quiet_zone_size = options.fetch(:quiet_zone_size)\n\n width = quiet_zone_size + @module_count + quiet_zone_size\n\n quiet_zone_size.times do |r|\n width.times do |c|\n output << flash(c,r) ## Top Quiet Zone\n output << flash(r,c) ## Left Quiet Zone\n output << flash(r+quiet_zone_size+@module_count,c)\n output << flash(c,r+quiet_zone_size+@module_count)\n end\n end\n\n\n @modules.each_index do |r|\n @modules[r].each_index do |c|\n if is_light(r, c)\n output << flash(quiet_zone_size+c,quiet_zone_size+r)\n end\n end\n end\n\n output << \"M02*\\n\"\n\n return output\nend\n" |
#flash(x, y) ⇒ Object
Returns a string of the QR code as characters writen with ANSI background set.
Options: light: Foreground (“033[47m”) dark: Background ANSI code. (“033[47m”) fill_character: The written character. (‘ ’) quiet_zone_size: (4)
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rqrcode/export/gerber.rb', line 15 def flash(x,y) top_y = (@module_count + (@quiet_zone_size *2 )) * @pixel_width y = top_y - (y * @pixel_width) if @mirrored then right_x = (@module_count + (@quiet_zone_size*2)) * @pixel_width x = right_x - (x * @pixel_width) else x = x * @pixel_width end x += (@x_origin) y += (@y_origin) y = (y * @p_mult).to_i x = (x * @p_mult).to_i return "G01X#{x}Y#{y}D03*\n" end |
#is_light(x, y) ⇒ Object
33 34 35 |
# File 'lib/rqrcode/export/gerber.rb', line 33 def is_light(x,y) ! is_dark(x,y) end |