Browse Source

add a decorative example

master 1.0
Nicolas Massé 8 years ago
parent
commit
24b508235e
  1. 2
      README.md
  2. 8
      examples/decorative/README.md
  3. 63
      examples/decorative/decorative.scad
  4. BIN
      examples/decorative/images/decorative_box.png
  5. BIN
      examples/decorative/images/decorative_pattern.png

2
README.md

@ -9,7 +9,7 @@ Patterns are widely used in common objects, and so are the possible usages of
this module: this module:
- [alveolar reinforcement](examples/reinforcement/) - [alveolar reinforcement](examples/reinforcement/)
- [moucharabieh](examples/moucharabieh/) - [moucharabieh](examples/moucharabieh/)
- decorative patterns - [decorative patterns](examples/decorative/)
- surface texturing - surface texturing
## Examples ## Examples

8
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)

63
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);
}
}
}

BIN
examples/decorative/images/decorative_box.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 149 KiB

BIN
examples/decorative/images/decorative_pattern.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Loading…
Cancel
Save