diff --git a/boxes.py b/boxes.py index 65a168a..922de22 100755 --- a/boxes.py +++ b/boxes.py @@ -3,6 +3,8 @@ import cairo import math +def dist(dx, dy): + return (dx*dx+dy*dy)**0.5 class Boxes: @@ -301,12 +303,25 @@ class Boxes: 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)) + return (dist(posx-cx, posy-cy) > (cx-r)) def hexHolesCircle(self, d, r, b, style="circle"): d2 = d/2.0 self.hexHolesRectangle(d, d, r, b, style, self.__skipcircle) + def hexHolesPlate(self, x, y, er, r, b, style='circle'): + def skip(x, y, r, b, posx, posy): + posx = abs(posx-(x/2.0)) + posy = abs(posy-(y/2.0)) + + wx = 0.5*x-er-r + wy = 0.5*y-er-r + + if (posx <= wx) or (posy <= wx): + return 0 + return dist(posx-wx, posy-wy) > er + + self.hexHolesRectangle(x, y, r, b, style, skip=skip) def hexHolesHex(self, h, r, b, style="circle", grow=None): self.ctx.rectangle(0, 0, h, h) diff --git a/lamp.py b/lamp.py index 72fa813..413f69e 100755 --- a/lamp.py +++ b/lamp.py @@ -21,7 +21,7 @@ class Lamp(Boxes): d = 2*(r+w) self.roundedPlate(d, d, r) self.moveTo(w/2.0, w/2.0) - self.hexHolesCircle(d-w, 5, 3) + self.hexHolesPlate(d-w, d-w, r-w/2.0, 5, 3) self.ctx.restore() def render(self, r, w):