diff --git a/battery-case-generator.py b/battery-case-generator.py index 4e0a1ae..1b7b0e9 100755 --- a/battery-case-generator.py +++ b/battery-case-generator.py @@ -44,8 +44,11 @@ args.radius = args.hole/2 args.corner = args.corner_length*args.thickness args.corner_s = args.corner*args.stretch 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.plug_inset = args.plug_radius/math.sqrt(3) 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.interior_leg = (args.interior_edge-args.horizontal_finger-args.kerf)/2-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) 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 HOLES = '' SHAPES = '' +MARKS = '' def draw_grid(cx, cy): global HOLES @@ -75,17 +79,19 @@ def draw_grid(cx, cy): for col in range(num_col): HOLES += '\n' % (cxr+col*args.grid, cyr, args.radius) -def draw_plane(cx, cy, interior=False): - global HOLES, SHAPES - if interior: +def draw_plane(cx, cy, layer): + global HOLES, SHAPES, MARKS + if layer=='interior': edge = args.interior_edge + elif layer=='plug' or layer=='plug_mark': + edge = args.plug_edge else: edge = args.exterior_edge turtle = svgturtle.SvgTurtle(cx, cy) turtle.penup() turtle.forward(edge) turtle.right(120) - if interior: + if layer=='interior': turtle.forward(args.corner_inset) turtle.pendown() for side in range(5): @@ -99,17 +105,28 @@ def draw_plane(cx, cy, interior=False): turtle.left(90) turtle.forward(args.interior_leg) 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) + 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: turtle.pendown() for side in range(6): - turtle.forward(args.exterior_edge) + turtle.forward(edge) turtle.right(60) - SHAPES += '\n' % turtle.to_s() - if not interior: - turtle.reset() - turtle.penup() + if layer=='plug': + HOLES += '\n' % turtle.to_s() + elif layer=='plug_mark': + MARKS += '\n' % turtle.to_s() + else: + SHAPES += '\n' % turtle.to_s() + turtle.reset() + turtle.penup() + if layer=='bottom' or layer=='rim': turtle.forward(args.interior_edge) turtle.right(120) turtle.forward(args.corner_inset) @@ -273,10 +290,14 @@ def draw_case(x0, y0, h, slots): print('' % (DIMX, DIMY, DIMX, DIMY)) 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_plane(1.90*args.grid*args.dimension, 0.60*args.grid*args.dimension, True) -draw_plane(3.15*args.grid*args.dimension, 0.60*args.grid*args.dimension) -draw_case(0.05*args.grid*args.dimension, 1.25*args.grid*args.dimension, args.height, args.slots) -print('', HOLES, '', '', SHAPES, '', sep='\n') +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, 'bottom') +draw_plane(0.65*args.grid*args.dimension, 1.70*args.grid*args.dimension, 'rim') +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('', HOLES, '', '', MARKS, '', '', SHAPES, '', sep='\n') print('')