• API
• FAQ
• Tools
• Archive
SHARE
TWEET  # Alphard a guest Apr 11th, 2015 30 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. """
2. Created on Sun Apr 12 01:22:11 2015
3.
4. @author: Alphard
5. """
6.
7. import math
8. import Image
9. import ImageDraw
10.
11. def hexagonVertices(edge, center):
12.     x, y = center
13.     for angle in range(0, 360, 60):
16.         yield x, y
17.
18. def drawHexagon(draw, vertices, label):
19.     if not label:
20.         label = (150, 150, 150)
21.     draw.polygon(list(vertices), outline='black', fill=label)
22.
23. rows = 30
24. cols = 6
25. offsetX = 25;
26. offsetY = 25;
27. edge = 20;
28.
29. labels = [[0 for x in range(cols)] for x in range(rows)]
30.
31. for k in range(5, 13, 2):
32.     labels[k] = 'red'
33.     labels[k] = 'red'
34.
35. for k in range(4, 12, 2):
36.     labels[k] = 'red'
37.     labels[k] = 'red'
38.     labels[k] = 'red'
39.
40. for k in range(12, 28, 2):
41.     labels[k] = 'green'
42.
43. labels = 'green'
44. labels = 'green'
45. labels = 'green'
46. labels = 'green'
47. labels = 'green'
48. labels = 'green'
49.
50.
51. image = Image.new('RGB', (int(3*edge*cols+2*offsetX), int(edge*rows+2*offsetY)), 'white')
52. draw = ImageDraw.Draw(image)
53.
54. for row in range(rows):
55.     for col in range(cols):
56.         oddOffset = 0 if row%2==1 else 1.5*edge
57.         x = 3*edge*col + oddOffset + offsetX
58.         y = 3**0.5*0.5*edge*row + offsetY
59.         drawHexagon(draw, hexagonVertices(edge, (x, y)), labels[row][col])
60.
61. image.show()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Not a member of Pastebin yet?