Skip to content

Instantly share code, notes, and snippets.

@crides
Last active December 31, 2021 21:19
Show Gist options
  • Save crides/5c702c65d93d3391ffb3d97fb54dab3e to your computer and use it in GitHub Desktop.
Save crides/5c702c65d93d3391ffb3d97fb54dab3e to your computer and use it in GitHub Desktop.
import math
from solidff import *
import solid
DEV = False
if DEV:
num_len = 2
num_width = 2
else:
num_len = 4
num_width = 9
channel_width = 0.5
hole_len = 3
hole_width = 1.2
hole_dist = 4.4
tolerance = 0.1
stem_len = 10
stem_width = 4.3
stem_nub_width = 3
stem_nub_depth = 1
thick = 0.75
wall_thick = 1
base_thick = 3
corner_r = 0.5
expand_r = 1.25
rail_gap = 0.5
total_thick = base_thick + thick
rail_offset = rail_gap + 1
bar_width = 1.5
base = s(stem_len, stem_width, True)
nub = s(stem_nub_width, stem_nub_depth).x(-stem_nub_width/2).y(stem_width / 2)
out_shape = (base + nub).o(delta=-(expand_r - corner_r)).o(r=expand_r + tolerance)
wall_height = thick + base_thick
hole = s(hole_width, hole_len).y(-hole_len / 2).x(hole_dist / 2).o(r=tolerance)
holes = (hole + hole.r(180))
mask = (mask_sketch := (out_shape - holes)).e(thick + 0.01)
mold_width = stem_width + stem_nub_depth + 2 * tolerance + wall_thick + 2 * 0.5
mold_len = stem_len + 2 * tolerance + wall_thick + 2 * 0.5
mold = s(mold_len, mold_width).e(total_thick).z(-base_thick)
stem_x_center = wall_thick / 2 + stem_len / 2 + 0.5 + tolerance
mold -= mask.r(180).t(stem_x_center, wall_thick + stem_width / 2 + 0.5 + tolerance + stem_nub_depth)
mold -= q(channel_width, wall_thick, thick).x(stem_x_center - channel_width / 2)
if not DEV:
mold = mold.render()
base_len = wall_thick + num_len * mold_len
base_width = wall_thick + num_width * mold_width
col = sum(mold.y(mold_width * i) for i in range(num_width))
# col += q(mold_len, wall_thick, total_thick).z(-base_thick).y(-wall_thick)
# col -= (funnel := b(r=wall_thick).t(stem_x_center, -wall_thick)).z(thick / 2) + funnel.z(-base_thick - thick / 2)
cols = sum(col.x(mold_len * i) for i in range(num_len))
total_width = mold_width * num_width
total_len = mold_len * num_len
half_bar_gap = (base_thick - bar_width) / 2
side_frame = q(wall_thick, total_width, total_thick).z(-base_thick)
side_frame += q(wall_thick, total_width + wall_thick + bar_width, total_thick - rail_gap).t(wall_thick, -bar_width, -base_thick + rail_offset)
bot_frame = q(total_len + 2*wall_thick, wall_thick, total_thick).z(-base_thick).t(-wall_thick, total_width)
top_bar = q(total_len + 2*wall_thick, bar_width, bar_width).t(-wall_thick, -bar_width, -half_bar_gap - bar_width)
frames = side_frame.m(1, 0, 0) + side_frame.x(total_len) + bot_frame + top_bar
cover_thick = half_bar_gap + bar_width
whole = cols + frames
cover = q(total_len + 2*wall_thick, total_width + wall_thick, cover_thick).x(-wall_thick) + q(total_len + 2*wall_thick, bar_width, bar_width).t(-wall_thick, -bar_width, half_bar_gap)
def masks_sketch():
col = sum(mask_sketch.y(mold_width * i) for i in range(num_width))
cols = sum(col.x(mold_len * i) for i in range(num_len))
return cols
def masks_sketch2(num_rows, num_cols):
row = sum(mask_sketch.x(mold_len * i) for i in range(num_cols))
flipped = mask_sketch.r(180).t(mold_len / 2, mold_width - 0.25)
flipped_row = sum(flipped.x(mold_len * i) for i in range(num_cols - 1))
group = row + flipped_row
group_width = 2 * wall_thick + stem_width + mold_width
return sum(group.y(group_width * i) for i in range(num_rows)).t(stem_x_center + wall_thick, wall_thick + stem_width / 2 + 0.5 + tolerance + stem_nub_depth)
cover.dump("cover.scad")
masks_sketch2(4, 10).dump("mask.scad")
whole.dump_this()
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View raw

(Sorry about that, but we can’t show files that are this big right now.)

Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment