Routines to quickly position 2D elements on the edges of a rectagular canvas on the XY-plane.
PTop( canvas ) | position children on top of the canvas |
PBottom( canvas ) | position children at the bottom of the canvas, mirror of PTop() |
PLeft( canvas ) | position children on the left of the canvas |
PRight( canvas ) | position children on the right of the canvas, mirror of PLeft() |
PFTop( canvas ) | same as PTop() but flipped |
PFBottom( canvas ) | same as PBottom() but flipped |
PFLeft( canvas ) | same as PLeft() but flipped |
PFRight( canvas ) | same as PRight() but flipped |
MUp( offset ) | move up |
MDown( offset ) | move down |
MLeft( offset ) | move left |
MRight( offset ) | move right |
canvas | height of canvas |
leftRight = 0 | left/right offset, right+ |
canvas | height of canvas |
leftRight = 0 | left/right offset, right+ |
canvas | width of canvas |
upDown = 0 | up/down offset, up+ |
canvas | width of canvas |
upDown = 0 | up/down offset, up+ |
offset | distance to move up |
leftRight = 0 | left/right offset, right+ |
offset | distance to move down |
leftRight = 0 | left/right offset, right+ |
offset | distance to move left |
upDown = 0 | up/down offset, up+ |
offset | distance to move right |
upDown = 0 | up/down offset, up+ |
cWidth = 80;
cHeight = 100;
// normal top/left
// bottom/right - mirror
canvas();
target();
color("red") PTop (cHeight) target();
color("green") PBottom(cHeight) target();
color("blue") PLeft (cWidth ) target();
color("orange") PRight (cWidth ) target();
// flipped top/left
// bottom/right - mirror
translate([120,0,0]) {
canvas();
target();
color("red") PFTop (cHeight) target();
color("green") PFBottom(cHeight) target();
color("blue") PFLeft (cWidth ) target();
color("orange") PFRight (cWidth ) target();
}
// move only
translate([240,0,0]) {
canvas();
circle(5);
color("red") MUp (20) circle(5);
color("green") MDown (20) circle(5);
color("blue") MLeft (20) circle(5);
color("orange") MRight(20) circle(5);
}
module canvas() {
color("gray")
translate([0,0,-1])
square([cWidth,cHeight],center=true);
color("red") translate([0,0,1]) {
square([cWidth,1],center=true);
square([1,cHeight],center=true);
}
}
module target() {
linear_extrude(1)
difference() {
polygon([[-15,0],[15,0],[15,-15],[-15,-5]]);
circle(3);
}
}