Mercurial > lasercutter
view graster/graster/bin/gtile @ 11:f952052e37b7
trying a fix.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Tue, 24 Aug 2010 19:06:45 -0400 |
parents | |
children |
line wrap: on
line source
1 #!/usr/bin/env ruby -rubygems2 # Tokyo cache cow command line interface script.3 # Run <tt>tokyo_cache_cow -h</tt> to get more usage.4 require File.dirname(__FILE__) + '/../lib/graster'6 unless ARGV.size == 57 puts "usage: ruby tile.rb <input-gcode-file> <tile-width> <tile-height> <horiz-count> <vert-count>"8 exit(1)9 end11 def parse_line line12 nc = {}13 line.gsub(/\([^)]*\)/,'').upcase.scan(/([A-Z])\s*([0-9\.]+)?/).each {|code| nc[code[0].intern] = (code[1] && code[1].to_f) }14 nc15 end17 def gcode ncs18 ncs = [ncs] unless ncs.is_a? Array19 ncs.reduce('') {|a,nc| a << (nc.map {|k,v| "#{k}#{v}" }.join(' ') + "\n") }20 end22 tile_width = ARGV[1].to_f23 tile_height = ARGV[2].to_f24 horiz_count = ARGV[3].to_i25 vert_count = ARGV[4].to_i27 header = []28 body = []29 footer = []30 state = :header33 File.open ARGV[0] do |io|34 io.each_line do |line|35 if (nc = parse_line(line)) != {}36 case state37 when :header38 if nc[:G] == 0 || nc[:G] == 139 state = :body40 body << nc41 else42 header << nc43 end45 when :body46 if nc[:G] == 0 || nc[:G] == 147 body << nc48 else49 state = :footer50 footer << nc51 end53 when :footer54 footer << nc55 end56 end # case58 end # io.each_line59 end # File.open61 print gcode(header)63 vert_count.times do |yc|64 horiz_count.times do |xc|65 body.each do |nc|66 nc = nc.dup67 nc[:X] += xc*tile_width if nc[:X]68 nc[:Y] += yc*tile_height if nc[:Y]69 print gcode(nc)70 end71 end72 end74 print gcode(footer)