slatwall
A Crystal shard that plans a slat panel TV media wall section:
- how many panels go across the wall, and how many rows are needed;
- how many slats fit on one panel with a minimum gap;
- the real gap when the slats are spread evenly;
- how many panels to order, with and without one spare;
- the wall area, and the width and height of a 16:9 TV from its diagonal.
All lengths are in inches. There are no dependencies.
The numbers are the same as the interactive planner at getmediawall.com/design-your-wall, and as GetMediaWall's tools in other languages (Rust, D, Julia, OCaml and Haskell).
Installation
Add the dependency to your shard.yml:
dependencies:
slatwall:
github: getmediawall/slatwall-cr
Then run shards install.
Usage
require "slatwall"
# A 10 ft x 8 ft section with the default 24 x 96 in panels,
# 1.1 in slats and at least 0.75 in between slats
plan = Slatwall.plan(Slatwall::Wall.new(width: 120, height: 96))
plan.panels_across # => 5
plan.rows # => 1
plan.slats_per_panel # => 12
plan.gap.round(2) # => 0.9
plan.order_with_spare # => 6
plan.area_sq_ft # => 80.0
# Panels from a different maker
plan = Slatwall.plan(Slatwall::Wall.new(width: 100, height: 94,
panel_width: 23.6, panel_length: 94.5, slat: 1.06, min_gap: 0.5))
plan.panels_across # => 5
plan.slats_per_panel # => 15
# A wall taller than one panel needs a second row
Slatwall.plan(Slatwall::Wall.new(width: 192, height: 108)).order # => 16
# Screen size of a 65" 16:9 TV
w, h = Slatwall.tv_size(65) # => {56.65..., 31.87...}
If a length is zero, negative or not a number, the shard raises
Slatwall::InvalidInput and names the field that is wrong.
The example program in examples/plan_wall.cr prints a plan for any wall:
$ crystal run examples/plan_wall.cr -- 144 96 75
Wall 144.0 x 96.0 in (96.0 sq ft)
Panels: 6 across x 1 row(s) = 6, buy 7 with a spare
Slats per panel: 12, gap 0.9 in
75" TV: 65.4 x 36.8 in screen
Plan it visually: https://getmediawall.com/design-your-wall
How the numbers are worked out
| Value | Formula | |---|---| | Panels across | ceil(wall width / panel width) | | Rows | ceil(wall height / panel length) | | Slats per panel | floor(panel width / (slat + minimum gap)), at least 1 | | Real gap | panel width / slats per panel − slat width | | Order | panels across × rows, plus 1 spare | | TV width and height | diagonal × 16/√337 and diagonal × 9/√337 |
The ceil and floor steps use a 1e-9 tolerance. This stops floating point noise from adding a panel: exactly 120 in of wall with 24 in panels gives 5 panels, not 6.
The defaults are typical values only. Use the data sheet of the panels you install. Mount the TV into studs or masonry behind the panels, never into the felt backing alone. For a full plan (mount height, seating distance, cable runs), use the Design Your Wall planner.
Development
crystal spec
crystal docs
License
MIT © GetMediaWall (getmediawall.com). The code was written with an AI assistant (Claude). It was checked by specs against the reference values of the other GetMediaWall implementations.