Created
June 23, 2019 22:20
-
-
Save tmikeschu/6baf0dd856617ef6b8fabf5661449c0e to your computer and use it in GitHub Desktop.
A fun little script I made to translate svgs polygon points from sketch to my inline implementations
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
#!/usr/bin/env ruby | |
def pbcopy(s) | |
IO.popen("pbcopy", "w") { |f| f << s } | |
end | |
def translate(x_offset, y_offset, raw_xys) | |
raw_xys | |
.strip | |
.split("\n") | |
.map { |pair| | |
pair | |
.strip | |
.split(/[,\s]/) | |
.map(&:to_i) | |
} | |
.map { |(x, y)| [x + x_offset, y + y_offset].join(",") } | |
.join("\n") | |
end | |
if ARGV.length < 3 | |
puts "Too few arguments" | |
exit | |
end | |
x, y, raw = ARGV | |
result = translate(x.to_i, y.to_i, raw) | |
pbcopy(result) | |
puts result | |
puts "\nCopied to clipboard :)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment