Skip to content

Instantly share code, notes, and snippets.

@nicktimko
Created September 28, 2025 04:04
Show Gist options
  • Select an option

  • Save nicktimko/6084819537adc46068c7ecd8f7d2ab2c to your computer and use it in GitHub Desktop.

Select an option

Save nicktimko/6084819537adc46068c7ecd8f7d2ab2c to your computer and use it in GitHub Desktop.
Drawing Screws
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "ec88692f-e512-4d1b-8a7b-2a3d548ab8b4",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"60\" height=\"60\"><circle stroke=\"red\" stroke-width=\"5\" cx=\"30\" cy=\"30\" r=\"20\" fill=\"white\"/></svg>"
],
"text/plain": [
"SVG(clip_rule=None, cursor=None, display=None, filter=None, pointer_events=None, color=None, color_interpolation=None, onfocusin=None, onfocusout=None, onactivate=None, onclick=None, onmousedown=None, onmouseup=None, onmouseover=None, onmousemove=None, onmouseout=None, onload=None, elements=[Circle(stroke='red', stroke_dasharray=None, stroke_dashoffset=None, stroke_opacity=None, stroke_width=5, clip_rule=None, cursor=None, display=None, filter=None, pointer_events=None, onfocusin=None, onfocusout=None, onactivate=None, onclick=None, onmousedown=None, onmouseup=None, onmouseover=None, onmousemove=None, onmouseout=None, onload=None, color=None, color_interpolation=None, pathLength=None, paint_order=None, shape_rendering=None, class_=None, vector_effect=None, visibility=None, mask=None, opacity=None, clip_path=None, elements=None, text=None, id=None, tabindex=None, lang=None, transform_origin=None, style=None, data=None, extra=None, externalResourcesRequired=None, transform=None, cx=30, cy=30, r=20, marker_mid=None, fill_opacity=None, fill='white')], text=None, id=None, tabindex=None, lang=None, transform_origin=None, style=None, data=None, extra=None, xmlns='http://www.w3.org/2000/svg', viewBox=None, preserveAspectRatio=None, x=None, y=None, width=60, height=60, class_=None, mask=None, opacity=None, clip_path=None, overflow=None, onunload=None, onabort=None, onerror=None, onresize=None, onscroll=None, onzoom=None)"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import math\n",
"\n",
"import svg\n",
"canvas = svg.SVG(\n",
" width=60,\n",
" height=60,\n",
" elements=[\n",
" svg.Circle(\n",
" cx=30, cy=30, r=20,\n",
" stroke=\"red\",\n",
" fill=\"white\",\n",
" stroke_width=5,\n",
" ),\n",
" ],\n",
")\n",
"canvas"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "5977e3d3-fbaf-41f1-b134-b37d745cec5c",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"350\" height=\"350\"><g transform=\"translate(200 120) rotate(45)\"><g transform=\"translate(0 50)\"><path stroke=\"black\" stroke-width=\"10\" d=\"M -27.5 0 L 27.5 0 M -27.5 20 L 27.5 20 M -27.5 40 L 27.5 40 M -27.5 60 L 27.5 60 M -27.5 80 L 27.5 80 M -27.5 100 L 27.5 100 M -27.5 120 L 27.5 120 M -27.5 140 L 27.5 140\" stroke-linecap=\"square\" fill=\"none\"/><path stroke=\"black\" stroke-width=\"10\" d=\"M -22.5 -30 L -22.5 150 L -12.5 160 L 12.5 160 L 22.5 150 L 22.5 -30 M 27.5 -50 L 27.5 -30 L -27.5 -30 L -27.5 -50\" stroke-linecap=\"square\" fill=\"none\"/></g><g transform=\"rotate(180)\"><path stroke=\"black\" stroke-width=\"10\" d=\"M 0 0 L 50.0 0 L 50.0 50 a 10 10 90 0 1 -10 10 L 0 60\" stroke-linecap=\"square\" fill=\"none\"/><path stroke=\"black\" stroke-width=\"10\" transform=\"scale(-1 1)\" d=\"M 0 0 L 50.0 0 L 50.0 50 a 10 10 90 0 1 -10 10 L 0 60\" stroke-linecap=\"square\" fill=\"none\"/><path stroke=\"black\" stroke-width=\"10\" d=\"M 30.0 20 L 30.0 40\" stroke-linecap=\"square\" fill=\"none\"/></g></g><g transform=\"translate(240 250)\"><g><circle stroke=\"black\" stroke-width=\"10\" cx=\"0\" cy=\"0\" r=\"50.0\" fill=\"none\"/><path stroke=\"black\" stroke-width=\"10\" d=\"M 25.0 0.0 L 12.500000000000004 21.650635094610966 L -12.499999999999996 21.65063509461097 L -25.0 3.061616997868383e-15 L -12.50000000000001 -21.65063509461096 L 12.500000000000004 -21.650635094610966 Z \" stroke-linecap=\"rounded\" fill=\"none\"/></g></g></svg>"
],
"text/plain": [
"SVG(clip_rule=None, cursor=None, display=None, filter=None, pointer_events=None, color=None, color_interpolation=None, onfocusin=None, onfocusout=None, onactivate=None, onclick=None, onmousedown=None, onmouseup=None, onmouseover=None, onmousemove=None, onmouseout=None, onload=None, elements=[G(stroke=None, stroke_dasharray=None, stroke_dashoffset=None, stroke_opacity=None, stroke_width=None, clip_rule=None, cursor=None, display=None, filter=None, pointer_events=None, color=None, color_interpolation=None, onfocusin=None, onfocusout=None, onactivate=None, onclick=None, onmousedown=None, onmouseup=None, onmouseover=None, onmousemove=None, onmouseout=None, onload=None, elements=[G(stroke=None, stroke_dasharray=None, stroke_dashoffset=None, stroke_opacity=None, stroke_width=None, clip_rule=None, cursor=None, display=None, filter=None, pointer_events=None, color=None, color_interpolation=None, onfocusin=None, onfocusout=None, onactivate=None, onclick=None, onmousedown=None, onmouseup=None, onmouseover=None, onmousemove=None, onmouseout=None, onload=None, elements=[Path(stroke='black', stroke_dasharray=None, stroke_dashoffset=None, stroke_opacity=None, stroke_width=10, clip_rule=None, cursor=None, display=None, filter=None, pointer_events=None, onfocusin=None, onfocusout=None, onactivate=None, onclick=None, onmousedown=None, onmouseup=None, onmouseover=None, onmousemove=None, onmouseout=None, onload=None, color=None, color_interpolation=None, pathLength=None, paint_order=None, shape_rendering=None, class_=None, vector_effect=None, visibility=None, mask=None, opacity=None, clip_path=None, elements=None, text=None, id=None, tabindex=None, lang=None, transform_origin=None, style=None, data=None, extra=None, externalResourcesRequired=None, transform=None, d=[MoveTo(x=-27.5, y=0), LineTo(x=27.5, y=0), MoveTo(x=-27.5, y=20), LineTo(x=27.5, y=20), MoveTo(x=-27.5, y=40), LineTo(x=27.5, y=40), MoveTo(x=-27.5, y=60), LineTo(x=27.5, y=60), MoveTo(x=-27.5, y=80), LineTo(x=27.5, y=80), MoveTo(x=-27.5, y=100), LineTo(x=27.5, y=100), MoveTo(x=-27.5, y=120), LineTo(x=27.5, y=120), MoveTo(x=-27.5, y=140), LineTo(x=27.5, y=140)], marker_start=None, marker_mid=None, marker_end=None, stroke_linecap='square', stroke_linejoin=None, stroke_miterlimit=None, fill_rule=None, fill_opacity=None, fill='none'), Path(stroke='black', stroke_dasharray=None, stroke_dashoffset=None, stroke_opacity=None, stroke_width=10, clip_rule=None, cursor=None, display=None, filter=None, pointer_events=None, onfocusin=None, onfocusout=None, onactivate=None, onclick=None, onmousedown=None, onmouseup=None, onmouseover=None, onmousemove=None, onmouseout=None, onload=None, color=None, color_interpolation=None, pathLength=None, paint_order=None, shape_rendering=None, class_=None, vector_effect=None, visibility=None, mask=None, opacity=None, clip_path=None, elements=None, text=None, id=None, tabindex=None, lang=None, transform_origin=None, style=None, data=None, extra=None, externalResourcesRequired=None, transform=None, d=[MoveTo(x=-22.5, y=-30), LineTo(x=-22.5, y=150), LineTo(x=-12.5, y=160), LineTo(x=12.5, y=160), LineTo(x=22.5, y=150), LineTo(x=22.5, y=-30), MoveTo(x=27.5, y=-50), LineTo(x=27.5, y=-30), LineTo(x=-27.5, y=-30), LineTo(x=-27.5, y=-50)], marker_start=None, marker_mid=None, marker_end=None, stroke_linecap='square', stroke_linejoin=None, stroke_miterlimit=None, fill_rule=None, fill_opacity=None, fill='none')], text=None, id=None, tabindex=None, lang=None, transform_origin=None, style=None, data=None, extra=None, transform=[Translate(x=0, y=50)], class_=None, mask=None, opacity=None, clip_path=None, fill_rule=None, fill_opacity=None, fill=None), G(stroke=None, stroke_dasharray=None, stroke_dashoffset=None, stroke_opacity=None, stroke_width=None, clip_rule=None, cursor=None, display=None, filter=None, pointer_events=None, color=None, color_interpolation=None, onfocusin=None, onfocusout=None, onactivate=None, onclick=None, onmousedown=None, onmouseup=None, onmouseover=None, onmousemove=None, onmouseout=None, onload=None, elements=[Path(stroke='black', stroke_dasharray=None, stroke_dashoffset=None, stroke_opacity=None, stroke_width=10, clip_rule=None, cursor=None, display=None, filter=None, pointer_events=None, onfocusin=None, onfocusout=None, onactivate=None, onclick=None, onmousedown=None, onmouseup=None, onmouseover=None, onmousemove=None, onmouseout=None, onload=None, color=None, color_interpolation=None, pathLength=None, paint_order=None, shape_rendering=None, class_=None, vector_effect=None, visibility=None, mask=None, opacity=None, clip_path=None, elements=None, text=None, id=None, tabindex=None, lang=None, transform_origin=None, style=None, data=None, extra=None, externalResourcesRequired=None, transform=None, d=[MoveTo(x=0, y=0), LineTo(x=50.0, y=0), LineTo(x=50.0, y=50), ArcRel(rx=10, ry=10, angle=90, large_arc=0, sweep=1, dx=-10, dy=10), LineTo(x=0, y=60)], marker_start=None, marker_mid=None, marker_end=None, stroke_linecap='square', stroke_linejoin=None, stroke_miterlimit=None, fill_rule=None, fill_opacity=None, fill='none'), Path(stroke='black', stroke_dasharray=None, stroke_dashoffset=None, stroke_opacity=None, stroke_width=10, clip_rule=None, cursor=None, display=None, filter=None, pointer_events=None, onfocusin=None, onfocusout=None, onactivate=None, onclick=None, onmousedown=None, onmouseup=None, onmouseover=None, onmousemove=None, onmouseout=None, onload=None, color=None, color_interpolation=None, pathLength=None, paint_order=None, shape_rendering=None, class_=None, vector_effect=None, visibility=None, mask=None, opacity=None, clip_path=None, elements=None, text=None, id=None, tabindex=None, lang=None, transform_origin=None, style=None, data=None, extra=None, externalResourcesRequired=None, transform=[Scale(x=-1, y=1)], d=[MoveTo(x=0, y=0), LineTo(x=50.0, y=0), LineTo(x=50.0, y=50), ArcRel(rx=10, ry=10, angle=90, large_arc=0, sweep=1, dx=-10, dy=10), LineTo(x=0, y=60)], marker_start=None, marker_mid=None, marker_end=None, stroke_linecap='square', stroke_linejoin=None, stroke_miterlimit=None, fill_rule=None, fill_opacity=None, fill='none'), Path(stroke='black', stroke_dasharray=None, stroke_dashoffset=None, stroke_opacity=None, stroke_width=10, clip_rule=None, cursor=None, display=None, filter=None, pointer_events=None, onfocusin=None, onfocusout=None, onactivate=None, onclick=None, onmousedown=None, onmouseup=None, onmouseover=None, onmousemove=None, onmouseout=None, onload=None, color=None, color_interpolation=None, pathLength=None, paint_order=None, shape_rendering=None, class_=None, vector_effect=None, visibility=None, mask=None, opacity=None, clip_path=None, elements=None, text=None, id=None, tabindex=None, lang=None, transform_origin=None, style=None, data=None, extra=None, externalResourcesRequired=None, transform=None, d=[MoveTo(x=30.0, y=20), LineTo(x=30.0, y=40)], marker_start=None, marker_mid=None, marker_end=None, stroke_linecap='square', stroke_linejoin=None, stroke_miterlimit=None, fill_rule=None, fill_opacity=None, fill='none')], text=None, id=None, tabindex=None, lang=None, transform_origin=None, style=None, data=None, extra=None, transform=[Rotate(a=180, x=None, y=None)], class_=None, mask=None, opacity=None, clip_path=None, fill_rule=None, fill_opacity=None, fill=None)], text=None, id=None, tabindex=None, lang=None, transform_origin=None, style=None, data=None, extra=None, transform=[Translate(x=200, y=120), Rotate(a=45, x=None, y=None)], class_=None, mask=None, opacity=None, clip_path=None, fill_rule=None, fill_opacity=None, fill=None), G(stroke=None, stroke_dasharray=None, stroke_dashoffset=None, stroke_opacity=None, stroke_width=None, clip_rule=None, cursor=None, display=None, filter=None, pointer_events=None, color=None, color_interpolation=None, onfocusin=None, onfocusout=None, onactivate=None, onclick=None, onmousedown=None, onmouseup=None, onmouseover=None, onmousemove=None, onmouseout=None, onload=None, elements=[G(stroke=None, stroke_dasharray=None, stroke_dashoffset=None, stroke_opacity=None, stroke_width=None, clip_rule=None, cursor=None, display=None, filter=None, pointer_events=None, color=None, color_interpolation=None, onfocusin=None, onfocusout=None, onactivate=None, onclick=None, onmousedown=None, onmouseup=None, onmouseover=None, onmousemove=None, onmouseout=None, onload=None, elements=[Circle(stroke='black', stroke_dasharray=None, stroke_dashoffset=None, stroke_opacity=None, stroke_width=10, clip_rule=None, cursor=None, display=None, filter=None, pointer_events=None, onfocusin=None, onfocusout=None, onactivate=None, onclick=None, onmousedown=None, onmouseup=None, onmouseover=None, onmousemove=None, onmouseout=None, onload=None, color=None, color_interpolation=None, pathLength=None, paint_order=None, shape_rendering=None, class_=None, vector_effect=None, visibility=None, mask=None, opacity=None, clip_path=None, elements=None, text=None, id=None, tabindex=None, lang=None, transform_origin=None, style=None, data=None, extra=None, externalResourcesRequired=None, transform=None, cx=0, cy=0, r=50.0, marker_mid=None, fill_opacity=None, fill='none'), Path(stroke='black', stroke_dasharray=None, stroke_dashoffset=None, stroke_opacity=None, stroke_width=10, clip_rule=None, cursor=None, display=None, filter=None, pointer_events=None, onfocusin=None, onfocusout=None, onactivate=None, onclick=None, onmousedown=None, onmouseup=None, onmouseover=None, onmousemove=None, onmouseout=None, onload=None, color=None, color_interpolation=None, pathLength=None, paint_order=None, shape_rendering=None, class_=None, vector_effect=None, visibility=None, mask=None, opacity=None, clip_path=None, elements=None, text=None, id=None, tabindex=None, lang=None, transform_origin=None, style=None, data=None, extra=None, externalResourcesRequired=None, transform=None, d=[MoveTo(x=25.0, y=0.0), LineTo(x=12.500000000000004, y=21.650635094610966), LineTo(x=-12.499999999999996, y=21.65063509461097), LineTo(x=-25.0, y=3.061616997868383e-15), LineTo(x=-12.50000000000001, y=-21.65063509461096), LineTo(x=12.500000000000004, y=-21.650635094610966), ClosePath()], marker_start=None, marker_mid=None, marker_end=None, stroke_linecap='rounded', stroke_linejoin=None, stroke_miterlimit=None, fill_rule=None, fill_opacity=None, fill='none')], text=None, id=None, tabindex=None, lang=None, transform_origin=None, style=None, data=None, extra=None, transform=None, class_=None, mask=None, opacity=None, clip_path=None, fill_rule=None, fill_opacity=None, fill=None)], text=None, id=None, tabindex=None, lang=None, transform_origin=None, style=None, data=None, extra=None, transform=[Translate(x=240, y=250)], class_=None, mask=None, opacity=None, clip_path=None, fill_rule=None, fill_opacity=None, fill=None)], text=None, id=None, tabindex=None, lang=None, transform_origin=None, style=None, data=None, extra=None, xmlns='http://www.w3.org/2000/svg', viewBox=None, preserveAspectRatio=None, x=None, y=None, width=350, height=350, class_=None, mask=None, opacity=None, clip_path=None, overflow=None, onunload=None, onabort=None, onerror=None, onresize=None, onscroll=None, onzoom=None)"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"line_width = LW = 10\n",
"\n",
"thread_width = 5.5 * LW\n",
"n_threads = 8\n",
"\n",
"shank_width = thread_width - 1 * LW\n",
"shank_length = n_threads * 2 * LW\n",
"shank_chamfer = 1 * LW\n",
"shank_above_threads = 3 * LW\n",
"unthreaded_shank_width = shank_width + LW\n",
"unthreaded_shank_length = 2 * LW\n",
"\n",
"threads = []\n",
"for n in range(n_threads):\n",
" threads.extend([\n",
" svg.MoveTo(-thread_width/2, n * line_width * 2), \n",
" svg.LineTo(thread_width/2, n * line_width * 2),\n",
" ])\n",
"\n",
"shank = [\n",
" svg.MoveTo(-shank_width/2, -shank_above_threads),\n",
" svg.LineTo(-shank_width/2, shank_length - shank_chamfer),\n",
" svg.LineTo(-shank_width/2 + shank_chamfer, shank_length),\n",
" svg.LineTo(shank_width/2 - shank_chamfer, shank_length),\n",
" svg.LineTo(shank_width/2, shank_length - shank_chamfer),\n",
" svg.LineTo(shank_width/2, -shank_above_threads),\n",
"]\n",
"if unthreaded_shank_length:\n",
" shank.extend([\n",
" svg.MoveTo(unthreaded_shank_width/2, -shank_above_threads-unthreaded_shank_length),\n",
" svg.LineTo(unthreaded_shank_width/2, -shank_above_threads),\n",
" svg.LineTo(-unthreaded_shank_width/2, -shank_above_threads),\n",
" svg.LineTo(-unthreaded_shank_width/2, -shank_above_threads-unthreaded_shank_length),\n",
" ])\n",
"\n",
"below_head = svg.G(\n",
" elements=[\n",
" svg.Path(\n",
" fill=\"none\",\n",
" stroke=\"black\",\n",
" stroke_width=line_width,\n",
" stroke_linecap=\"square\",\n",
" d=threads,\n",
" ),\n",
" svg.Path(\n",
" fill=\"none\",\n",
" stroke=\"black\",\n",
" stroke_width=line_width,\n",
" stroke_linecap=\"square\",\n",
" d=shank,\n",
" ),\n",
" ],\n",
" transform=[svg.Translate(0, shank_above_threads + unthreaded_shank_length)],\n",
")\n",
"\n",
"cap_head_height = 6 * LW\n",
"cap_head_width = 10 * LW\n",
"cap_head_top_fillet = 1 * LW\n",
"# hex_head = \n",
"cap_head = [\n",
" svg.MoveTo(0, 0),\n",
" svg.LineTo(cap_head_width/2, 0),\n",
" svg.LineTo(cap_head_width/2, cap_head_height - cap_head_top_fillet),\n",
" svg.ArcRel(cap_head_top_fillet, cap_head_top_fillet, 90, 0, 1, -cap_head_top_fillet, cap_head_top_fillet),\n",
" svg.LineTo(0, cap_head_height),\n",
"]\n",
"cap_head_detail = [\n",
" svg.MoveTo(cap_head_width/2 - line_width * 2, line_width * 2),\n",
" svg.LineTo(cap_head_width/2 - line_width * 2, cap_head_height - line_width * 2),\n",
"]\n",
"\n",
"head_strokes = cap_head\n",
"head_detail = cap_head_detail\n",
"head = svg.G(\n",
" elements=[\n",
" svg.Path(\n",
" fill=\"none\",\n",
" stroke=\"black\",\n",
" stroke_width=line_width,\n",
" stroke_linecap=\"square\",\n",
" d=head_strokes,\n",
" ),\n",
" svg.Path(\n",
" fill=\"none\",\n",
" stroke=\"black\",\n",
" stroke_width=line_width,\n",
" stroke_linecap=\"square\",\n",
" d=head_strokes,\n",
" transform=[svg.Scale(-1, 1)]\n",
" ),\n",
" svg.Path(\n",
" fill=\"none\",\n",
" stroke=\"black\",\n",
" stroke_width=line_width,\n",
" stroke_linecap=\"square\",\n",
" d=head_detail,\n",
" ),\n",
" ],\n",
" transform=[svg.Rotate(180)],\n",
")\n",
"cap_hex_dia = 5 * line_width\n",
"cap_hex_rad = cap_hex_dia / 2\n",
"cap_hex_points = []\n",
"for n in range(6):\n",
" if n == 0:\n",
" op = svg.MoveTo\n",
" else:\n",
" op = svg.LineTo\n",
" cap_hex_points.append(op(cap_hex_rad * math.cos(n * math.pi / 3), cap_hex_rad * math.sin(n * math.pi / 3)))\n",
"cap_hex_points.append(svg.ClosePath())\n",
" \n",
"cap_top_view = svg.G(\n",
" elements=[\n",
" svg.Circle(\n",
" cx=0, cy=0, \n",
" r=(cap_head_width/2),\n",
" stroke=\"black\",\n",
" fill=\"none\",\n",
" stroke_width=line_width,\n",
" ),\n",
" svg.Path(\n",
" stroke=\"black\",\n",
" fill=\"none\",\n",
" stroke_linecap=\"rounded\",\n",
" stroke_width=line_width,\n",
" d=cap_hex_points,\n",
" )\n",
" ],\n",
")\n",
"\n",
"top_view = cap_top_view\n",
"\n",
"svg.SVG(\n",
" height=350,\n",
" width=350,\n",
" # viewBox=svg.ViewBoxSpec(0, 0, 250, 150),\n",
" elements=[\n",
" svg.G(\n",
" elements=[\n",
" below_head,\n",
" head\n",
" ],\n",
" transform=[svg.Translate(200, 120), svg.Rotate(45)],\n",
" ),\n",
" svg.G(\n",
" elements=[top_view],\n",
" transform=[svg.Translate(240, 250)],\n",
" )\n",
" ]\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "c8df2e2f-5892-4648-87e2-42dbb93c4b47",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"350\" height=\"350\"><g transform=\"translate(200 120) rotate(45) scale(10 10)\"><g transform=\"translate(0 5)\"><path stroke=\"black\" stroke-width=\"1\" d=\"M -2.75 0 L 2.75 0 M -2.75 2 L 2.75 2 M -2.75 4 L 2.75 4 M -2.75 6 L 2.75 6 M -2.75 8 L 2.75 8 M -2.75 10 L 2.75 10 M -2.75 12 L 2.75 12 M -2.75 14 L 2.75 14\" stroke-linecap=\"square\" fill=\"none\"/><path stroke=\"black\" stroke-width=\"1\" d=\"M -2.25 -3 L -2.25 15 L -1.25 16 L 1.25 16 L 2.25 15 L 2.25 -3 M 2.75 -5 L 2.75 -3 L -2.75 -3 L -2.75 -5\" stroke-linecap=\"square\" fill=\"none\"/></g><g transform=\"rotate(180)\"><path stroke=\"black\" stroke-width=\"1\" d=\"M 0 0 L 5.0 0 L 5.0 5 a 1 1 90 0 1 -1 1 L 0 6\" stroke-linecap=\"square\" fill=\"none\"/><path stroke=\"black\" stroke-width=\"1\" transform=\"scale(-1 1)\" d=\"M 0 0 L 5.0 0 L 5.0 5 a 1 1 90 0 1 -1 1 L 0 6\" stroke-linecap=\"square\" fill=\"none\"/><path stroke=\"black\" stroke-width=\"1\" d=\"M 3.0 2 L 3.0 4\" stroke-linecap=\"square\" fill=\"none\"/></g></g><g transform=\"translate(240 250) scale(10 10)\"><g><circle stroke=\"black\" stroke-width=\"1\" cx=\"0\" cy=\"0\" r=\"5.0\" fill=\"none\"/><path stroke=\"black\" stroke-width=\"1\" d=\"M 2.5 0.0 L 1.2500000000000002 2.1650635094610964 L -1.2499999999999996 2.165063509461097 L -2.5 3.061616997868383e-16 L -1.250000000000001 -2.165063509461096 L 1.2500000000000002 -2.1650635094610964 Z \" stroke-linecap=\"rounded\" fill=\"none\"/></g></g></svg>"
],
"text/plain": [
"SVG(clip_rule=None, cursor=None, display=None, filter=None, pointer_events=None, color=None, color_interpolation=None, onfocusin=None, onfocusout=None, onactivate=None, onclick=None, onmousedown=None, onmouseup=None, onmouseover=None, onmousemove=None, onmouseout=None, onload=None, elements=[G(stroke=None, stroke_dasharray=None, stroke_dashoffset=None, stroke_opacity=None, stroke_width=None, clip_rule=None, cursor=None, display=None, filter=None, pointer_events=None, color=None, color_interpolation=None, onfocusin=None, onfocusout=None, onactivate=None, onclick=None, onmousedown=None, onmouseup=None, onmouseover=None, onmousemove=None, onmouseout=None, onload=None, elements=[G(stroke=None, stroke_dasharray=None, stroke_dashoffset=None, stroke_opacity=None, stroke_width=None, clip_rule=None, cursor=None, display=None, filter=None, pointer_events=None, color=None, color_interpolation=None, onfocusin=None, onfocusout=None, onactivate=None, onclick=None, onmousedown=None, onmouseup=None, onmouseover=None, onmousemove=None, onmouseout=None, onload=None, elements=[Path(stroke='black', stroke_dasharray=None, stroke_dashoffset=None, stroke_opacity=None, stroke_width=1, clip_rule=None, cursor=None, display=None, filter=None, pointer_events=None, onfocusin=None, onfocusout=None, onactivate=None, onclick=None, onmousedown=None, onmouseup=None, onmouseover=None, onmousemove=None, onmouseout=None, onload=None, color=None, color_interpolation=None, pathLength=None, paint_order=None, shape_rendering=None, class_=None, vector_effect=None, visibility=None, mask=None, opacity=None, clip_path=None, elements=None, text=None, id=None, tabindex=None, lang=None, transform_origin=None, style=None, data=None, extra=None, externalResourcesRequired=None, transform=None, d=[MoveTo(x=-2.75, y=0), LineTo(x=2.75, y=0), MoveTo(x=-2.75, y=2), LineTo(x=2.75, y=2), MoveTo(x=-2.75, y=4), LineTo(x=2.75, y=4), MoveTo(x=-2.75, y=6), LineTo(x=2.75, y=6), MoveTo(x=-2.75, y=8), LineTo(x=2.75, y=8), MoveTo(x=-2.75, y=10), LineTo(x=2.75, y=10), MoveTo(x=-2.75, y=12), LineTo(x=2.75, y=12), MoveTo(x=-2.75, y=14), LineTo(x=2.75, y=14)], marker_start=None, marker_mid=None, marker_end=None, stroke_linecap='square', stroke_linejoin=None, stroke_miterlimit=None, fill_rule=None, fill_opacity=None, fill='none'), Path(stroke='black', stroke_dasharray=None, stroke_dashoffset=None, stroke_opacity=None, stroke_width=1, clip_rule=None, cursor=None, display=None, filter=None, pointer_events=None, onfocusin=None, onfocusout=None, onactivate=None, onclick=None, onmousedown=None, onmouseup=None, onmouseover=None, onmousemove=None, onmouseout=None, onload=None, color=None, color_interpolation=None, pathLength=None, paint_order=None, shape_rendering=None, class_=None, vector_effect=None, visibility=None, mask=None, opacity=None, clip_path=None, elements=None, text=None, id=None, tabindex=None, lang=None, transform_origin=None, style=None, data=None, extra=None, externalResourcesRequired=None, transform=None, d=[MoveTo(x=-2.25, y=-3), LineTo(x=-2.25, y=15), LineTo(x=-1.25, y=16), LineTo(x=1.25, y=16), LineTo(x=2.25, y=15), LineTo(x=2.25, y=-3), MoveTo(x=2.75, y=-5), LineTo(x=2.75, y=-3), LineTo(x=-2.75, y=-3), LineTo(x=-2.75, y=-5)], marker_start=None, marker_mid=None, marker_end=None, stroke_linecap='square', stroke_linejoin=None, stroke_miterlimit=None, fill_rule=None, fill_opacity=None, fill='none')], text=None, id=None, tabindex=None, lang=None, transform_origin=None, style=None, data=None, extra=None, transform=[Translate(x=0, y=5)], class_=None, mask=None, opacity=None, clip_path=None, fill_rule=None, fill_opacity=None, fill=None), G(stroke=None, stroke_dasharray=None, stroke_dashoffset=None, stroke_opacity=None, stroke_width=None, clip_rule=None, cursor=None, display=None, filter=None, pointer_events=None, color=None, color_interpolation=None, onfocusin=None, onfocusout=None, onactivate=None, onclick=None, onmousedown=None, onmouseup=None, onmouseover=None, onmousemove=None, onmouseout=None, onload=None, elements=[Path(stroke='black', stroke_dasharray=None, stroke_dashoffset=None, stroke_opacity=None, stroke_width=1, clip_rule=None, cursor=None, display=None, filter=None, pointer_events=None, onfocusin=None, onfocusout=None, onactivate=None, onclick=None, onmousedown=None, onmouseup=None, onmouseover=None, onmousemove=None, onmouseout=None, onload=None, color=None, color_interpolation=None, pathLength=None, paint_order=None, shape_rendering=None, class_=None, vector_effect=None, visibility=None, mask=None, opacity=None, clip_path=None, elements=None, text=None, id=None, tabindex=None, lang=None, transform_origin=None, style=None, data=None, extra=None, externalResourcesRequired=None, transform=None, d=[MoveTo(x=0, y=0), LineTo(x=5.0, y=0), LineTo(x=5.0, y=5), ArcRel(rx=1, ry=1, angle=90, large_arc=0, sweep=1, dx=-1, dy=1), LineTo(x=0, y=6)], marker_start=None, marker_mid=None, marker_end=None, stroke_linecap='square', stroke_linejoin=None, stroke_miterlimit=None, fill_rule=None, fill_opacity=None, fill='none'), Path(stroke='black', stroke_dasharray=None, stroke_dashoffset=None, stroke_opacity=None, stroke_width=1, clip_rule=None, cursor=None, display=None, filter=None, pointer_events=None, onfocusin=None, onfocusout=None, onactivate=None, onclick=None, onmousedown=None, onmouseup=None, onmouseover=None, onmousemove=None, onmouseout=None, onload=None, color=None, color_interpolation=None, pathLength=None, paint_order=None, shape_rendering=None, class_=None, vector_effect=None, visibility=None, mask=None, opacity=None, clip_path=None, elements=None, text=None, id=None, tabindex=None, lang=None, transform_origin=None, style=None, data=None, extra=None, externalResourcesRequired=None, transform=[Scale(x=-1, y=1)], d=[MoveTo(x=0, y=0), LineTo(x=5.0, y=0), LineTo(x=5.0, y=5), ArcRel(rx=1, ry=1, angle=90, large_arc=0, sweep=1, dx=-1, dy=1), LineTo(x=0, y=6)], marker_start=None, marker_mid=None, marker_end=None, stroke_linecap='square', stroke_linejoin=None, stroke_miterlimit=None, fill_rule=None, fill_opacity=None, fill='none'), Path(stroke='black', stroke_dasharray=None, stroke_dashoffset=None, stroke_opacity=None, stroke_width=1, clip_rule=None, cursor=None, display=None, filter=None, pointer_events=None, onfocusin=None, onfocusout=None, onactivate=None, onclick=None, onmousedown=None, onmouseup=None, onmouseover=None, onmousemove=None, onmouseout=None, onload=None, color=None, color_interpolation=None, pathLength=None, paint_order=None, shape_rendering=None, class_=None, vector_effect=None, visibility=None, mask=None, opacity=None, clip_path=None, elements=None, text=None, id=None, tabindex=None, lang=None, transform_origin=None, style=None, data=None, extra=None, externalResourcesRequired=None, transform=None, d=[MoveTo(x=3.0, y=2), LineTo(x=3.0, y=4)], marker_start=None, marker_mid=None, marker_end=None, stroke_linecap='square', stroke_linejoin=None, stroke_miterlimit=None, fill_rule=None, fill_opacity=None, fill='none')], text=None, id=None, tabindex=None, lang=None, transform_origin=None, style=None, data=None, extra=None, transform=[Rotate(a=180, x=None, y=None)], class_=None, mask=None, opacity=None, clip_path=None, fill_rule=None, fill_opacity=None, fill=None)], text=None, id=None, tabindex=None, lang=None, transform_origin=None, style=None, data=None, extra=None, transform=[Translate(x=200, y=120), Rotate(a=45, x=None, y=None), Scale(x=10, y=10)], class_=None, mask=None, opacity=None, clip_path=None, fill_rule=None, fill_opacity=None, fill=None), G(stroke=None, stroke_dasharray=None, stroke_dashoffset=None, stroke_opacity=None, stroke_width=None, clip_rule=None, cursor=None, display=None, filter=None, pointer_events=None, color=None, color_interpolation=None, onfocusin=None, onfocusout=None, onactivate=None, onclick=None, onmousedown=None, onmouseup=None, onmouseover=None, onmousemove=None, onmouseout=None, onload=None, elements=[G(stroke=None, stroke_dasharray=None, stroke_dashoffset=None, stroke_opacity=None, stroke_width=None, clip_rule=None, cursor=None, display=None, filter=None, pointer_events=None, color=None, color_interpolation=None, onfocusin=None, onfocusout=None, onactivate=None, onclick=None, onmousedown=None, onmouseup=None, onmouseover=None, onmousemove=None, onmouseout=None, onload=None, elements=[Circle(stroke='black', stroke_dasharray=None, stroke_dashoffset=None, stroke_opacity=None, stroke_width=1, clip_rule=None, cursor=None, display=None, filter=None, pointer_events=None, onfocusin=None, onfocusout=None, onactivate=None, onclick=None, onmousedown=None, onmouseup=None, onmouseover=None, onmousemove=None, onmouseout=None, onload=None, color=None, color_interpolation=None, pathLength=None, paint_order=None, shape_rendering=None, class_=None, vector_effect=None, visibility=None, mask=None, opacity=None, clip_path=None, elements=None, text=None, id=None, tabindex=None, lang=None, transform_origin=None, style=None, data=None, extra=None, externalResourcesRequired=None, transform=None, cx=0, cy=0, r=5.0, marker_mid=None, fill_opacity=None, fill='none'), Path(stroke='black', stroke_dasharray=None, stroke_dashoffset=None, stroke_opacity=None, stroke_width=1, clip_rule=None, cursor=None, display=None, filter=None, pointer_events=None, onfocusin=None, onfocusout=None, onactivate=None, onclick=None, onmousedown=None, onmouseup=None, onmouseover=None, onmousemove=None, onmouseout=None, onload=None, color=None, color_interpolation=None, pathLength=None, paint_order=None, shape_rendering=None, class_=None, vector_effect=None, visibility=None, mask=None, opacity=None, clip_path=None, elements=None, text=None, id=None, tabindex=None, lang=None, transform_origin=None, style=None, data=None, extra=None, externalResourcesRequired=None, transform=None, d=[MoveTo(x=2.5, y=0.0), LineTo(x=1.2500000000000002, y=2.1650635094610964), LineTo(x=-1.2499999999999996, y=2.165063509461097), LineTo(x=-2.5, y=3.061616997868383e-16), LineTo(x=-1.250000000000001, y=-2.165063509461096), LineTo(x=1.2500000000000002, y=-2.1650635094610964), ClosePath()], marker_start=None, marker_mid=None, marker_end=None, stroke_linecap='rounded', stroke_linejoin=None, stroke_miterlimit=None, fill_rule=None, fill_opacity=None, fill='none')], text=None, id=None, tabindex=None, lang=None, transform_origin=None, style=None, data=None, extra=None, transform=None, class_=None, mask=None, opacity=None, clip_path=None, fill_rule=None, fill_opacity=None, fill=None)], text=None, id=None, tabindex=None, lang=None, transform_origin=None, style=None, data=None, extra=None, transform=[Translate(x=240, y=250), Scale(x=10, y=10)], class_=None, mask=None, opacity=None, clip_path=None, fill_rule=None, fill_opacity=None, fill=None)], text=None, id=None, tabindex=None, lang=None, transform_origin=None, style=None, data=None, extra=None, xmlns='http://www.w3.org/2000/svg', viewBox=None, preserveAspectRatio=None, x=None, y=None, width=350, height=350, class_=None, mask=None, opacity=None, clip_path=None, overflow=None, onunload=None, onabort=None, onerror=None, onresize=None, onscroll=None, onzoom=None)"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def threads(\n",
" *, \n",
" n_threads=8, \n",
" shank_width=4.5, shank_length=16, shank_chamfer=1, \n",
" shank_above_threads=3, \n",
" shoulder_step=0.5,\n",
" shoulder_length=2,\n",
") -> svg.Element:\n",
"\n",
" thread_width = shank_width + 1 \n",
" shoulder_width = shank_width + shoulder_step * 2\n",
" \n",
" threads = []\n",
" for n in range(n_threads):\n",
" threads.extend([\n",
" svg.MoveTo(-thread_width/2, n * 2), \n",
" svg.LineTo(thread_width/2, n * 2),\n",
" ])\n",
" \n",
" shank = [\n",
" svg.MoveTo(-shank_width/2, -shank_above_threads),\n",
" svg.LineTo(-shank_width/2, shank_length - shank_chamfer),\n",
" svg.LineTo(-shank_width/2 + shank_chamfer, shank_length),\n",
" svg.LineTo(shank_width/2 - shank_chamfer, shank_length),\n",
" svg.LineTo(shank_width/2, shank_length - shank_chamfer),\n",
" svg.LineTo(shank_width/2, -shank_above_threads),\n",
" ]\n",
" if shoulder_length:\n",
" shank.extend([\n",
" svg.MoveTo(shoulder_width/2, -shank_above_threads-shoulder_length),\n",
" svg.LineTo(shoulder_width/2, -shank_above_threads),\n",
" svg.LineTo(-shoulder_width/2, -shank_above_threads),\n",
" svg.LineTo(-shoulder_width/2, -shank_above_threads-shoulder_length),\n",
" ])\n",
" \n",
" return svg.G(\n",
" elements=[\n",
" svg.Path(\n",
" fill=\"none\",\n",
" stroke=\"black\",\n",
" stroke_width=1,\n",
" stroke_linecap=\"square\",\n",
" d=threads,\n",
" ),\n",
" svg.Path(\n",
" fill=\"none\",\n",
" stroke=\"black\",\n",
" stroke_width=1,\n",
" stroke_linecap=\"square\",\n",
" d=shank,\n",
" ),\n",
" ],\n",
" transform=[svg.Translate(0, shank_above_threads + shoulder_length)],\n",
" )\n",
"\n",
"def cap_head(\n",
" *,\n",
" height=6,\n",
" width=10,\n",
" fillet=1,\n",
") -> svg.Element:\n",
" radius = width/2\n",
" cap_head = [\n",
" svg.MoveTo(0, 0),\n",
" svg.LineTo(radius, 0),\n",
" svg.LineTo(radius, height - fillet),\n",
" svg.ArcRel(fillet, fillet, 90, 0, 1, -fillet, fillet),\n",
" svg.LineTo(0, height),\n",
" ]\n",
" cap_head_detail = [\n",
" svg.MoveTo(radius - 2, 2),\n",
" svg.LineTo(radius - 2, height - 2),\n",
" ]\n",
" return svg.G(\n",
" elements=[\n",
" svg.Path(\n",
" fill=\"none\",\n",
" stroke=\"black\",\n",
" stroke_width=1,\n",
" stroke_linecap=\"square\",\n",
" d=cap_head,\n",
" ),\n",
" svg.Path(\n",
" fill=\"none\",\n",
" stroke=\"black\",\n",
" stroke_width=1,\n",
" stroke_linecap=\"square\",\n",
" d=cap_head,\n",
" transform=[svg.Scale(-1, 1)]\n",
" ),\n",
" svg.Path(\n",
" fill=\"none\",\n",
" stroke=\"black\",\n",
" stroke_width=1,\n",
" stroke_linecap=\"square\",\n",
" d=cap_head_detail,\n",
" ),\n",
" ],\n",
" transform=[svg.Rotate(180)],\n",
" )\n",
"\n",
"def cap_top(\n",
" *,\n",
" dia=10,\n",
" hex_dia=5,\n",
") -> svg.Element:\n",
" radius = dia / 2\n",
" hex_rad = hex_dia / 2\n",
" cap_hex_points = []\n",
" for n in range(6):\n",
" if n == 0:\n",
" op = svg.MoveTo\n",
" else:\n",
" op = svg.LineTo\n",
" cap_hex_points.append(op(hex_rad * math.cos(n * math.pi / 3), hex_rad * math.sin(n * math.pi / 3)))\n",
" cap_hex_points.append(svg.ClosePath())\n",
" \n",
" return svg.G(\n",
" elements=[\n",
" svg.Circle(\n",
" cx=0, cy=0, \n",
" r=radius,\n",
" stroke=\"black\",\n",
" fill=\"none\",\n",
" stroke_width=1,\n",
" ),\n",
" svg.Path(\n",
" stroke=\"black\",\n",
" fill=\"none\",\n",
" stroke_linecap=\"rounded\",\n",
" stroke_width=1,\n",
" d=cap_hex_points,\n",
" )\n",
" ],\n",
" )\n",
"\n",
"stroke_scale = 10\n",
"scale = svg.Scale(stroke_scale, stroke_scale)\n",
"\n",
"svg.SVG(\n",
" height=350,\n",
" width=350,\n",
" # viewBox=svg.ViewBoxSpec(0, 0, 250, 150),\n",
" elements=[\n",
" svg.G(\n",
" elements=[\n",
" threads(), \n",
" cap_head(),\n",
" ],\n",
" transform=[svg.Translate(200, 120), svg.Rotate(45), scale],\n",
" ),\n",
" svg.G(\n",
" elements=[cap_top()],\n",
" transform=[svg.Translate(240, 250), scale],\n",
" )\n",
" ]\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "60ebac7e-e031-453c-a4dd-5d454ade458f",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Data Analysis",
"language": "python",
"name": "jupyterdata"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.2"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment