Advertisement
gwilliams

isometric graph paper generator

Nov 20th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.83 KB | None | 0 0
  1. # -*- coding: UTF-8 -*-
  2. import math
  3. import sys
  4.  
  5. from reportlab.lib.units import inch
  6.  
  7. LIB_DIR = './lib'
  8. if not LIB_DIR in sys.path:
  9.     sys.path.insert(0, LIB_DIR)
  10.  
  11. import PDF
  12.  
  13. pdf = PDF.PDF('graph_paper.pdf', page_orientation = PDF.PageOrientation.Portrait)
  14.  
  15. margin = 0.25 * inch
  16.  
  17. spacing = 0.25 * inch
  18. spacing2 = 0.5 * math.sqrt(3) * spacing
  19.  
  20. hmargin = 0.5 * math.fmod(pdf.page_width, spacing2)
  21. vmargin = 0.5 * math.fmod(pdf.page_height, spacing)
  22.  
  23. epsilon = 0.25
  24.  
  25. for col in range(int(pdf.page_width / spacing2) + 1):
  26.     x = hmargin + col * spacing2
  27.  
  28.     for row in range(int(pdf.page_height / spacing) + 1):
  29.         if col & 1 == 1:
  30.             y = pdf.page_height - vmargin - row * spacing
  31.         else:
  32.             y = pdf.page_height - vmargin - (row + 0.5) * spacing
  33.  
  34.         pdf.ellipse(x-epsilon, y-epsilon, x+epsilon, y+epsilon, fill = 1)
  35.  
  36.  
  37. pdf.save()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement