Potentially useful code snippets
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.1 KiB

import svgwrite
from svgwrite import cm,mm
from math import cos,sin,pi
'''
https://stackoverflow.com/questions/13006601/setting-default-units-in-svg-python-svgwrite
'''
drawring = svgwrite.Drawing('test.svg', profile='tiny', size=('17cm', '13cm'), viewBox=('0 0 17 13'))
''' You need size and viewBox. Why I don't know, also formatting is insane'''
x=[]
y=[]
N=6
r=2
print(cm)
for n in range(N):
x.append( (r * cos(2*pi*n/N)+7) )
y.append( (r * sin(2*pi*n/N)+7) )
z=list(zip(x,y))
def polycoord(sides,radius,cenx=0,ceny=0,unit='cm'):
x=[]
y=[]
for n in range(sides):
x.append( str((r *cos(2*pi*n/sides)+(sides+1))) + cenx)
y.append( str((r *sin(2*pi*n/sides)+(sides+1))) + ceny)
z=list(zip(x,y))
return z
'''
print(x,y)
print(z)
point=list(zip([xp*cm for xp in x],[yp*cm for yp in y]))
print(point)
'''
hex=drawring.polygon(points=z, stroke='green',fill='yellow', id='hex1',stroke_width='.1')
'''
hex=drawring.polygon(points=[(9,7),(8, 8.732050807568877),(6,8.732050807568879),(5, 7),(6, 5.267949192431123),(8, 5.267949192431123)] ,stroke='green',id='hex1',stroke_width=3)
'''
drawring.add(hex)
drawring.save()