Skip to content

Commit b18d176

Browse files
committed
(+ example_1.rst)
1 parent 6e06a14 commit b18d176

7 files changed

+78
-36
lines changed
Loading
Loading
Loading
Loading

docs/examples_1.rst

+43-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@ Most of the examples show the builder and algebra modes.
3939
:link: examples-build123d_logo
4040
:link-type: ref
4141

42-
42+
43+
.. grid-item-card:: Canadian Flag blowing in the wind |Builder| |Algebra|
44+
:img-top: assets/examples/thumbnail_canadian_flag_01.png
45+
:link: examples-canadian_flag
46+
:link-type: ref
47+
4348
.. NOTE 01: insert new example thumbnails above this line
4449
4550
.. TODO: Copy this block to add the example thumbnails here
@@ -157,6 +162,43 @@ The builder mode example also generates the SVG file `logo.svg`.
157162
:start-after: [Code]
158163
:end-before: [End]
159164

165+
166+
.. _examples-canadian_flag:
167+
168+
Canadian Flag blowing in the wind
169+
--------------------------------
170+
.. image:: assets/examples/example_canadian_flag_01.png
171+
:align: center
172+
173+
174+
175+
A Canadian Flag blowing in the wind created by projecting planar faces onto a non-planar face (the_wind).
176+
177+
This example also demonstrates building complex lines that snap to existing features.
178+
179+
180+
.. dropdown:: More Images
181+
182+
.. image:: assets/examples/example_canadian_flag_02.png
183+
:align: center
184+
185+
.. image:: assets/examples/example_canadian_flag_03.png
186+
:align: center
187+
188+
189+
.. dropdown:: |Builder| Reference Implementation (Builder Mode)
190+
191+
.. literalinclude:: ../examples/canadian_flag.py
192+
:start-after: [Code]
193+
:end-before: [End]
194+
195+
.. dropdown:: |Algebra| Reference Implementation (Algebra Mode)
196+
197+
.. literalinclude:: ../examples/canadian_flag_algebra.py
198+
:start-after: [Code]
199+
:end-before: [End]
200+
201+
160202
.. NOTE 02: insert new example thumbnails above this line
161203
162204

examples/canadian_flag.py

+23-29
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,36 @@
11
"""
2-
3-
Projection Examples: Canadian Flag in the Wind
4-
5-
name: canadian_flag.py
6-
by: Gumyr
7-
date: February 23th 2023
8-
9-
desc: A Canadian Flag blowing in the wind created by projecting planar
10-
faces onto a non-planar face (the_wind).
11-
12-
This example also demonstrates building complex lines that snap to
13-
existing features.
14-
15-
license:
16-
17-
Copyright 2023 Gumyr
18-
19-
Licensed under the Apache License, Version 2.0 (the "License");
20-
you may not use this file except in compliance with the License.
21-
You may obtain a copy of the License at
22-
23-
http://www.apache.org/licenses/LICENSE-2.0
24-
25-
Unless required by applicable law or agreed to in writing, software
26-
distributed under the License is distributed on an "AS IS" BASIS,
27-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28-
See the License for the specific language governing permissions and
29-
limitations under the License.
30-
2+
name: "canadian_flag.py"
3+
title: "Canadian Flag blowing in the wind"
4+
authors: "Gumyr"
5+
license: "http://www.apache.org/licenses/LICENSE-2.0"
6+
created: "2023-02-23"
7+
modified: "2023-07-31"
8+
9+
description: |
10+
A Canadian Flag blowing in the wind created by projecting planar faces onto a non-planar face (the_wind).
11+
12+
This example also demonstrates building complex lines that snap to existing features.
13+
14+
has_builder_mode: true
15+
has_algebra_mode: true
16+
image_files:
17+
- "example_canadian_flag_01.png"
18+
- "example_canadian_flag_02.png"
19+
- "example_canadian_flag_03.png"
3120
"""
21+
22+
# [Imports]
3223
from math import sin, cos, pi
3324
from build123d import *
3425
from ocp_vscode import show_object
3526

27+
# [Parameters]
3628
# Canadian Flags have a 2:1 aspect ratio
3729
height = 50
3830
width = 2 * height
3931
wave_amplitude = 3
4032

33+
# [Code]
4134

4235
def surface(amplitude, u, v):
4336
"""Calculate the surface displacement of the flag at a given position"""
@@ -112,3 +105,4 @@ def surface(amplitude, u, v):
112105
show_object(east_field, name="east", options={"color": (255, 0, 0)})
113106
show_object(center_field, name="center", options={"color": (255, 255, 255)})
114107
show_object(maple_leaf, name="maple", options={"color": (255, 0, 0)})
108+
# [End]

examples/canadian_flag_algebra.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1+
"""
2+
for details see `canadian_flag.py`
3+
"""
4+
# [Imports]
15
from math import sin, cos, pi
26
from build123d import *
7+
from ocp_vscode import *
38

9+
# [Parameters]
410
# Canadian Flags have a 2:1 aspect ratio
511
height = 50
612
width = 2 * height
713
wave_amplitude = 3
814

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

8288

83-
if "show_object" in locals():
84-
show_object(west_field, name="west", options={"color": (255, 0, 0)})
85-
show_object(east_field, name="east", options={"color": (255, 0, 0)})
86-
show_object(center_field, name="center", options={"color": (255, 255, 255)})
87-
show_object(maple_leaf, name="maple", options={"color": (255, 0, 0)})
89+
show_object(west_field, name="west", options={"color": (255, 0, 0)})
90+
show_object(east_field, name="east", options={"color": (255, 0, 0)})
91+
show_object(center_field, name="center", options={"color": (255, 255, 255)})
92+
show_object(maple_leaf, name="maple", options={"color": (255, 0, 0)})
93+
# [End]

0 commit comments

Comments
 (0)