[Android Apps and Games] Tamasaka:
Graph paper (log)

I prepared yet another graph paper. Design of linear coordinate is based on Canguy247's "Graph paper".

In this version logarithmic coordinates and color options were added.

Parameter 1 is the number of logarithmic axes. 0 is for linear coordinate, 1 is for semi-log and 2 is for log-log coordinate.

Parameter 2 gives the length of decade of log-axis.

Parameter 3 selects the color of grid line and frame.

Parameter 4 selects the color of background. 0 is for transparence.

Parameter 5 is the switch for snapping to grid.

Color, line width, opacity and softness of current pencil do not affect the resulting graph paper. When "Pencil draws behind other colors" option is selected in custom pencil settings, the graph paper is drawn behind the other colors. This property is not a demerit. You can draw graph paper behind the plotted data. Anyway in most case, it is better to use layers for this purpose. ;)

/* Graph paper (log) ver.1.05 */
logaxis = 1;
logspacing = 1;
linecolor = 1;
bgcolor = 1;
snap = 1;
if (LN.getNumberOfParameters() >= 1)
logaxis = LN.getParameter(1); /* Log axis, 0 ≤ Parameter(1) ≤ 2, 3 steps */
if (LN.getNumberOfParameters() >= 2)
logspacing = LN.getParameter(2); /* Grid spacings per logarithmic decade,1 ≤ Parameter(2) ≤ 4, 4 steps */
if (LN.getNumberOfParameters() >= 3)
linecolor = LN.getParameter(3); /* Line color (1:turquoise, 2:mint, 3:sepia), 1 ≤ Parameter(3) ≤ 3, 3 steps */
if (LN.getNumberOfParameters() >= 4)
bgcolor = LN.getParameter(4); /* Background (0:clear, 1:snow, 2:ash, 3:sky, 4:ivory), 0 ≤ Parameter(4) ≤ 4, 5 steps */
if (LN.getNumberOfParameters() >= 5)
snap = LN.getParameter(5); /* Snap to grid (1:on), 0 ≤ Parameter(5) ≤ 1, 2 steps */

width = LN.getWidth();
scale = LN.getScale();
step = width / 150 + scale * width / 25;
fineStep=step/5;
LN.setSoftness(0);
LN.setAlpha(1);
ystep = xstep = step * logspacing;
if (logaxis < 2)
xstep = step;
if (logaxis < 1)
ystep = step;
x1 = LN.getX1();
y1 = LN.getY1();
x2 = LN.getX2();
y2 = LN.getY2();

if (snap) {
x1 = step/2 + Math.floor((x1 - step/2) / step + 0.5) * step;
y1 = step/2 + Math.floor((y1 - step/2) / step + 0.5) * step;
x2 = step/2 + Math.floor((x2 - step/2) / step + 0.5) * step;
y2 = step/2 + Math.floor((y2 - step/2) / step + 0.5) * step;
}
xmin = Math.min(x1, x2);
xmax = Math.max(x1, x2);
ymin = Math.min(y1, y2);
ymax = Math.max(y1, y2);
LN.setClip(xmin, ymin, xmax, ymax);

switch (bgcolor) {
default:
LN.setColor(1, 1, 1);
break;
case 2:
LN.setColor(0.97, 0.97, 0.97);
break;
case 3:
LN.setColor(0.95, 1, 1);
break;
case 4:
LN.setColor(1, 1, 0.95);
break;
}
if (bgcolor > 0) {
LN.drawFilledRect(xmin, ymin, xmax, ymax);
}

switch (linecolor) {
default:
LN.setColor(0, 0, 0);
break;
case 1:
LN.setColor(0.3, 0.85, 0.9);
break;
case 2:
LN.setColor(0.4, 0.9, 0.65);
break;
case 3:
LN.setColor(0.8, 0.65, 0.5);
break;
}

LN.setStrokeWidth(0.5);
if (logaxis < 2) {
for(i = xmin; i <= xmax; i += fineStep) {
LN.drawLine(i, ymin, i, ymax);
}
}
else {
for(i = xmin; i < xmax; i += xstep) {
for (j = 2; j <= 9; j++) {
xlog = i + Math.log(j) / Math.LN10 * xstep;
if (xlog >= xmax)
break;
LN.drawLine(xlog, ymin, xlog, ymax);
}
}
}
if (logaxis < 1) {
for(i = ymax; i >= ymin; i -= fineStep) {
LN.drawLine(xmin, i, xmax, i);
}
}
else {
for(i = ymax; i > ymin; i -= ystep) {
for(j=2; j <= 9; j++) {
ylog = i - Math.log(j) / Math.LN10 * ystep;
if (ylog <= ymin)
break;
LN.drawLine(xmin, ylog, xmax, ylog);
}
}
}

LN.setStrokeWidth(1);
for(i = xmin; i <= xmax; i += xstep) {
LN.drawLine(i, ymin, i, ymax);
}
for(i = ymax; i >= ymin; i -= ystep) {
LN.drawLine(xmin, i, xmax, i);
}
LN.setStrokeWidth(1.5);
LN.drawRect(xmin, ymin, xmax, ymax);