Skip to content

Instantly share code, notes, and snippets.

@ciscorn

ciscorn/a5_1.py Secret

Created September 1, 2013 07:05
Show Gist options
  • Save ciscorn/6402796 to your computer and use it in GitHub Desktop.
Save ciscorn/6402796 to your computer and use it in GitHub Desktop.
grid paper generator
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import A4
from reportlab.lib.units import mm
c = canvas.Canvas("hello.pdf", pagesize=A4)
width, height = A4
numv = int((width - ((4 + 4) * mm)) / (5 * mm))
numh = int((height / 2.0 - ((12.5 + 2) * mm)) / (5 * mm))
voff = (width - numv * 5 * mm) / 2.0
hoff = height / 2 - (12.5 + numh * 5) * mm
# Draw grid
c.setLineWidth(0.15)
c.setStrokeColorRGB(0.5, 0.5, 1)
for xi in xrange(numv + 1):
c.line(xi * mm * 5 + voff, hoff,
xi * mm * 5 + voff, hoff + numh * mm * 5)
c.line(xi * mm * 5 + voff, height - hoff,
xi * mm * 5 + voff, height - (hoff + numh * mm * 5))
for yi in xrange(numh + 1):
c.line(voff, hoff + yi * mm * 5,
voff + numv * mm * 5, hoff + yi * mm * 5)
c.line(voff, height - (hoff + yi * mm * 5),
voff + numv * mm * 5, height - (hoff + yi * mm * 5))
# Draw horizontal center
c.setDash(1)
c.setStrokeColorRGB(0.5, 0.5, 1)
c.circle(width / 2, height / 2 + 1.5 * mm, 0.5, fill=1)
c.circle(width / 2, height / 2 - 1.5 * mm, 0.5, fill=1)
# Draw splitter
c.setDash([3, 3])
c.setStrokeColorRGB(0.4, 0.4, 0.4)
c.line(0, height / 2, width, height / 2)
c.save()
from reportlab.pdfgen import canvas
from reportlab.lib.units import mm
OUTPUT = "grid.pdf"
width, height = (181.7 * mm, 256.8 * mm)
GRID_COLOR = (0.5, 0.5, 1)
INTERVAL = 5 * mm
numv = int((width - ((4 + 4) * mm)) / INTERVAL)
numh = int((height - (16 + 3) * mm) / INTERVAL)
voff = (width - numv * INTERVAL) / 2.0
hoff = 16 * mm
# Draw
c = canvas.Canvas(OUTPUT, pagesize=(width, height))
c.setLineWidth(0.15)
c.setStrokeColorRGB(*GRID_COLOR)
for xi in xrange(numv + 1):
c.line(xi * INTERVAL + voff, hoff,
xi * INTERVAL + voff, hoff + numh * INTERVAL)
for yi in xrange(numh + 1):
c.line(voff, hoff + yi * INTERVAL,
voff + numv * INTERVAL, hoff + yi * INTERVAL)
#c.circle(width / 2, 5 * mm, 0.7, fill=1)
c.save()
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import A4
from reportlab.lib.units import mm
width, height = (181.7 * mm, 256.8 * mm)
numv = int((width - ((17 + 4) * mm)) / (5 * mm))
numh = int((height / 2.0 - (5 + 5) * mm) / (5 * mm))
voff = 17 * mm
hoff = (height / 2 - numh * 5 * mm) / 2.0
c = canvas.Canvas("b6.pdf", pagesize=(width, height))
# Draw grid
c.setLineWidth(0.15)
c.setStrokeColorRGB(0.5, 0.5, 1)
for xi in xrange(numv + 1):
c.line(xi * mm * 5 + voff, hoff,
xi * mm * 5 + voff, hoff + numh * mm * 5)
c.line(xi * mm * 5 + voff, height - hoff,
xi * mm * 5 + voff, height - (hoff + numh * mm * 5))
for yi in xrange(numh + 1):
c.line(voff, hoff + yi * mm * 5,
voff + numv * mm * 5, hoff + yi * mm * 5)
c.line(voff, height - (hoff + yi * mm * 5),
voff + numv * mm * 5, height - (hoff + yi * mm * 5))
# Draw horizontal center
c.setDash(1)
c.setStrokeColorRGB(0.5, 0.5, 1)
c.circle(5 * mm, height / 4, 0.5, fill=1)
c.circle(5 * mm, height / 4 * 3, 0.5, fill=1)
# Draw splitter line
c.setDash([3, 3])
c.setStrokeColorRGB(0.4, 0.4, 0.4)
c.line(0, height / 2, width, height / 2)
c.save()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment