Fix hexHolesRectangle and add skip param
Use skip param to implement hexHolesCircle
This commit is contained in:
parent
00658341e1
commit
a8dcf02918
1
TODO.txt
1
TODO.txt
|
@ -2,7 +2,6 @@
|
||||||
* Make outer edge continuous even if other parts are drawn intermediately.
|
* Make outer edge continuous even if other parts are drawn intermediately.
|
||||||
* Fix burn compensation for building blocks (especially fingerHolesAt)
|
* Fix burn compensation for building blocks (especially fingerHolesAt)
|
||||||
* Fix hexHoles* (leftoover, grow to space, ...)
|
* Fix hexHoles* (leftoover, grow to space, ...)
|
||||||
* Add hexHolesCircle and may be other shapes
|
|
||||||
* Try out box with fully mixed fF edges and check if all corners work properly
|
* Try out box with fully mixed fF edges and check if all corners work properly
|
||||||
* finish lamp
|
* finish lamp
|
||||||
* make fingerJointSettings depending on thickness?
|
* make fingerJointSettings depending on thickness?
|
||||||
|
|
44
boxes.py
44
boxes.py
|
@ -269,18 +269,44 @@ class Boxes:
|
||||||
self.ctx.arc(-r, 0, r, 0, 2*math.pi)
|
self.ctx.arc(-r, 0, r, 0, 2*math.pi)
|
||||||
self.ctx.restore()
|
self.ctx.restore()
|
||||||
|
|
||||||
def hexHolesRectangle(self, x, y, r, b, style="circle"):
|
def hexHolesRectangle(self, x, y, r, b, style="circle", skip=None):
|
||||||
|
"""
|
||||||
|
Fills a rectangle with holes.
|
||||||
|
r : radius of holes
|
||||||
|
b : space between holes
|
||||||
|
style : what types of holes (not yet implemented)
|
||||||
|
skip : function to check if hole should be present
|
||||||
|
gets x, y, r, b, posx, posy
|
||||||
|
"""
|
||||||
w = r+b/2.0
|
w = r+b/2.0
|
||||||
dist = w * math.cos(math.pi/6.0)
|
dist = w * math.cos(math.pi/6.0)
|
||||||
# XXX leftover
|
|
||||||
cx = int(x // dist) # ???
|
# how many half circles do fit
|
||||||
cy = int(y // dist) # ???
|
cx = int((x-2*r) // (w)) + 2
|
||||||
self.moveTo(dist/2, r)
|
cy = int((y-2*r) // (dist)) + 2
|
||||||
|
|
||||||
|
# what's left on the sides
|
||||||
|
lx = (x - (2*r+(cx-2)*w))/2.0
|
||||||
|
ly = (y - (2*r+(cy-3)*dist))/2.0
|
||||||
|
|
||||||
for i in xrange(cy//2):
|
for i in xrange(cy//2):
|
||||||
for j in xrange(cx):
|
for j in xrange((cx-(i%2))//2):
|
||||||
self.hole(2*j*w, i*4*dist, r)
|
px = 2*j*w + r + lx
|
||||||
for j in xrange(cx-1):
|
py = i*2*dist + r + ly
|
||||||
self.hole(2*j*w+w, i*4*dist + 2*dist, r)
|
if i % 2:
|
||||||
|
px += dist
|
||||||
|
if skip and skip(x, y, r, b, px, py):
|
||||||
|
continue
|
||||||
|
self.hole(px, py, r)
|
||||||
|
|
||||||
|
def __skipcircle(self, x, y, r, b, posx, posy):
|
||||||
|
cx, cy = x/2.0, y/2.0
|
||||||
|
return ((((posx-cx)**2+(posy-cy)**2)**0.5) > (cx-r))
|
||||||
|
|
||||||
|
def hexHolesCircle(self, d, r, b, style="circle"):
|
||||||
|
d2 = d/2.0
|
||||||
|
self.hexHolesRectangle(d, d, r, b, style, self.__skipcircle)
|
||||||
|
|
||||||
|
|
||||||
def hexHolesHex(self, h, r, b, style="circle", grow=None):
|
def hexHolesHex(self, h, r, b, style="circle", grow=None):
|
||||||
self.ctx.rectangle(0, 0, h, h)
|
self.ctx.rectangle(0, 0, h, h)
|
||||||
|
|
8
lamp.py
8
lamp.py
|
@ -20,8 +20,8 @@ class Lamp(Boxes):
|
||||||
self.ctx.save()
|
self.ctx.save()
|
||||||
d = 2*(r+w)
|
d = 2*(r+w)
|
||||||
self.roundedPlate(d, d, r)
|
self.roundedPlate(d, d, r)
|
||||||
self.moveTo(0, 0)
|
self.moveTo(w/2.0, w/2.0)
|
||||||
self.hexHolesHex(2*(r+w), 5, 3, grow='space')
|
self.hexHolesCircle(d-w, 5, 3)
|
||||||
self.ctx.restore()
|
self.ctx.restore()
|
||||||
|
|
||||||
def side(self, r, w, h):
|
def side(self, r, w, h):
|
||||||
|
@ -72,8 +72,8 @@ class Lamp(Boxes):
|
||||||
|
|
||||||
self.moveTo(0, 270)
|
self.moveTo(0, 270)
|
||||||
|
|
||||||
#self.hexHolesHex(200, 20, 5)
|
#self.hexHolesHex(200, 10, 5)
|
||||||
#self.hexHolesRectangle(400, 200, 20, 5)
|
#self.hexHolesRectangle(400, 200, 11, 2)
|
||||||
|
|
||||||
self.ctx.stroke()
|
self.ctx.stroke()
|
||||||
self.surface.flush()
|
self.surface.flush()
|
||||||
|
|
Loading…
Reference in New Issue