Skip to content

Instantly share code, notes, and snippets.

@onitake
Created March 30, 2016 18:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save onitake/78a35293501b03c2dd72c9ab5dede1db to your computer and use it in GitHub Desktop.
Save onitake/78a35293501b03c2dd72c9ab5dede1db to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import sys
import math
import json
steps = 6
if len(sys.argv) > 1:
steps = int(sys.argv[1])
radius = 80.0
if len(sys.argv) > 2:
radius = float(sys.argv[2])
anglestep = math.pi / 2 / steps
points = []
for step in xrange(steps + 1):
angle = anglestep * step
points.append([ math.cos(angle) * radius, math.sin(angle) * radius])
polys = []
for step in xrange(steps):
polys.append([
[ radius, radius ],
[ points[step][0], points[step][1] ],
[ points[step + 1][0], points[step + 1][1] ],
])
polys.append([
[ -radius, radius ],
[ -points[step][0], points[step][1] ],
[ -points[step + 1][0], points[step + 1][1] ],
])
polys.append([
[ radius, -radius ],
[ points[step][0], -points[step][1] ],
[ points[step + 1][0], -points[step + 1][1] ],
])
polys.append([
[ -radius, -radius ],
[ -points[step][0], -points[step][1] ],
[ -points[step + 1][0], -points[step + 1][1] ],
])
print json.dumps({ "default": polys })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment