#!ruby
class Hexagon
attr_reader :h, :r, :s, :a, :b
def initialize s
@s = s
angle = Math::PI * 30 / 180
@r = (Math.cos(angle) * s).to_int
@h = (Math.sin(angle) * s).to_int
@b = s + 2 * @h
@a = 2 * @r
end
def hex_to_pixel x, y
return (x * 2 * @r + ((y & 1) * @r)), (y * (@h + @s))
end
def mapsize x, y, b
return x * 2 * @r + @r + b, y * (@h + @s) + @h + b
end
def pointset x, y
bx, by = hex_to_pixel x, y
points = [
[bx + @r, by],
[bx + 2 * @r, by + @h],
[bx + 2 * @r, by + @h + @s],
[bx + @r, by + (2 * @h) + @s],
[bx, by + @h + @s],
[bx, by + @h]
]
end
end
a = Hexagon.new 80
sizex, sizey = a.mapsize(10,10,10)
require "GD"
# create a new image
im = GD::Image.new(sizex,sizey)
# allocate some colors
white = im.colorAllocate(255,255,255)
black = im.colorAllocate(0,0,0)
red = im.colorAllocate(255,0,0)
blue = im.colorAllocate(0,0,255)
burlybrown = im.colorAllocate "#DEB887"
goldenrod = im.colorAllocate "#DAA520"
10.times do |x|
10.times do |y|
p = GD::Polygon.new
ps = a.pointset(x,y)
6.times {|i| p.addPt(ps[i][0],ps[i][1])}
p.offset(5, 5)
im.polygon(p, black)
fx, fy = a.hex_to_pixel(x,y)
fx += 2 + 5
fy += 2 + 5 + a.h
case rand 3
when 0
im.fill fx, fy, blue
when 1
im.fill fx, fy, burlybrown
when 2
im.fill fx, fy, goldenrod
end
im.string(GD::Font::GiantFont, fx, fy, "#{x},#{y}", red)
end
end
# make the background transparent and interlaced
im.transparent(white)
im.interlace = true
# Convert the image to PNG and print it on standard output
im.png STDOUT
Well, I found a website that has graph paper available to print for free. It has numerous different types of graph paper too.
Cartesian (standard grids)
Engineering
Polar
Isometric
Logarithmic
Hexagonal
Probability
And smith chart
You can select the size and everything. It's really nifty. The website is http://www.printfreegraphpaper.com check it out.