Add stuff

This commit is contained in:
jimmy 2023-03-05 13:20:58 +13:00
parent 65a2f586f5
commit 3f05655d4c
1 changed files with 264 additions and 33 deletions

View File

@ -3,32 +3,20 @@
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "23b382e7", "id": "23b382e7",
"metadata": {}, "metadata": {
"tags": []
},
"source": [ "source": [
"# Solid Python Demo" "# Solid Python Demo"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 1,
"id": "bb0d0f76",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "f4b63a52",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 3,
"id": "a75c573b", "id": "a75c573b",
"metadata": {}, "metadata": {
"tags": []
},
"outputs": [], "outputs": [],
"source": [ "source": [
"from solid import *\n", "from solid import *\n",
@ -41,19 +29,231 @@
"id": "6a77043a", "id": "6a77043a",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Create a cylinder" "## Create a cylinder"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 4, "execution_count": null,
"id": "25a01e9c", "id": "25a01e9c",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"c = cylinder(r=7, h=2)\n",
"r.render(c)"
]
},
{
"cell_type": "markdown",
"id": "6cb47c97-3f36-4b31-baaf-905a399ed7be",
"metadata": {
"tags": []
},
"source": [
"## Create a cuboid"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ecdfd420-ebef-49b1-8d90-c35b1e5ac571",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"c = cube((10,4,6)) #pass a tuple x, y, z\n",
"r.render(c)"
]
},
{
"cell_type": "markdown",
"id": "c77c2196-ccf6-4be8-94ea-8ad870ccdd23",
"metadata": {}, "metadata": {},
"source": [
"## Translating"
]
},
{
"cell_type": "code",
"execution_count": 33,
"id": "2ae63616-4044-4c6a-bf11-9ebf83f8f22a",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"from solid.utils import *"
]
},
{
"cell_type": "code",
"execution_count": 34,
"id": "77e99d01-1aa4-43ce-93bf-c71c6f1325c8",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"x, y, z = 1, 1, 1\n",
"c = translate([x, y, z]) (\n",
" cylinder(r=1, h=5)\n",
")\n",
"r.render(c)"
]
},
{
"cell_type": "code",
"execution_count": 35,
"id": "bb5ad126-5476-43a8-9c8f-75aebce0c47e",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"c = left(x)(\n",
" forward(y)(\n",
" up(z)(\n",
" cylinder(r=1, h=5)\n",
" )\n",
" )\n",
" )\n",
"r.render(c)"
]
},
{
"cell_type": "markdown",
"id": "1bc5ffad-a5d3-4d61-8d38-5ee2c015c3cc",
"metadata": {},
"source": [
"## Rotating"
]
},
{
"cell_type": "code",
"execution_count": 43,
"id": "86cb4b1a-03cf-449c-bc08-2ea81512c34a",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"c = cylinder(r=2, h=4)\n",
"rotated = rotate((90, 0 , 0))(c)\n",
"r.render(rotated)"
]
},
{
"cell_type": "markdown",
"id": "153bc0ab-212a-417c-aefd-0693b2c6a704",
"metadata": {
"tags": []
},
"source": [
"## Adding objects"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "a5769eb4-13d4-425a-a22b-8e14123f8908",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"base = cube((5,5,1)) #pass a tuple x, y, z\n",
"top = cylinder(r=1, h=5)\n",
"part = union()(\n",
" base,\n",
" translate((2.5, 2.5, 1))(\n",
" top\n",
" )\n",
")\n",
"r.render(part)"
]
},
{
"cell_type": "code",
"execution_count": 48,
"id": "6107bce9-ff24-4f94-974b-637445c707f5",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"base = cube((5,5,1)) #pass a tuple x, y, z\n",
"top = cylinder(r=1, h=5)\n",
"part = base + translate((2.5, 2.5, 1))(\n",
" rotate((60, 0, 0))(\n",
" top\n",
" )\n",
")\n",
"\n",
"r.render(part)"
]
},
{
"cell_type": "markdown",
"id": "c1413bc8-05a6-458c-b308-07e8af2b1ebe",
"metadata": {},
"source": [
"## Subtracting objects"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "c425603f-8c79-4e7b-b204-3c128768b6ab",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"base = cube((5,5,1)) #pass a tuple x, y, z\n",
"top = cylinder(r=1, h=5)\n",
"part = difference()(\n",
" base,\n",
" translate((2.5, 2.5, 0))(\n",
" top\n",
" )\n",
")\n",
"r.render(part)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "9062af4f-d729-4208-abbf-1750b682b482",
"metadata": {
"tags": []
},
"outputs": [ "outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Geometries in cache: 4\n",
"Geometry cache size in bytes: 9824\n",
"CGAL Polyhedrons in cache: 1\n",
"CGAL cache size in bytes: 65232\n",
"Total rendering time: 0:00:00.068\n",
" Top level object is a 3D object:\n",
" Simple: yes\n",
" Vertices: 48\n",
" Halfedges: 144\n",
" Edges: 72\n",
" Halffacets: 52\n",
" Facets: 26\n",
" Volumes: 2\n"
]
},
{ {
"data": { "data": {
"application/vnd.jupyter.widget-view+json": { "application/vnd.jupyter.widget-view+json": {
"model_id": "62ecf44ecacd4ffc95b4ae71d5f53ebf", "model_id": "11a120f2cd4641279ef0d1f1af319eac",
"version_major": 2, "version_major": 2,
"version_minor": 0 "version_minor": 0
}, },
@ -66,8 +266,47 @@
} }
], ],
"source": [ "source": [
"c = cylinder(r=5, h=2)\n", "base = cube((5,5,2))\n",
"r.render(c)" "inner = cylinder(r=0.5, h=5)\n",
"part = base - translate((2.5, 0, 1))(\n",
" rotate((270,0,0))(\n",
" inner\n",
" )\n",
")\n",
"\n",
"\n",
"r.render(part)"
]
},
{
"cell_type": "markdown",
"id": "856d57d9-c292-48ba-8871-050ea53c0110",
"metadata": {},
"source": [
"## Save to SCAD"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "1810ff24-c0f8-4c80-adc2-6985cd52d7dc",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"'/home/jimmy/projects/Solid-Python-Demo/part.scad'"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"scad_render_to_file(part, \"part.scad\")"
] ]
}, },
{ {
@ -79,14 +318,6 @@
"https://solidpython.readthedocs.io/en/latest/\n", "https://solidpython.readthedocs.io/en/latest/\n",
"https://openscad.org/" "https://openscad.org/"
] ]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b6538a9c",
"metadata": {},
"outputs": [],
"source": []
} }
], ],
"metadata": { "metadata": {
@ -105,7 +336,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.8.10" "version": "3.10.6"
} }
}, },
"nbformat": 4, "nbformat": 4,