Created
November 11, 2011 13:36
-
-
Save michiakig/1358015 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'RMagick' | |
import Magick | |
if(ARGV.length < 2) | |
puts "call with image filename and gcode filename" | |
exit(1) | |
end | |
XSTEP = 5 | |
YSTEP = 5 | |
ZSTEP = 10 | |
img = Image.read(ARGV[0]) | |
pixels = img.export_pixels | |
scanlines = pixels.each_slice(img.columns).to_a | |
File.open(ARGV[1]) do |f| | |
f.puts('G28') # zero | |
f.puts('G91') # set to relative positioning | |
scanlines.each do |line| | |
line.each do |px| | |
if(not_white(px)) | |
f.puts("G1 Z-#{ZSTEP}") # lower pen | |
f.puts("G1 Z#{ZSTEP}") # raise pen | |
end | |
f.puts("G1 X#{XSTEP}") # move to next px | |
end | |
f.puts("G1 Y#{YSTEP}") # move to next lime | |
f.puts('G28 X0') # zero X | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment