diff --git a/README.md b/README.md index 7410182..e7f65b2 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Patterns are widely used in common objects, and so are the possible usages of this module: - [alveolar reinforcement](examples/reinforcement/) - [moucharabieh](examples/moucharabieh/) - - decorative patterns + - [decorative patterns](examples/decorative/) - surface texturing ## Examples diff --git a/examples/decorative/README.md b/examples/decorative/README.md new file mode 100644 index 0000000..7d0a890 --- /dev/null +++ b/examples/decorative/README.md @@ -0,0 +1,8 @@ +# A decorative pattern + +This example shows how to build a box, whose top is filled with a decorative pattern. + +## Showcase + +![pattern](images/decorative_pattern.png?raw=true) +![the finished box](images/decorative_box.png?raw=true) diff --git a/examples/decorative/decorative.scad b/examples/decorative/decorative.scad new file mode 100644 index 0000000..7a4ec89 --- /dev/null +++ b/examples/decorative/decorative.scad @@ -0,0 +1,63 @@ +// First, include the module +use <../../pattern.scad> + +// Define the base shape: a curvy bean +module bean(r1, r2, spacing, h1, h2) { + translate([ -spacing / 2, 0, 0 ]) circle(r = r1, center = true); + translate([ spacing / 2, 0, 0 ]) circle(r = r1, center = true); + difference() { + square([ spacing, h1 * 2 ], center = true); + translate([0, h2, 0]) circle(r = r2, center = true); + translate([0, -h2, 0]) circle(r = r2, center = true); + } +} + +module bean_pattern(bounding_box, r1 = 5, r2 = 10, spacing = 20, margin = 1) { + h2 = sqrt(pow(r1 + r2, 2) - pow(spacing / 2, 2)); // Pythagore theorem + h1 = h2 * r1 / (r2 + r1); // Thales theorem + distance = h2 - r2 + margin + spacing / 2 + r1; + + // Define our moves: how the pattern is sprayed + moves = [ + [ r1 * 2 + spacing + 2 * (h2 - r2 + margin), 0 ], + [ 0, r1 * 2 + spacing + 2 * (h2 - r2 + margin) ], + ]; + + spray_pattern(bounding_box, moves) { + // four beans arranged in a way the pattern repeat itself + bean(r1, r2, spacing, h1, h2); + translate([ 0, distance ]) rotate([0, 0, 90]) bean(r1, r2, spacing, h1, h2); + translate([ distance, distance ]) bean(r1, r2, spacing, h1, h2); + translate([ distance, 0 ]) rotate([0, 0, 90]) bean(r1, r2, spacing, h1, h2); + } +} + +// Instanciate the base shape, once. +translate([-100, -100, 0]) + bean_pattern([[0,0],[10,10]]); + +// The size of our box that will receive the decorative pattern +margin = 5; +width = 110; +length = 210; + +// Define the boundaries: the area to spray is defined by a rectangle +bounding_box = [ + [ margin, margin ], // Lower left corner + [ length + margin, width + margin ] // upper right corner +]; + +scale([ 1, 1, -1 ]) // Flip on z axis +difference () { + // The box + cube([ length + 2 * margin, width + 2 * margin, 20 ]); + + // A linear extrusion of the pattern + linear_extrude(3, center=true, convexity = 4) { // Due to the bean shape, convexity needs to be set + intersection () { // crop the pattern to the final size, leaving a margin around + translate(bounding_box[0]) + square(size = [ length, width ]); + bean_pattern(bounding_box); + } + } +} diff --git a/examples/decorative/images/decorative_box.png b/examples/decorative/images/decorative_box.png new file mode 100644 index 0000000..447ee04 Binary files /dev/null and b/examples/decorative/images/decorative_box.png differ diff --git a/examples/decorative/images/decorative_pattern.png b/examples/decorative/images/decorative_pattern.png new file mode 100644 index 0000000..dc5fefa Binary files /dev/null and b/examples/decorative/images/decorative_pattern.png differ