[Android Apps and Games] Tamasaka:
Parallelogram

This script draws a parallelogram ABCD where A is the start point and B is the end point of selection box. Sides BC and DA are parallel to Y-axis.

Parameter 1 indicates height or length of side BC. The length is given by product of parameter 1 and spacing of coarse grid which is same as the acadoid's standard grid.

Parameter 2 is the switch for filling.

Parameter 3 is the switch to snap start point (corner A) to grid. 1 is for snapping to fine grid which is 1/5 of the coarse grid. 2 is for snapping to the coarse grid.

Parameter 4 is the switch to snap end point (corner B) to grid. 1 is for snapping to the fine cartesian grid while based on the start point (cornar A). 2 is for snapping to coaxial grid which is centered around the start point (corner A) with angle of every 5 degrees, and the length of AB snaps to 1/5 of the coarse grid.

Snapping selection has 9 patterns (3 × 3) in which the pattern "fine start point and fine end point" gives easily continuous parallelograms.

The height is semi-fixed, though it is scalable by parameter 1. We can select angle and aspect ratio of parallelogram by start point and end point of selection box. After drawing parallelogram, we can resize and rotate it by the ‘Cutter’.

/* Parallelogram ver. 1.07 */
quadrheight = 1;
fill = 0;
snapstart = 0;
snapend = 0;
if (LN.getNumberOfParameters() >= 1)
quadrheight = LN.getParameter(1); /* Height (in coarse grid spacings), 0.2 ≤ Parameter(1) ≤ 4.0, 20 steps */
if (LN.getNumberOfParameters() >= 2)
fill = LN.getParameter(2); /* Fill (0:open, 1:filled), 0 ≤ Parameter(2) ≤ 1, 2 steps */
if (LN.getNumberOfParameters() >= 3)
snapstart = LN.getParameter(3); /* Snap start point to grid (0:free, 1:fine, 2:coarse), 0 ≤ Parameter(3) ≤ 2, 3 steps */
if (LN.getNumberOfParameters() >= 4)
snapend = LN.getParameter(4); /* Snap end point to grid (0:free, 1:fine, 2:coaxial), 0 ≤ Parameter(4) ≤ 2, 3 steps */

width = LN.getWidth();
scale = LN.getScale();
step = width / 150 + scale * width / 25;
finestep = step / 5;
astep = Math.PI / 36;
ylength = step * quadrheight;

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

if (snapstart == 1) {
x1 = finestep / 2 + Math.floor((x1 - finestep / 2) / finestep + 0.5) * finestep;
y1 = finestep / 2 + Math.floor((y1 - finestep / 2) / finestep + 0.5) * finestep;
}
else if (snapstart == 2) {
x1 = step / 2 + Math.floor((x1 - step / 2) / step + 0.5) * step;
y1 = step / 2 + Math.floor((y1 - step / 2) / step + 0.5) * step;
}
if (snapend == 1) {
x2 = x1 + Math.floor((x2 - x1 - finestep / 2) / finestep + 0.5) * finestep;
y2 = y1 + Math.floor((y2 - y1 - finestep / 2) / finestep + 0.5) * finestep;
}
else if (snapend == 2) {
angle = Math.atan2(y2 - y1, x2 - x1);
ag = Math.floor(angle / astep + 0.5) * astep;
distance = Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
dt = Math.floor(distance / finestep + 0.5) * finestep;
x2 = x1 + dt * Math.cos(ag);
y2 = y1 + dt * Math.sin(ag);
}

x3 = x2;
y3 = y2 - ylength;
x4 = x1;
y4 = y1 - ylength;

xmin = Math.min(x1, x2);
xmax = Math.max(x1, x2);
ymin = Math.min(y1, y2);
ymax = Math.max(y1, y2);

LN.setClip(xmin, ymin - ylength, xmax, ymax);
if (fill)
LN.drawFilledQuadrangle(x1, y1, x2, y2, x3, y3, x4, y4);
else {
LN.drawLine(x1, y1, x2, y2);
LN.drawLine(x2, y2, x3, y3);
LN.drawLine(x3, y3, x4, y4);
LN.drawLine(x4, y4, x1, y1);
}