[Android Apps and Games] Tamasaka:
Bracket

This script draws a left bracket or a right bracket. It takes five parameters as follows.

1.Maximum width of bracket. Width of bracket is controlled by selection's end x coordinate up to this limit.

2.Select the shape from square bracket, round bracket, hexagon bracket (aka tortoise shell bracket) or brace.

3.Curliness of round bracket. Larger value curls both ends of bracket.

4.Curliness of brace. Larger value curls the center peak and both ends of brace.

5.Free or snap to grid.

/* Bracket ver. 1.09 */
maxwidth = 4;
shape = 0;
roundcurl = 3;
bracecurl = 4;
snap = 1;
if (LN.getNumberOfParameters() >= 1)
maxwidth = LN.getParameter(1); /* Maximum width, 1 ≤ Parameter(1) ≤ 6, 6 steps */
if (LN.getNumberOfParameters() >= 2)
shape = LN.getParameter(2); /* Shape (0:square,1:round, 2:hexagon[tortoise shell], 3:brace), 0 ≤ Parameter(2) ≤ 3, 4 steps */
if (LN.getNumberOfParameters() >= 3)
roundcurl = LN.getParameter(3); /* Curliness of round bracket, 1 ≤ Parameter(3) ≤ 5, 5 steps */
if (LN.getNumberOfParameters() >= 4)
bracecurl = LN.getParameter(4); /* Curliness of brace, 1 ≤ Parameter(4) ≤ 5, 5 steps */
if (LN.getNumberOfParameters() >= 5)
snap = LN.getParameter(5); /* Snap to grid (0:off), 0 ≤ Parameter(5) ≤ 1, 2 steps */

x1 = LN.getX1();
y1 = LN.getY1();
x2 = LN.getX2();
y2 = LN.getY2();

switch (shape) {
default:
case 0:
case 2:
widthfactor = 6;
break;
case 1:
widthfactor = 10;
break;
case 3:
widthfactor = 5;
break;
}

if (snap) {
width = LN.getWidth();
scale = LN.getScale();
step = width / 150 + scale * width / 25;
x1 = (step / 2) + Math.floor((x1 - (step / 2)) / step + 0.5) * step;
y1 = (step / 2) + Math.floor((y1 - (step / 2)) / step + 0.5) * step;
y2 = (step / 2) + Math.floor((y2 - (step / 2)) / step + 0.5) * step;
finestep = Math.abs(y2 - y1) * widthfactor / 120;
x2 = x1 + Math.floor((x2 - x1 - (finestep / 2)) / finestep + 0.5) * finestep;
}
xmin = Math.min(x1, x2);
xmax = Math.max(x1, x2);
ymin = Math.min(y1, y2);
ymax = Math.max(y1, y2);
bracketwidth = radius = Math.min((ymax - ymin) * maxwidth * widthfactor / 120, xmax - xmin);
yradius = Math.min((ymax - ymin) * maxwidth * widthfactor / 60, (ymax - ymin) / 2, (xmax - xmin) * 2);
LN.setClip(x1 - radius, ymin, x1 + radius, ymax);

switch (shape) {
default:
case 0:
if (LN.getStrokeCap() == 1)
LN.setStrokeCap(2);
if (x1 < x2) {
LN.drawLine(xmin + bracketwidth , ymin, xmin, ymin);
LN.drawLine(xmin, ymax, xmin + bracketwidth , ymax);
}
else {
LN.drawLine(xmax - bracketwidth , ymin, xmax, ymin);
LN.drawLine(xmax, ymax, xmax - bracketwidth , ymax);
}
LN.setStrokeCap(0);
LN.drawLine(x1, ymin, x1, ymax);
break;
case 1:
theta = Math.PI * (roundcurl + 3) / 16;
if (x1 < x2) {
LN.drawArc(x1 + radius, ymax - yradius , radius, yradius, Math.PI - theta, theta);
LN.drawArc(x1 + radius, ymin + yradius, radius, yradius, Math.PI, theta);
}
else {
LN.drawArc(x1 - radius, ymax - yradius, radius, yradius, 0, theta);
LN.drawArc(x1 - radius, ymin + yradius, radius, yradius, - theta, theta);
}
LN.setStrokeCap(0);
LN.drawLine(x1, ymin + yradius, x1, ymax - yradius);
break;
case 2:
ycut= bracketwidth / Math.tan(Math.PI /3);
if (x1 < x2) {
LN.drawLine(xmin + bracketwidth , ymin, xmin, ymin + ycut);
LN.drawLine(xmin, ymax - ycut, xmin + bracketwidth , ymax);
}
else {
LN.drawLine(xmax - bracketwidth , ymin, xmax, ymin + ycut);
LN.drawLine(xmax, ymax - ycut, xmax - bracketwidth , ymax);
}
LN.setStrokeCap(0);
LN.drawLine(x1, ymin + ycut, x1, ymax - ycut);
break;
case 3:
theta = Math.PI * (bracecurl + 3) / 16;
ycurl = radius * Math.sin(theta);
if (x1 < x2) {
LN.drawArc(x1 + radius, ymax - radius, radius, Math.PI - theta, theta);
LN.drawArc(x1 + radius, ymin + radius, radius, Math.PI, theta);
if (bracecurl < 4)
LN.setStrokeCap(0);
LN.drawArc(x1 - radius, (ymax + ymin) / 2 + ycurl, radius, - theta, theta);
LN.drawArc(x1 - radius, (ymax + ymin) / 2 - ycurl, radius, 0, theta);
}
else {
LN.drawArc(x1 - radius, ymax - radius, radius, 0, theta);
LN.drawArc(x1 - radius, ymin + radius, radius, - theta, theta);
if (bracecurl < 4)
LN.setStrokeCap(0);
LN.drawArc(x1 + radius, (ymax + ymin) / 2 + ycurl, radius, Math.PI, theta);
LN.drawArc(x1 + radius, (ymax + ymin) / 2 - ycurl, radius, Math.PI - theta, theta);
}
LN.setStrokeCap(0);
LN.drawLine(x1, ymin + radius, x1, (ymax + ymin) / 2 - ycurl);
LN.drawLine(x1, ymax - radius, x1, (ymax + ymin) / 2 + ycurl);
break;
}