Skip to content

Commit

Permalink
Merge pull request #504 from 42sol-eu/dev
Browse files Browse the repository at this point in the history
closing issue #493 - examples to documentation
  • Loading branch information
gumyr authored Jan 27, 2024
2 parents c6b0cd1 + b2a7431 commit 89eda23
Show file tree
Hide file tree
Showing 16 changed files with 232 additions and 93 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/examples/example_canadian_flag_01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/examples/example_canadian_flag_02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/examples/example_canadian_flag_03.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/examples/example_circuit_board_01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/examples/example_circuit_board_02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
116 changes: 116 additions & 0 deletions docs/examples_1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,23 @@ Most of the examples show the builder and algebra modes.
:link: examples-build123d_customizable_logo
:link-type: ref

.. grid-item-card:: Former build123d Logo |Builder| |Algebra|
:img-top: assets/examples/thumbnail_build123d_logo_01.png
:link: examples-build123d_logo
:link-type: ref


.. grid-item-card:: Circuit Board With Holes |Builder| |Algebra|
:img-top: assets/examples/thumbnail_canadian_flag_01.png
:link: examples-canadian_flag
:link-type: ref


.. grid-item-card:: Canadian Flag Blowing in The Wind |Builder| |Algebra|
:img-top: assets/examples/thumbnail_circuit_board_01.png
:link: examples-circuit_board
:link-type: ref

.. NOTE 01: insert new example thumbnails above this line
.. TODO: Copy this block to add the example thumbnails here
Expand Down Expand Up @@ -125,6 +141,106 @@ It shows how text is created, placed and sizes of text is calulated to define si
:start-after: [Code]
:end-before: [End]


.. _examples-build123d_logo:

Former build123d Logo
--------------------------------
.. image:: assets/examples/example_build123d_logo_01.png
:align: center


This example creates the former build123d logo (new logo was created in the end of 2023).

Using text and lines to create the first build123d logo.
The builder mode example also generates the SVG file `logo.svg`.


.. dropdown:: |Builder| Reference Implementation (Builder Mode)

.. literalinclude:: ../examples/build123d_logo.py
:start-after: [Code]
:end-before: [End]

.. dropdown:: |Algebra| Reference Implementation (Algebra Mode)

.. literalinclude:: ../examples/build123d_logo_algebra.py
:start-after: [Code]
:end-before: [End]


.. _examples-canadian_flag:

Canadian Flag Blowing in The Wind
----------------------------------
.. image:: assets/examples/example_canadian_flag_01.png
:align: center



A Canadian Flag blowing in the wind created by projecting planar faces onto a non-planar face (the_wind).

This example also demonstrates building complex lines that snap to existing features.


.. dropdown:: More Images

.. image:: assets/examples/example_canadian_flag_02.png
:align: center

.. image:: assets/examples/example_canadian_flag_03.png
:align: center


.. dropdown:: |Builder| Reference Implementation (Builder Mode)

.. literalinclude:: ../examples/canadian_flag.py
:start-after: [Code]
:end-before: [End]

.. dropdown:: |Algebra| Reference Implementation (Algebra Mode)

.. literalinclude:: ../examples/canadian_flag_algebra.py
:start-after: [Code]
:end-before: [End]


.. _examples-circuit_board:


Circuit Board With Holes
------------------------
.. image:: assets/examples/example_circuit_board_01.png
:align: center



This example demonstrates placing holes around a part.

- Builder mode uses `Locations` context to place the positions.
- Algebra mode uses `product` and `range` to calculate the positions.



.. dropdown:: More Images

.. image:: assets/examples/example_circuit_board_02.png
:align: center


.. dropdown:: |Builder| Reference Implementation (Builder Mode)

.. literalinclude:: ../examples/circuit_board.py
:start-after: [Code]
:end-before: [End]

.. dropdown:: |Algebra| Reference Implementation (Algebra Mode)

.. literalinclude:: ../examples/circuit_board_algebra.py
:start-after: [Code]
:end-before: [End]


.. NOTE 02: insert new example thumbnails above this line
Expand Down
47 changes: 23 additions & 24 deletions examples/build123d_logo.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
"""
name: build123d_logo.py
by: Gumyr
date: August 5th 2022
desc:
This example creates the build123d logo.
license:
Copyright 2022 Gumyr
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
name: "build_123d_logo.py"
title: "Former build123d Logo"
authors: "Gumyr"
license: "http://www.apache.org/licenses/LICENSE-2.0"
created: "2022-08-05"
modified: "2023-07-31"
description: |
This example creates the former build123d logo (new logo was created in the end of 2023).
Using text and lines to create the first build123d logo.
The builder mode example also generates the SVG file `logo.svg`.
has_builder_mode: true
has_algebra_mode: true
image_files:
- "example_build123d_logo_01.png"
"""
# [Imports]
from build123d import *
from build123d import Shape
from ocp_vscode import *

# [Parameters]
# - none

# [Code]
with BuildSketch() as logo_text:
Text("123d", font_size=10, align=(Align.MIN, Align.MIN))
font_height = logo_text.vertices().sort_by(Axis.Y)[-1].Y
Expand Down Expand Up @@ -120,3 +118,4 @@ def add_svg_shape(svg: ExportSVG, shape: Shape, color: tuple[float, float, float
show_object(three_d, name="three_d")
show_object(extension_lines, name="extension_lines")
show_object(build, name="build")
# [End]
15 changes: 12 additions & 3 deletions examples/build123d_logo_algebra.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
"""
for details see `build123d_logo.py`
"""
# [Imports]
from build123d import *
from ocp_vscode import *

# [Parameters]
# - none

# [Code]
logo_text = Text("123d", font_size=10, align=Align.MIN)
font_height = logo_text.vertices().sort_by(Axis.Y).last.Y

Expand Down Expand Up @@ -30,7 +38,7 @@
)
extension_lines = l1 + l2
extension_lines += Pos(*(l1 @ 0.5)) * arrow_left
extension_lines += (Pos(*(l2 @ 0.5)) * Rot(z=180)) * arrow_left
extension_lines += (Pos(*(l2 @ 0.5)) * Rot(Z=180)) * arrow_left
extension_lines += Line(l1 @ 0.5, l1 @ 0.5 + Vector(dim_line_length, 0))
extension_lines += Line(l2 @ 0.5, l2 @ 0.5 - Vector(dim_line_length, 0))

Expand All @@ -40,5 +48,6 @@

cmpd = Compound.make_compound([three_d, two, one, build, extension_lines])

if "show_object" in locals():
show_object(cmpd, name="compound")
show_object(cmpd, name="compound")

# [End]
52 changes: 23 additions & 29 deletions examples/canadian_flag.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,36 @@
"""
Projection Examples: Canadian Flag in the Wind
name: canadian_flag.py
by: Gumyr
date: February 23th 2023
desc: A Canadian Flag blowing in the wind created by projecting planar
faces onto a non-planar face (the_wind).
This example also demonstrates building complex lines that snap to
existing features.
license:
Copyright 2023 Gumyr
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
name: "canadian_flag.py"
title: "Canadian Flag blowing in the wind"
authors: "Gumyr"
license: "http://www.apache.org/licenses/LICENSE-2.0"
created: "2023-02-23"
modified: "2023-07-31"
description: |
A Canadian Flag blowing in the wind created by projecting planar faces onto a non-planar face (the_wind).
This example also demonstrates building complex lines that snap to existing features.
has_builder_mode: true
has_algebra_mode: true
image_files:
- "example_canadian_flag_01.png"
- "example_canadian_flag_02.png"
- "example_canadian_flag_03.png"
"""

# [Imports]
from math import sin, cos, pi
from build123d import *
from ocp_vscode import show_object

# [Parameters]
# Canadian Flags have a 2:1 aspect ratio
height = 50
width = 2 * height
wave_amplitude = 3

# [Code]

def surface(amplitude, u, v):
"""Calculate the surface displacement of the flag at a given position"""
Expand Down Expand Up @@ -112,3 +105,4 @@ def surface(amplitude, u, v):
show_object(east_field, name="east", options={"color": (255, 0, 0)})
show_object(center_field, name="center", options={"color": (255, 255, 255)})
show_object(maple_leaf, name="maple", options={"color": (255, 0, 0)})
# [End]
18 changes: 12 additions & 6 deletions examples/canadian_flag_algebra.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
"""
for details see `canadian_flag.py`
"""
# [Imports]
from math import sin, cos, pi
from build123d import *
from ocp_vscode import *

# [Parameters]
# Canadian Flags have a 2:1 aspect ratio
height = 50
width = 2 * height
wave_amplitude = 3


# [Code]
def surface(amplitude, u, v):
"""Calculate the surface displacement of the flag at a given position"""
return v * amplitude / 20 * cos(3.5 * pi * u) + amplitude / 10 * v * sin(
Expand Down Expand Up @@ -80,8 +86,8 @@ def project(obj):
maple_leaf = project(maple_leaf_planar)


if "show_object" in locals():
show_object(west_field, name="west", options={"color": (255, 0, 0)})
show_object(east_field, name="east", options={"color": (255, 0, 0)})
show_object(center_field, name="center", options={"color": (255, 255, 255)})
show_object(maple_leaf, name="maple", options={"color": (255, 0, 0)})
show_object(west_field, name="west", options={"color": (255, 0, 0)})
show_object(east_field, name="east", options={"color": (255, 0, 0)})
show_object(center_field, name="center", options={"color": (255, 255, 255)})
show_object(maple_leaf, name="maple", options={"color": (255, 0, 0)})
# [End]
Loading

0 comments on commit 89eda23

Please sign in to comment.