Commits

Manfred Moitzi committed 1a8b27b

minor edits

Comments (0)

Files changed (2)

examples/checkerboard.py

 # License: GPLv3
 
 import sys
+import os
 
 try:
     import svgwrite
 except ImportError:
-    # if svgwrite is not 'installed' append parent dir of __file__ to sys.path
-    import os
     sys.path.insert(0, os.path.abspath(os.path.split(os.path.abspath(__file__))[0]+'/..'))
 
+import svgwrite
 if svgwrite.version < (1,0,1):
     print("This script requires svgwrite 1.0.1 or newer for internal stylesheets.")
     sys.exit()
 BOARD_HEIGHT = "10cm"
 BOARD_SIZE = (BOARD_WIDTH, BOARD_HEIGHT)
 CSS_STYLES = """
+    .background { fill: lavenderblush; }
     .line { stroke: firebrick; stroke-width: .1mm; }
     .blacksquare { fill: indigo; }
     .whitesquare { fill: hotpink; }
 """
 
 def draw_board(dwg):
-    def draw_lines():
-        lines = dwg.add(dwg.g(class_="line"))
-        for i in range(9):
-            y = i * 10
-            lines.add(dwg.line(start=(0, y), end=(80, y)))
-            x = i * 10
-            lines.add(dwg.line(start=(x, 0), end=(x, 80)))
-
-    def draw_squares():
-        white_squares = dwg.add(dwg.g(class_="whitesquare"))
-        black_squares = dwg.add(dwg.g(class_="blacksquare"))
-        for x in range(8):
-            for y in range (8):
-                xc = x * 10 + 1
-                yc = y * 10 + 1
-                square = dwg.rect(insert=(xc, yc), size=(8, 8))
-                (white_squares if (x+y) % 2 else black_squares).add(square)
-    draw_lines()
-    draw_squares()
-
+    def group(classname):
+        return dwg.add(dwg.g(class_=classname))
+    
+    # setup element groups
+    lines = group("line")
+    white_squares = group("whitesquare")
+    black_squares = group("blacksquare")
+    
+    # draw lines
+    for i in range(9):
+        y = i * 10
+        lines.add(dwg.line(start=(0, y), end=(80, y)))
+        x = i * 10
+        lines.add(dwg.line(start=(x, 0), end=(x, 80)))
+        
+    # draw squares
+    for x in range(8):
+        for y in range(8):
+            xc = x * 10 + 1
+            yc = y * 10 + 1
+            square = dwg.rect(insert=(xc, yc), size=(8, 8))
+            (white_squares if (x+y) % 2 else black_squares).add(square)
 
 def main():
     dwg = svgwrite.Drawing('checkerboard.svg', size=BOARD_SIZE)
 
     # always use css for styling
     dwg.defs.add(dwg.style(CSS_STYLES))
+    
+    # set background
+    dwg.add(dwg.rect(size=('100%','100%'), class_='background'))
     draw_board(dwg)
     dwg.save()
 
 [tox]
-envlist=py27,py32
+envlist=py27,py32,pypy
 
 [testenv]
 downloadcache= ../__cache__
 deps=nose
 commands=nosetests
-[testenv:pypy]
-basepython=c:\pypy-1.8\pypy.exe
 
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.