Draw rim and lid

This commit is contained in:
Matthias Neeracher 2021-11-24 04:51:25 +01:00
parent 144f6d951e
commit bcf34f8976

View File

@ -44,8 +44,11 @@ args.radius = args.hole/2
args.corner = args.corner_length*args.thickness args.corner = args.corner_length*args.thickness
args.corner_s = args.corner*args.stretch args.corner_s = args.corner*args.stretch
args.corner_radius = 3*args.corner_s/math.pi args.corner_radius = 3*args.corner_s/math.pi
args.plug_radius = args.corner_radius-args.thickness
args.corner_inset = args.corner_s*math.sqrt(3)/math.pi args.corner_inset = args.corner_s*math.sqrt(3)/math.pi
args.plug_inset = args.plug_radius/math.sqrt(3)
args.interior_edge = args.grid*args.dimension*0.5+args.outside_padding args.interior_edge = args.grid*args.dimension*0.5+args.outside_padding
args.plug_edge = args.interior_edge-args.thickness
args.exterior_edge = args.interior_edge+2.0*args.thickness args.exterior_edge = args.interior_edge+2.0*args.thickness
args.interior_leg = (args.interior_edge-args.horizontal_finger-args.kerf)/2-args.corner_inset args.interior_leg = (args.interior_edge-args.horizontal_finger-args.kerf)/2-args.corner_inset
finger_length = args.interior_edge-2.0*args.corner_inset finger_length = args.interior_edge-2.0*args.corner_inset
@ -60,11 +63,12 @@ if args.verbose:
print(args, file=sys.stderr) print(args, file=sys.stderr)
DIMX = 5.0*args.grid*args.dimension DIMX = 5.0*args.grid*args.dimension
DIMY = 3.0*args.grid*args.dimension DIMY = 2.5*args.grid*args.dimension+args.height+3.0*args.thickness
PI3 = math.pi/3 PI3 = math.pi/3
HOLES = '' HOLES = ''
SHAPES = '' SHAPES = ''
MARKS = ''
def draw_grid(cx, cy): def draw_grid(cx, cy):
global HOLES global HOLES
@ -75,17 +79,19 @@ def draw_grid(cx, cy):
for col in range(num_col): for col in range(num_col):
HOLES += '<circle cx="%.2f" cy="%.2f" r="%.2f"/>\n' % (cxr+col*args.grid, cyr, args.radius) HOLES += '<circle cx="%.2f" cy="%.2f" r="%.2f"/>\n' % (cxr+col*args.grid, cyr, args.radius)
def draw_plane(cx, cy, interior=False): def draw_plane(cx, cy, layer):
global HOLES, SHAPES global HOLES, SHAPES, MARKS
if interior: if layer=='interior':
edge = args.interior_edge edge = args.interior_edge
elif layer=='plug' or layer=='plug_mark':
edge = args.plug_edge
else: else:
edge = args.exterior_edge edge = args.exterior_edge
turtle = svgturtle.SvgTurtle(cx, cy) turtle = svgturtle.SvgTurtle(cx, cy)
turtle.penup() turtle.penup()
turtle.forward(edge) turtle.forward(edge)
turtle.right(120) turtle.right(120)
if interior: if layer=='interior':
turtle.forward(args.corner_inset) turtle.forward(args.corner_inset)
turtle.pendown() turtle.pendown()
for side in range(5): for side in range(5):
@ -99,17 +105,28 @@ def draw_plane(cx, cy, interior=False):
turtle.left(90) turtle.left(90)
turtle.forward(args.interior_leg) turtle.forward(args.interior_leg)
turtle.circle(-args.corner_radius, 60) turtle.circle(-args.corner_radius, 60)
turtle.forward(args.interior_edge-2.0*args.corner_inset) turtle.forward(edge-2.0*args.corner_inset)
turtle.circle(-args.corner_radius, 60) turtle.circle(-args.corner_radius, 60)
elif layer=='plug' or layer=='plug_mark':
turtle.forward(args.plug_inset)
turtle.pendown()
for side in range(6):
turtle.forward(edge-2.0*args.plug_inset)
turtle.circle(-args.plug_radius, 60)
else: else:
turtle.pendown() turtle.pendown()
for side in range(6): for side in range(6):
turtle.forward(args.exterior_edge) turtle.forward(edge)
turtle.right(60) turtle.right(60)
SHAPES += '<path d="%s"/>\n' % turtle.to_s() if layer=='plug':
if not interior: HOLES += '<path d="%s"/>\n' % turtle.to_s()
turtle.reset() elif layer=='plug_mark':
turtle.penup() MARKS += '<path d="%s"/>\n' % turtle.to_s()
else:
SHAPES += '<path d="%s"/>\n' % turtle.to_s()
turtle.reset()
turtle.penup()
if layer=='bottom' or layer=='rim':
turtle.forward(args.interior_edge) turtle.forward(args.interior_edge)
turtle.right(120) turtle.right(120)
turtle.forward(args.corner_inset) turtle.forward(args.corner_inset)
@ -273,10 +290,14 @@ def draw_case(x0, y0, h, slots):
print('<svg viewBox="0 0 %.2f %.2f" width="%.2fmm" height="%.2fmm" stroke-width="0.1" xmlns="http://www.w3.org/2000/svg">' % (DIMX, DIMY, DIMX, DIMY)) print('<svg viewBox="0 0 %.2f %.2f" width="%.2fmm" height="%.2fmm" stroke-width="0.1" xmlns="http://www.w3.org/2000/svg">' % (DIMX, DIMY, DIMX, DIMY))
draw_grid(0.65*args.grid*args.dimension, 0.60*args.grid*args.dimension) draw_grid(0.65*args.grid*args.dimension, 0.60*args.grid*args.dimension)
draw_plane(0.65*args.grid*args.dimension, 0.60*args.grid*args.dimension, True) draw_plane(0.65*args.grid*args.dimension, 0.60*args.grid*args.dimension, 'interior')
draw_grid(1.90*args.grid*args.dimension, 0.60*args.grid*args.dimension) draw_grid(1.90*args.grid*args.dimension, 0.60*args.grid*args.dimension)
draw_plane(1.90*args.grid*args.dimension, 0.60*args.grid*args.dimension, True) draw_plane(1.90*args.grid*args.dimension, 0.60*args.grid*args.dimension, 'interior')
draw_plane(3.15*args.grid*args.dimension, 0.60*args.grid*args.dimension) draw_plane(3.15*args.grid*args.dimension, 0.60*args.grid*args.dimension, 'bottom')
draw_case(0.05*args.grid*args.dimension, 1.25*args.grid*args.dimension, args.height, args.slots) draw_plane(0.65*args.grid*args.dimension, 1.70*args.grid*args.dimension, 'rim')
print('<g fill="none" stroke="red">', HOLES, '</g>', '<g fill="none" stroke="black">', SHAPES, '</g>', sep='\n') draw_plane(0.65*args.grid*args.dimension, 1.70*args.grid*args.dimension, 'plug')
draw_plane(2.00*args.grid*args.dimension, 1.70*args.grid*args.dimension, 'lid')
draw_plane(2.00*args.grid*args.dimension, 1.70*args.grid*args.dimension, 'plug_mark')
draw_case(0.05*args.grid*args.dimension, 2.30*args.grid*args.dimension, args.height, args.slots)
print('<g fill="none" stroke="red">', HOLES, '</g>', '<g fill="none" stroke="blue">', MARKS, '</g>', '<g fill="none" stroke="black">', SHAPES, '</g>', sep='\n')
print('</svg>') print('</svg>')