Add 2D flex pattern

This commit is contained in:
Florian Festi 2016-07-12 16:12:28 +02:00
parent 6c82bb9e32
commit f33f74ab3f
1 changed files with 31 additions and 0 deletions

View File

@ -929,6 +929,37 @@ class Boxes:
self.hole(j*2*w+i*w, i*2*dist, r)
self.hole(j*2*w+i*w, -i*2*dist, r)
def flex2D(self, x, y, width=1):
width *= self.thickness
cx = int(x // (5*width))
wx = x / 5. / cx
cy = int(y // (5*width))
wy = y / 5. / cy
armx = (4*wx, 90, 4*wy, 90, 2*wx, 90, 2*wy)
army = (4*wy, 90, 4*wx, 90, 2*wy, 90, 2*wx)
for i in range(cx):
for j in range(cy):
if (i+j) % 2:
self.ctx.save()
self.moveTo((5*i)*wx, (5*j)*wy)
self.polyline(*armx)
self.ctx.restore()
self.ctx.save()
self.moveTo((5*i+5)*wx, (5*j+5)*wy, -180)
self.polyline(*armx)
self.ctx.restore()
else:
self.ctx.save()
self.moveTo((5*i+5)*wx, (5*j)*wy, 90)
self.polyline(*army)
self.ctx.restore()
self.ctx.save()
self.moveTo((5*i)*wx, (5*j+5)*wy, -90)
self.polyline(*army)
self.ctx.restore()
self.ctx.stroke()
##################################################
### parts
##################################################