79 lines
2.7 KiB
Python
79 lines
2.7 KiB
Python
#!/usr/bin/env python3
|
|
|
|
import math
|
|
from pathlib import Path
|
|
import webbrowser
|
|
|
|
from gerbonara.utils import setup_svg, Tag, MM, rotate_point
|
|
import click
|
|
|
|
@click.command()
|
|
@click.option('--steps', type=int, default=4)
|
|
@click.option('--mesh-thickness', type=float, default=1.6)
|
|
@click.option('--offset', type=float, default=10)
|
|
@click.option('--mesh-space', type=float, default=3)
|
|
@click.option('--mesh-width', type=float, default=15)
|
|
@click.option('--start', type=click.Choice(['center', 'offset']))
|
|
@click.option('--initial-radius', type=float, default=14)
|
|
@click.argument('out_svg', type=click.Path(dir_okay=False, path_type=Path))
|
|
def cli(out_svg, mesh_thickness, offset, mesh_space, mesh_width, start, initial_radius, steps):
|
|
tags = []
|
|
|
|
circle = lambda pt, r, c, w=0.2: Tag('circle', stroke=c, fill='none', stroke_width=w, cx=pt[0], cy=pt[1], r=r)
|
|
|
|
current_radius = initial_radius
|
|
|
|
def ring(pt, c):
|
|
nonlocal current_radius
|
|
|
|
c_line = c.format(100)
|
|
c_area = c.format(30)
|
|
|
|
r1 = current_radius
|
|
r2 = math.hypot(mesh_width/2, r1 + mesh_thickness)
|
|
|
|
tags.append(circle(pt, (r1+r2)/2, c_area, r2-r1))
|
|
tags.append(circle(pt, r1, c_line))
|
|
tags.append(circle(pt, r2, c_line))
|
|
|
|
px, py = pt
|
|
tags.append(Tag('rect', x=px + r1, y=py-mesh_width/2, width=mesh_thickness, height=mesh_width,
|
|
fill=c_line))
|
|
tags.append(Tag('rect', x=px - r1 - mesh_thickness, y=py-mesh_width/2, width=mesh_thickness, height=mesh_width,
|
|
fill=c_line))
|
|
|
|
current_radius = r2
|
|
|
|
crosshairs = lambda pt, s=3: Tag('path', fill='none', stroke_width=0.4, stroke='black',
|
|
d=f'M {pt[0]-s},{pt[1]} h {2*s} m {-s},{s} v {-2*s}')
|
|
|
|
current_point = (0, 0)
|
|
next_point = (offset, 0)
|
|
|
|
tags.append(crosshairs(current_point))
|
|
tags.append(crosshairs(next_point))
|
|
|
|
current_color = 'hsl(0 80% 50% / {}%)'
|
|
next_color = 'hsl(240 80% 50% / {}%)'
|
|
|
|
if start == 'offset':
|
|
current_point, next_point = next_point, current_point
|
|
current_color, next_color = next_color, current_color
|
|
|
|
#if (r := offset - mesh_space - initial_radius) > 0:
|
|
# ring(next_point, next_color)
|
|
|
|
for i in range(steps):
|
|
print(f'Radius at step {i}: {current_radius:.2f} mm')
|
|
ring(current_point, current_color)
|
|
current_radius += mesh_space + offset
|
|
|
|
current_point, next_point = next_point, current_point
|
|
current_color, next_color = next_color, current_color
|
|
|
|
r_max = current_radius + offset
|
|
out_svg.write_text(str(setup_svg(tags, bounds=((-r_max, -r_max), (+r_max, +r_max)), margin=3)))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
cli()
|