mirror of
https://github.com/gumyr/build123d.git
synced 2025-12-15 15:20:37 -08:00
more examples ported
This commit is contained in:
parent
25af1e9722
commit
8911244cd2
2 changed files with 160 additions and 0 deletions
45
examples/build123d_logo_algebra.py
Normal file
45
examples/build123d_logo_algebra.py
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
from build123d import *
|
||||
|
||||
logo_text = Text("123d", font_size=10, align=(Align.MIN, Align.MIN))
|
||||
font_height = logo_text.vertices().sort_by(Axis.Y)[-1].Y
|
||||
|
||||
build_text = Text("build", font_size=5, align=(Align.CENTER, Align.CENTER))
|
||||
build_bb = build_text.bounding_box()
|
||||
build_width = build_bb.max.X - build_bb.min.X
|
||||
|
||||
l1 = Line((font_height * 0.3, 0), (font_height * 0.3, font_height))
|
||||
one = l1 + TangentArc(l1 @ 1, (0, font_height * 0.7), tangent=(l1 % 1) * -1)
|
||||
|
||||
two = Pos(font_height * 0.35, 0) * Text("2", font_size=10, align=(Align.MIN, Align.MIN))
|
||||
|
||||
three_d = Text("3d", font_size=10, align=(Align.MIN, Align.MIN))
|
||||
three_d = Pos(font_height * 1.1, 0) * extrude(three_d, amount=font_height * 0.3)
|
||||
logo_width = three_d.vertices().sort_by(Axis.X)[-1].X
|
||||
|
||||
t1 = TangentArc((0, 0), (1, 0.75), tangent=(1, 0))
|
||||
arrow_left = t1 + mirror(t1, about=Plane.XZ)
|
||||
|
||||
ext_line_length = font_height * 0.5
|
||||
dim_line_length = (logo_width - build_width - 2 * font_height * 0.05) / 2
|
||||
|
||||
l1 = Line((0, -font_height * 0.1), (0, -ext_line_length - font_height * 0.1))
|
||||
l2 = Line(
|
||||
(logo_width, -font_height * 0.1),
|
||||
(logo_width, -ext_line_length - font_height * 0.1),
|
||||
)
|
||||
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 += 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))
|
||||
|
||||
# Precisely center the build Faces
|
||||
p1 = Pos((l1 @ 0.5 + l2 @ 0.5) / 2 - Vector((build_bb.max.X + build_bb.min.X) / 2, 0))
|
||||
build = p1 * build_text
|
||||
|
||||
if "show_object" in locals():
|
||||
show_object(one.wrapped, name="one")
|
||||
show_object(two.wrapped, name="two")
|
||||
show_object(three_d.wrapped, name="three_d")
|
||||
show_object(extension_lines.wrapped, name="extension_lines")
|
||||
show_object(build.wrapped, name="build")
|
||||
115
examples/custom_sketch_objects_algebra.py
Normal file
115
examples/custom_sketch_objects_algebra.py
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
from typing import Tuple, Union
|
||||
from build123d import *
|
||||
|
||||
|
||||
class Club(Sketch):
|
||||
def __init__(
|
||||
self,
|
||||
height: float,
|
||||
align: Union[Align, Tuple[Align, Align]] = None,
|
||||
):
|
||||
l0 = Line((0, -188), (76, -188))
|
||||
b0 = Bezier(l0 @ 1, (61, -185), (33, -173), (17, -81))
|
||||
b1 = Bezier(b0 @ 1, (49, -128), (146, -145), (167, -67))
|
||||
b2 = Bezier(b1 @ 1, (187, 9), (94, 52), (32, 18))
|
||||
b3 = Bezier(b2 @ 1, (92, 57), (113, 188), (0, 188))
|
||||
club = l0 + b0 + b1 + b2 + b3
|
||||
club += mirror(club, about=Plane.YZ)
|
||||
club = make_face(club)
|
||||
club = scale(club, by=height / club.bounding_box().size.Y)
|
||||
|
||||
super().__init__(club.wrapped)
|
||||
# self._align(align)
|
||||
|
||||
|
||||
class Spade(Sketch):
|
||||
def __init__(
|
||||
self,
|
||||
height: float,
|
||||
align: Union[Align, Tuple[Align, Align]] = None,
|
||||
):
|
||||
b0 = Bezier((0, 198), (6, 190), (41, 127), (112, 61))
|
||||
b1 = Bezier(b0 @ 1, (242, -72), (114, -168), (11, -105))
|
||||
b2 = Bezier(b1 @ 1, (31, -174), (42, -179), (53, -198))
|
||||
l0 = Line(b2 @ 1, (0, -198))
|
||||
spade = l0 + b0 + b1 + b2
|
||||
spade += mirror(spade, about=Plane.YZ)
|
||||
spade = make_face(spade)
|
||||
spade = scale(spade, by=height / spade.bounding_box().size.Y)
|
||||
|
||||
super().__init__(spade.wrapped)
|
||||
# self._align(align)
|
||||
|
||||
|
||||
class Heart(Sketch):
|
||||
def __init__(
|
||||
self,
|
||||
height: float,
|
||||
align: Union[Align, Tuple[Align, Align]] = None,
|
||||
):
|
||||
b1 = Bezier((0, 146), (20, 169), (67, 198), (97, 198))
|
||||
b2 = Bezier(b1 @ 1, (125, 198), (151, 186), (168, 167))
|
||||
b3 = Bezier(b2 @ 1, (197, 133), (194, 88), (158, 31))
|
||||
b4 = Bezier(b3 @ 1, (126, -13), (94, -48), (62, -95))
|
||||
b5 = Bezier(b4 @ 1, (40, -128), (0, -198))
|
||||
heart = b1 + b2 + b3 + b4 + b5
|
||||
heart += mirror(heart, about=Plane.YZ)
|
||||
heart = make_face(heart)
|
||||
heart = scale(heart, by=height / heart.bounding_box().size.Y)
|
||||
|
||||
super().__init__(heart.wrapped)
|
||||
# self._align(align)
|
||||
|
||||
|
||||
class Diamond(Sketch):
|
||||
def __init__(
|
||||
self,
|
||||
height: float,
|
||||
align: Union[Align, Tuple[Align, Align]] = None,
|
||||
):
|
||||
diamond = Bezier((135, 0), (94, 69), (47, 134), (0, 198))
|
||||
diamond += mirror(diamond, about=Plane.XZ)
|
||||
diamond += mirror(diamond, about=Plane.YZ)
|
||||
diamond = make_face(diamond)
|
||||
diamond = scale(diamond, by=height / diamond.bounding_box().size.Y)
|
||||
|
||||
super().__init__(diamond.wrapped)
|
||||
# self._align(align)
|
||||
|
||||
|
||||
# The inside of the box fits 2.5x3.5" playing card deck with a small gap
|
||||
pocket_w = 2.5 * IN + 2 * MM
|
||||
pocket_l = 3.5 * IN + 2 * MM
|
||||
pocket_t = 0.5 * IN + 2 * MM
|
||||
wall_t = 3 * MM # Wall thickness
|
||||
bottom_t = wall_t / 2 # Top and bottom thickness
|
||||
lid_gap = 0.5 * MM # Spacing between base and lid
|
||||
lip_t = wall_t / 2 - lid_gap / 2 # Lip thickness
|
||||
|
||||
|
||||
box_plan = RectangleRounded(pocket_w + 2 * wall_t, pocket_l + 2 * wall_t, pocket_w / 15)
|
||||
box = extrude(box_plan, amount=bottom_t + pocket_t / 2)
|
||||
base_top = box.faces().sort_by(Axis.Z).last
|
||||
walls = Plane(base_top) * Offset(box_plan, amount=-lip_t)
|
||||
box += extrude(walls, amount=pocket_t / 2)
|
||||
top = Plane.XY.offset(wall_t / 2) * Offset(box_plan, amount=-wall_t)
|
||||
box -= extrude(top, amount=pocket_t)
|
||||
|
||||
|
||||
pocket = extrude(box_plan, amount=pocket_t / 2 + bottom_t)
|
||||
lid_bottom = offset(box_plan, amount=-(wall_t - lip_t))
|
||||
pocket -= extrude(lid_bottom, amount=pocket_t / 2)
|
||||
pocket = Pos(0, 0, (wall_t + pocket_t) / 2) * pocket
|
||||
|
||||
plane = Plane(pocket.faces().sort_by().last)
|
||||
suites = Pos(-0.3 * pocket_w, 0.3 * pocket_l) * Heart(pocket_l / 5)
|
||||
suites += Pos(-0.3 * pocket_w, -0.3 * pocket_l) * Diamond(pocket_l / 5)
|
||||
suites += Pos(0.3 * pocket_w, 0.3 * pocket_l) * Spade(pocket_l / 5)
|
||||
suites += Pos(0.3 * pocket_w, -0.3 * pocket_l) * Club(pocket_l / 5)
|
||||
suites = plane * suites
|
||||
|
||||
lid = pocket - extrude(suites, dir=(0, 0, 1), amount=-wall_t)
|
||||
|
||||
if "show_object" in locals():
|
||||
show_object(box, name="box")
|
||||
show_object(lid, name="lid", options={"alpha": 0.6})
|
||||
Loading…
Add table
Add a link
Reference in a new issue