Add hexHolesPlate
This commit is contained in:
parent
4705135755
commit
7fe2c37a9c
17
boxes.py
17
boxes.py
|
@ -3,6 +3,8 @@
|
||||||
import cairo
|
import cairo
|
||||||
import math
|
import math
|
||||||
|
|
||||||
|
def dist(dx, dy):
|
||||||
|
return (dx*dx+dy*dy)**0.5
|
||||||
|
|
||||||
class Boxes:
|
class Boxes:
|
||||||
|
|
||||||
|
@ -301,12 +303,25 @@ class Boxes:
|
||||||
|
|
||||||
def __skipcircle(self, x, y, r, b, posx, posy):
|
def __skipcircle(self, x, y, r, b, posx, posy):
|
||||||
cx, cy = x/2.0, y/2.0
|
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"):
|
def hexHolesCircle(self, d, r, b, style="circle"):
|
||||||
d2 = d/2.0
|
d2 = d/2.0
|
||||||
self.hexHolesRectangle(d, d, r, b, style, self.__skipcircle)
|
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):
|
def hexHolesHex(self, h, r, b, style="circle", grow=None):
|
||||||
self.ctx.rectangle(0, 0, h, h)
|
self.ctx.rectangle(0, 0, h, h)
|
||||||
|
|
2
lamp.py
2
lamp.py
|
@ -21,7 +21,7 @@ class Lamp(Boxes):
|
||||||
d = 2*(r+w)
|
d = 2*(r+w)
|
||||||
self.roundedPlate(d, d, r)
|
self.roundedPlate(d, d, r)
|
||||||
self.moveTo(w/2.0, w/2.0)
|
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()
|
self.ctx.restore()
|
||||||
|
|
||||||
def render(self, r, w):
|
def render(self, r, w):
|
||||||
|
|
Loading…
Reference in New Issue