Created
August 14, 2011 21:17
-
-
Save rngtng/1145322 to your computer and use it in GitHub Desktop.
Cutpath for LED table parts
This file contains 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 'prawn' | |
require 'prawn/measurement_extensions' | |
@width = 550.mm | |
@height = 50.mm | |
@extra_height = 35.mm | |
@cols_width = 5.mm | |
@cols_height = 26.mm | |
@set_width = 35.mm | |
@set_trap_width = 3.mm | |
@offset = @height + @extra_height | |
def reset(x, y) | |
[@x = x, @y = y] | |
end | |
def go(w, h, flip = false) | |
h = -h if flip | |
[@x += w, @y += h] | |
end | |
def bar(pdf, boxes, offset = 0, flip = false) | |
space_width = (@width - (boxes - 1) * @cols_width) / boxes.to_f | |
points = [] | |
points << reset(0, offset) | |
boxes.times do |i| | |
if i > 0 | |
points << go(@cols_width, 0, flip) | |
end | |
points << go(@set_width, 0, flip) | |
points << go(@set_trap_width, @set_trap_width, flip) | |
points << go(space_width - 2 * (@set_width + @set_trap_width), 0, flip) | |
points << go(@set_trap_width, -@set_trap_width, flip) | |
points << go(@set_width, 0, flip) | |
end | |
points << go(0, @height, flip) | |
boxes.times do |i| | |
if i > 0 | |
points << go(0, -@cols_height, flip) | |
points << go(-@cols_width, 0, flip) | |
points << go(0, @cols_height, flip) | |
end | |
points << go(-space_width, 0, flip) | |
end | |
pdf.polygon *points | |
end | |
def bar1(pdf, boxes, offset = 0, flip = false) | |
space_width = (@width - (boxes - 1) * @cols_width) / boxes.to_f | |
points = [] | |
points << reset(0, offset) | |
boxes.times do |i| | |
if i > 0 | |
points << go(0, @cols_height, flip) | |
points << go(@cols_width, 0, flip) | |
points << go(0, -@cols_height, flip) | |
end | |
points << go(@set_width, 0, flip) | |
points << go(@set_trap_width, @set_trap_width, flip) | |
points << go(space_width - 2 * (@set_width + @set_trap_width), 0, flip) | |
points << go(@set_trap_width, -@set_trap_width, flip) | |
points << go(@set_width, 0, flip) | |
end | |
points << go(0, @height, flip) | |
points << go(-@width, 0, flip) | |
pdf.polygon *points | |
end | |
Prawn::Document.generate('table.pdf', :page_size => [24.in, 18.in]) do |pdf| | |
pdf.stroke do | |
bar1(pdf, 5, 0 * @height) | |
bar1(pdf, 5, 2 * @height, true) | |
bar1(pdf, 5, 2 * @height) | |
bar(pdf, 4, 4 * @height, true) | |
bar(pdf, 4, 4 * @height) | |
bar(pdf, 4, 6 * @height, true) | |
bar(pdf, 4, 6 * @height) | |
end | |
=begin | |
pdf.start_new_page | |
pdf.stroke do | |
height = @height + @extra_height | |
width = @width + @cols_width | |
4.times do |i| | |
pdf.rectangle [0, @offset + i * height], width, height | |
end | |
end | |
=end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment