yashsingh1/xdaforums huggingface dataset:
[Android Apps and Games] jcziviani:
Code and suggestion

I made a coordinate system (grid) and Dotted Checkered pattern (code below) that works great together to make graphics.

As for Custom Drawing tools, I think the best way is like Firefox extensions or Google Play. Create a simple server that advanced users can upload drawing tools, and show these tools in a list inside LN, with screenshot, description, rating and an install button. When clicked, the tool is automatically downloaded and installed. This would make tools available for 95% users that does not know how to unzip and/or run scripts.

Julio.

Coordinate system (grid)

width = LN.getWidth();
scale = LN.getScale();
step = width / 150 + scale * width / 25;
strokewidth = LN.getStrokeWidth();
x1 = LN.getX1();
y1 = LN.getY1();
x2 = LN.getX2();
y2 = LN.getY2();
head = 10 * strokewidth;
headsin=head*0.389*0.8;
headcos=head* 0.921;

x1g = step/2 + Math.floor((x1-step/2)/(step*2)+0.5) * step*2;
y1g = step/2 + Math.floor((y1-step/2)/(step*2)+0.5) * step*2 ;
x2g = step/2 + Math.floor((x2-step/2)/(step*2)+0.5)* step*2;
y2g = step/2 + Math.floor((y2-step/2)/(step*2)+0.5) * step*2;
xmin = Math.min(x1g, x2g);
ymin = Math.min(y1g, y2g);
xmax = Math.max(x1g, x2g);
ymax = Math.max(y1g, y2g);
xavail = xmax-xmin;
yavail = ymax-ymin;
xorigin = xavail/2;
yorigin = yavail/2;

LN.setClip(xmin, ymin, xmax, ymax);
LN.setSoftness(0);
LN.drawLine(xmin, ymax - yorigin, xmax - headcos, ymax - yorigin);
LN.drawLine(xmin + xorigin, ymin + headcos, xmin + xorigin, ymax);
count =1;

for( x=step/5;x < (xavail-headcos-1); x += step/5) {
tick = (count++ % 5) ? step/8: step/4;
LN.drawLine( xmin +x, ymax-yorigin - tick, xmin+x,ymax-yorigin+tick);
}
count =1;

for( y=step/5;y < (yavail-headcos-1); y += step/5) {
tick = (count++ % 5) ? step/8: step/4;
LN.drawLine( xmin + xorigin-tick, ymax-y, xmin+xorigin+tick,ymax-y);
}
LN.drawFilledTriangle(xmax - headcos, ymax - yorigin + headsin, xmax, ymax - yorigin, xmax - headcos, ymax - yorigin - headsin);
LN.drawFilledTriangle(xmin + xorigin - headsin, ymin + headcos, xmin + xorigin, ymin, xmin + xorigin + headsin, ymin + headcos);

------------------------------------------
Dotted Checkered pattern (grid)

width = LN.getWidth();
scale = LN.getScale();
step = width / 150 + scale * width / 25;
strokewidth = LN.getStrokeWidth();
x1 = LN.getX1();
y1 = LN.getY1();
x2 = LN.getX2();
y2 = LN.getY2();
x1g = (step / 2) + Math.floor((x1 - (step / 2)) / step + 0.5) * step;
y1g = (step / 2) + Math.floor((y1 - (step / 2)) / step + 0.5) * step;
x2g = (step / 2) + Math.floor((x2 - (step / 2)) / step + 0.5) * step;
y2g = (step / 2) + Math.floor((y2 - (step / 2)) / step + 0.5) * step;
xmin = Math.min(x1g, x2g);
ymin = Math.min(y1g, y2g);
xmax = Math.max(x1g, x2g);
ymax = Math.max(y1g, y2g);
LN.setClip(xmin, ymin, xmax, ymax);
LN.setSoftness(0);
strokewidth = LN.getStrokeWidth();
dashing1 = (LN.getStrokeCap() == 1) ? strokewidth : 0.5;
dashing2 = (LN.getStrokeCap() == 1) ? dashing1 : dashing1 + 2 * strokewidth;
LN.setDashing(dashing1, dashing2);
LN.drawCheckeredPattern(scale, xmin - strokewidth / 2, ymin - strokewidth / 2, xmax + strokewidth / 2, ymax + strokewidth / 2);
[Android Apps and Games] acadoid:
[MENTION=5729018]jcziviani[/MENTION]: I guess you noticed that: The ZIP archive that LectureNotes produces upon sharing a custom drawing tool or container can be directly imported into LectureNotes, no need to manually unzip the archive.
[Android Apps and Games] jcziviani:
Drawing Tools List

The problem is not zip or unzip inside your application, this is trivial. The problem is the whole process. I will make an example, please correct me if my suppositions are wrong.

Let's assume some one in Brazil makes a great Drawing Tool. Let make 2 scenarios:

Scenario 1: Somehow an user is aware that someone in Brazil made a drawing tool that might be interesting (this itself is an unlikely event to happen). First, he has to google it and go to some site, forum, github or whatever to find it. Then he has to download it, using a browser or something like that. Then he has to know which folder it was downloaded (usually not shown), and open that folder in import menu inside LN to get access to plugin. You may think this is easy because you are a developer and you do it all the time. But ask an average user to do that. Sit beside him and just watch what he is doing.

Scenario 2: User opens Custom Drawing Tool in LN, it shows a list of available custom tools. He finds a tool interesting in the list. He clicks "install".
[Android Apps and Games] acadoid:
[MENTION=5729018]jcziviani[/MENTION]: I agree that `sharing´ (exporting) and importing custom drawing tools is only the very first and very last step. However, to setup a kind of `marketplace´ (whether it is commercial or not) is not trivial.

If I am not mistaken, xda-developers.com allows to attach ZIP archives to posts, so that one can post custom drawing tools here. In fact, my intention of starting this thread (and the sibling thread http://xdaforums.com/showthread.php?t=1936617 concerning custom paper pattern) was to establish a platform for sharing. I agree that this is not as comfortable as your scenario (2) but has the advantage that it is readily available.
[Android Apps and Games] jcziviani:
A simple solution is not that hard to implement. You need basically one message to send tools to server and one to get the list from it. These messages can be using HTTP with XML or JSON content.

1) To upload the tool, the fields would be:

user email

tool title

tool description

and upload a zip file with code, screenshot and icon.

If the combination of "email"+"tool title" already exists, it is handled as an update, otherwise is handled as a new custom tool.

2) To make the list, your request would contain a list with:

title

description

icon URL

screenshot URL

code URL.

With that information, you can automatically download and install requested tool (downloading from "code URL", using FTP or HTTP).

For the server, a simple PHP solution can be made, storing data in a mysql database and images/zip files in a public folder. All you need is a basic VPS to host it.

If you want to use this solution, I can make server code and donate to you.
[Android Apps and Games] acadoid:
[MENTION=5729018]jcziviani[/MENTION]: Many thanks for your kind offer.

My description `not trivial´ was more concerning monetary and legal issues than concerning technical ones.
[Android Apps and Games] jcziviani:
type != int

Is it possible to use other parameter types? I was thinking to create function plotter, with a string function as parameter, and use eval() to compute graph values.
[Android Apps and Games] acadoid:
[MENTION=5729018]jcziviani[/MENTION]: Presently not, but to allow string parameters is an interesting idea, I noted it down.
[Android Apps and Games] Kuime:
That's what I m also looking for! Many thanks :victory:
[Android Apps and Games] herph:
Here's a variation of the stock Vertical and Horizontal lines that combines them into a single tool. If you want a horizontal line, just draw more horizontal than vertical, if you want a vertical line, draw more vertical than horizontal - up or down, right or left. I think you'll find it pretty handy.

width = LN.getWidth();

height = LN.getHeight();

x1 = LN.getX1();

y1 = LN.getY1();

x2 = LN.getX2();

y2 = LN.getY2();

xm = (x1 + x2) / 2;

ym = (y1 + y2) / 2;

if (Math.abs(x2-x1)>Math.abs(y2-y1))

{

LN.drawLine(x1, ym, x2, ym);

}

else

{

LN.drawLine(xm, y1, xm, y2);

}
[Android Apps and Games] Abudabilibre:
This is a tool to draw a cube.

width=LN.getWidth();
height=LN.getHeight();
size=Math.min(width, height);
strokewidth=LN.getStrokeWidth();
das1=0.01*size;
das2=(LN.getStrokeCap()==1)?das1:das1+2*strokewidth;
x1 = LN.getX1();
y1 = LN.getY1();
x2 = LN.getX2();
y2 = LN.getY2();
LN.drawRect(x1,y1+(y2-y1)/3,x1+(x2-x1)*2/3,y2);
LN.drawLine(x1+(x2-x1)/3,y1,x2,y1);
LN.drawLine(x2,y1,x2,y1+(y2-y1)*2/3);
LN.drawLine(x1+(x2-x1)/3,y1,x1,y1+(y2-y1)/3);
LN.drawLine(x2,y1,x1+(x2-x1)*2/3,y1+(y2-y1)/3);
LN.drawLine(x2,y1+(y2-y1)*2/3,x1+(x2-x1)*2/3,y2);
LN.setDashing(das1,das2);
LN.drawLine(x1+(x2-x1)/3,y1,x1+(x2-x1)/3,y1+(y2-y1)*2/3);
LN.drawLine(x1,y2,x1+(x2-x1)/3,y1+(y2-y1)*2/3);
LN.drawLine(x2,y1+(y2-y1)*2/3,x1+(x2-x1)/3,y1+(y2-y1)*2/3);
[Android Apps and Games] loripino13:
Circuit Compnents

Hi,

It would be amazing to have a tool that draws electrical components such as a resistor, a generator or a transistor!

Is there someone that would post the code?

Thanks!!
[Android Apps and Games] Abudabilibre:
And this is the 2D representation of a sphere:

width=LN.getWidth();
height=LN.getHeight();
size=Math.min(width, height);
strokewidth=LN.getStrokeWidth();
das1=0.01*size;
das2=(LN.getStrokeCap()==1)?das1:das1+2*strokewidth;
x1 = LN.getX1();
y1 = LN.getY1();
x2 = LN.getX2();
y2 = LN.getY2();
r=Math.min(Math.abs(x2-x1),Math.abs(y2-y1))/2;
pi=3.14159;
r2=2*r*0.866-r;
cx= (x1+x2)/2;
cy= (y1+y2)/2;
LN.drawCircle(cx ,cy,r);
LN.drawArc(cx+r+r2,cy,2*r,150*pi/180, 60*pi/180);
LN.drawArc(cx,cy-r-r2,2*r,60*pi/180, 60*pi/180);
LN.setDashing(das1,das2);
LN.drawArc(cx-r-r2,cy,2*r,330*pi/180, 60*pi/180);
LN.drawArc(cx,cy+r+r2 ,2*r,240*pi/180, 60*pi/180);
[Android Apps and Games] Tamasaka:
Rounded rectangles

This script draws a rounded rectangle with current pencil. It has two parameters: roundness of four corners and the switch for filling. If you skip setting the parameters, it works with default parameters. I wonder whether the tools must be simple or multi-functioned. In this script the code for filled rounded rectangle was combined with that for open one by using additional parameter.

Sorry, I cannot upload files. The following code may not be indented.

-----------------

roundness = 2;

fill = 0;

if (LN.getNumberOfParameters() >= 1)

roundness = LN.getParameter(1); /* 1 ≤ Parameter(1) ≤ 5 */

if (LN.getNumberOfParameters() >= 2)

fill = LN.getParameter(2); /* 0 ≤ Parameter(2) ≤ 1 (0: open, 1: filled) */

x1 = LN.getX1();

y1 = LN.getY1();

x2 = LN.getX2();

y2 = LN.getY2();

if (x1>=x2) {

xmin = x2;

xmax = x1;

}

else {

xmin = x1;

xmax = x2;

}

if (y1>=y2) {

ymin = y2;

ymax = y1;

}

else {

ymin = y1;

ymax = y2;

}

shortside = Math.min(xmax - xmin, ymax - ymin);

radius = shortside * roundness / 10;

if (fill) {

LN.drawFilledRect(xmax - radius, ymax, xmin + radius, ymin);

LN.drawFilledRect(xmin, ymax - radius, xmax, ymin + radius);

LN.drawFilledCircle(xmax - radius, ymax - radius, radius);

LN.drawFilledCircle(xmin + radius, ymax - radius, radius);

LN.drawFilledCircle(xmin + radius, ymin + radius, radius);

LN.drawFilledCircle(xmax - radius, ymin + radius, radius);

}

else {

LN.drawArc(xmax - radius, ymax - radius, radius, 0, Math.PI /2);

LN.drawLine(xmax - radius, ymax, xmin + radius, ymax);

LN.drawArc(xmin + radius, ymax - radius, radius, Math.PI / 2, Math.PI /2);

LN.drawLine(xmin, ymax - radius, xmin, ymin + radius);

LN.drawArc(xmin + radius, ymin + radius, radius, Math.PI, Math.PI /2);

LN.drawLine(xmin + radius, ymin, xmax - radius, ymin);

LN.drawArc(xmax - radius, ymin + radius, radius, Math.PI * 3 /2, Math.PI /2);

LN.drawLine(xmax, ymin + radius, xmax, ymax - radius);

}

-------------------
[Android Apps and Games] Adam.D:
Please Help! I need a tool for drawing coordinates in 3D

I do not know java. I would be happy if you help me to create something like that ...
[Android Apps and Games] Adam.D:
Please Help! I need a tool for drawing coordinates in 3D

I do not know java. I would be happy if you help me to create something like that ...

dropbox.com/s/xvysfs5cr6aaf6j/Screenshot_2014-04-25-01-01-19.png

And important to me that will be linked to the Pattern (Grid)

Thank you so much for helping
[Android Apps and Games] Tamasaka:
We can make your first 3D coordinate by using Canguy247's script "Graph paper" and above "Arrows in various shapes" with the parameter 5 (Snap to grid).

Fortunately the two scripts share the same grid.

The second 3D coordinate needs more modification.
[Android Apps and Games] Tamasaka:
Isometric drawing

This script draws a single line snapped to isometric grid.

Parameter 1 selects dashed lines. 0 is for solid line, 1 is for dashed line and 2 is for dotted line. Codes for dashed and dotted lines are same as acadoid's examples.

Parameter 2 is the switch for connecting any grid points. When this switch is off, direction of lines are limited in every 60 degrees.

Parameter 3 determines the grid spacing.

/* Isometric drawing ver. 1.03 */
dash = 0;
freeconnect = 0;
gridspacing = 5;
if (LN.getNumberOfParameters() >= 1)
dash = LN.getParameter(1); /* Dashed line (0:solid, 1:dash, 2:dot), 0 ? Parameter(1) ? 2, 3 steps */
if (LN.getNumberOfParameters() >= 2)
freeconnect = LN.getParameter(2); /* Connect any grid points (1:on), 0 ? Parameter(2) ? 1, 2 steps */
if (LN.getNumberOfParameters() >= 3)
gridspacing = LN.getParameter(3); /* Grid spacing, 1 ? Parameter(3) ? 15, 15 steps */

width = LN.getWidth();
height = LN.getHeight();
scale = LN.getScale();
step = width / 150 + scale * width / 25;
ys = step * gridspacing / 5;
xs = ys * Math.sqrt(3);

if (dash) {
size = Math.min(width, height);
strokewidth = LN.getStrokeWidth();
if (dash == 1)
dashing1 = 0.005 * size;
else
dashing1 = (LN.getStrokeCap() == 1) ? strokewidth : 0.5;
dashing2 = (LN.getStrokeCap() == 1) ? dashing1 : dashing1 + 2 * strokewidth;
LN.setDashing(dashing1, dashing2);
}

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

x1g = xs/2 + Math.floor((x1 - xs/2) / xs + 0.5) * xs;
y1g = ys/2 + Math.floor((y1 - ys/2) / ys + 0.5) * ys;
if ((x1 - x1g) > xs/4)
x1 = x1g + xs/2;
else if ((x1 - x1g) < -xs/4)
x1 = x1g - xs/2;
else {
x1 = x1g;
y1 = y1g;
}
if ((y1 - y1g) > 0)
y1 = y1g + ys/2;
else if ((y1 - y1g) < 0)
y1 = y1g - ys/2;

if (freeconnect) {
x2g = xs/2 + Math.floor((x2 - xs/2) / xs + 0.5) * xs;
y2g = ys/2 + Math.floor((y2 - ys/2) / ys + 0.5) * ys;
if ((x2 - x2g) > xs/4)
x2 = x2g + xs/2;
else if ((x2 - x2g) < -xs/4)
x2 = x2g - xs/2;
else {
x2 = x2g;
y2 = y2g;
}
if ((y2 - y2g) > 0)
y2 = y2g + ys/2;
else if ((y2 - y2g) < 0)
y2 = y2g - ys/2;
}
else {
astep = Math.PI / 3;
angle = Math.atan2(y2 - y1, x2 - x1);
ag = astep/2 + Math.floor((angle - astep/2) / astep + 0.5) * astep;
distance = Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
dg = Math.floor((distance) / ys + 0.5) * ys;
x2 = x1 + dg * Math.cos(ag);
y2 = y1 + dg * Math.sin(ag);
}

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);
LN.drawLine(x1, y1, x2, y2);
[Android Apps and Games] maddojf:
Feature request: drawing tool that inserts an image.

I have a feature request. I would like to be able to insert an image with a drawing tool. I would like to call a function with a filename and coordinates to have the image imported into the document at the location. i.e.

Pseudo-code:

LN.importImageScaled(filename, x1, y1, x2, y2)

LN.importImageNoScale(filename, x, y)
​

I would like to create a directory in the LectureNotes directory that contains the images I want to insert regularly. The filename passed to the function could then be relative to the LecureNotes main directory, i.e. images/commonlyusedfigure.png. I would also like to be able to specify whether or not the image gets scaled.

My primary use case would be to insert equations rended with LaTeX that I use as a starting point for many problems (an even better solution would be to allow LaTeX to be typeset by an external program somehow, but I can imagine that would be challenging to implement). I can also envision using this to add drawing tools that make shapes which are too complex to create with javascript.

Since the end result can already be achieved using the 'Import image'/'Import PDF' commands, I am hoping it will be possible to expose that functionality to the custom drawing tools so that I could make shortcuts.

Thanks for the great program.
[Android Apps and Games] acadoid:
[MENTION=5394275]maddojf[/MENTION]: The `paste from non-standard clipboard´ function is partially intended for clip art usage: LectureNotes also scans folders such as `Download´ and `Pictures´ (including subfolders), so that you place your clip art in one of these folders.
[Android Apps and Games] xnord:
Hello Tamasaka, is there a way to change your bracket script into a sigma sign script?

Thanks for your scripts and help :good:
[Android Apps and Games] Tamasaka:
Sigma

Try this script and please modify by yourself. Hope this helps.

/* Sigma ver. 0.01 */
minwidth = 7;
maxwidth = 15;
serif =0.12;
stepfactor = 10;

x1 = LN.getX1();
y1 = LN.getY1();
x2 = LN.getX2();
y2 = LN.getY2();
step = Math.abs(y2 - y1) * stepfactor / 120;
x2 = x1 + Math.floor((x2 - x1 - step / 2) / step + 0.5) * step;
y2 = y1 + Math.floor((y2 - y1 - 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);
xdiff = xmax - xmin;
ydiff20 = (ymax - ymin) / 20;
xmax = xmin + Math.max(Math.min(xdiff, ydiff20 * maxwidth), ydiff20 * minwidth);

LN.setClip(xmin, ymin, xmax, ymax);
LN.setStrokeCap(0);
LN.drawLine(xmin, ymin, xmax, ymin);
LN.drawLine(xmax, ymin, xmax, (ymax * serif + ymin) / (serif + 1));
LN.drawLine(xmin, ymin, (xmax * 2 + xmin) / 3, (ymax + ymin) /2);
LN.drawLine((xmax * 2 + xmin) / 3, (ymax + ymin) /2, xmin, ymax);
LN.drawLine(xmin, ymax, xmax, ymax);
LN.drawLine(xmax, ymax, xmax, (ymax + ymin * serif) / (serif + 1));
[Android Apps and Games] xnord:
Thanks Tamasaka, that one is perfect! :) :good:
[Android Apps and Games] Tamasaka:
Wavy line

It's a small tool to draw a horizontal wavy line with current pencil.

The only one parameter specifies the size of wave.

/* Wavy line ver. 1.00 */
wavesize = 4;
if (LN.getNumberOfParameters() >= 1)
wavesize = LN.getParameter(1); /* Wave size, 2 ≤ Parameter(1) ≤ 15, 14 steps */

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

xmin = Math.min(x1, x2);
xmax = Math.max(x1, x2);
ym = (y1 + y2) / 2;
a1 = Math.PI * 5/4;
a2 = Math.PI / 4;
as = Math.PI / 2;
p = wavesize;
radius = Math.sqrt(2) * p;
LN.setClip(xmin, ym - p, xmax, ym + p);
xp = xmin - p;
while (xp < xmax) {
LN.drawArc(xp += p * 2, ym + p, radius, a1, as);
LN.drawArc(xp += p * 2, ym - p, radius, a2, as);
}
[Android Apps and Games] Adam.D:
You're right!

You're right ... I want to use in your code and I do not know how ... I did copy paste software and it did not work.
[Android Apps and Games] Tintinnuntius:
Here's a script that draws a Koch line (fractal curve). Recursion depth and height of the bump are adjustable. Warning: Do not use recursion levels higher than 5 or so. The image will look the same or worse but performance will suffer greatly (to put it mildly).

The script for the Koch snowflake will be in the next post... Screenshots, too.

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

y = (y1+y2)/2;

level = LN.getParameter(1);
height = LN.getParameter(2);

a = Math.sqrt(3);
b = 1/a;
c = 1/2;
d = 2/3;
e = 1/3;
f = c*b*height;
t = LN.getStrokeWidth();
LN.setStrokeWidth(5*t/level);

function koch (x1, y1, x2, y2, level){
if (level == 0){
LN.drawLine(x1, y1, x2, y2);
}
if (level > 0){
level = level-1;
koch(x1, y1, d*x1+e*x2, d*y1+e*y2, level);
koch(d*x1+e*x2, d*y1+e*y2, c*(x1+x2)+f*(y2-y1),c*(y1+y2)-f*(x2-x1), level);
koch(c*(x1+x2)+f*(y2-y1),c*(y1+y2)-f*(x2-x1), e*x1+d*x2, e*y1+d*y2, level);
koch(e*x1+d*x2, e*y1+d*y2, x2, y2, level);
}
}

koch(x1,y, x2, y, level)
[Android Apps and Games] Tintinnuntius:
Here's a script for Koch snowflake. Recursion depth and height of the bump are adjustable. Warning: Do not use recursion levels higher than 5 or so. The image will look the same or worse but performance will suffer greatly (to put it mildly).

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

x0 = (x1+x2)/2;
y0 = (y1+y2)/2;

level = LN.getParameter(1);
height = LN.getParameter(2);

pi = 3.14159;
a = Math.sqrt(3);
b = 1/a;
c = 1/2;
d = 2/3;
e = 1/3;
f = c*b*height;
t = LN.getStrokeWidth();
LN.setStrokeWidth(3*t/level);

function koch (x1, y1, x2, y2, level){
if (level == 0){
LN.drawLine(x1, y1, x2, y2);
}
if (level > 0){
level = level-1;
koch(x1, y1, d*x1+e*x2, d*y1+e*y2, level);
koch(d*x1+e*x2, d*y1+e*y2, c*(x1+x2)+f*(y2-y1),c*(y1+y2)-f*(x2-x1), level);
koch(c*(x1+x2)+f*(y2-y1),c*(y1+y2)-f*(x2-x1), e*x1+d*x2, e*y1+d*y2, level);
koch(e*x1+d*x2, e*y1+d*y2, x2, y2, level);
}
}

sides = 3;
r = 0.5*Math.min(Math.abs(x2-x1),Math.abs(y2-y1));

x = x0+r*Math.cos(2*pi/sides);
y = y0-r*Math.sin(2*pi/sides);

xx = x0+r*Math.cos(4*pi/sides);
yy = y0-r*Math.sin(4*pi/sides);

xxx = x0+r*Math.cos(6*pi/sides);
yyy = y0-r*Math.sin(6*pi/sides);

koch(xx,yy, x, y, level);
koch(xxx,yyy, xx, yy, level);
koch(x, y, xxx,yyy, level);
[Android Apps and Games] acadoid:
[MENTION=5835367]Adam.D[/MENTION]: Where did you paste the code?

You need to create a new custom drawing tool, open it, add the parameters (including minimal, maximal, and step values) and paste the code into the JavaScript code editor.

[MENTION=4226212]Tintinnuntius[/MENTION]: I very much appreciate your posts. Would it be possible to include the ZIP file into the posts that LectureNotes creates upon sharing the custom drawing tool? This would make usage much easier, one would only need to import the ZIP file.
[Android Apps and Games] Tintinnuntius:
Well, since I'm about to move to 12.2 and should make a backup anyway... :) Here's all the scripts I've made so far, divided into several containers:

Discrete Maths:

- Graphs on n points (cycles, wheels, paths, etc.)

- Famous graphs (K(3,3), Petersen, Durer, Heawood, cube, octahedron,...)

- Venn diagram (just three simple circles)

- Truth table

Geometry:

- Sphere

- Torus

- Koch line

- Koch snowflake

Probability:

- various discrete distributions (graphs and tables)

- Bell curve (graph)

- Chi squared curve (graph)

Statistics:

- sample statistics

- pie chart

- bar chart

- Student table

- Chi squared table

Misc:

- parabola

- checkerboard

- square root symbol

Hopefully, I renamed the containers correctly as they were uploaded to Dropbox. Let me know if I messed it up.
[Android Apps and Games] Tamasaka:
3D Spere

This script draws a 3D sphere colored with current pencil color.

Parameter 1 sets the lighting angle from left. Value 0 is for lighting from center of front. The rendering is not raytracing, but pseudo 3D.

Parameter 2 sets the lighting angle from up side.

Parameter 3 is the switch to snap radius to grid which is 1/20 of standard grid.

Parameter 4 sets the resolution of drawing.

/* Sphere 1.00 */
xf = 0.8;
yf = 0.8;
snap = 1;
res = 25;
if (LN.getNumberOfParameters() >= 1)
xf = LN.getParameter(1); /* Left lighting angle (0 - 1.0), 0 ≤ Parameter(1) ≤ 0.8, 9 steps */
if (LN.getNumberOfParameters() >= 2)
yf = LN.getParameter(2); /* Upper lighting angle (0 - 1.0), 0 ≤ Parameter(2) ≤ 0.8, 9 steps */
if (LN.getNumberOfParameters() >= 3)
snap = LN.getParameter(3); /* Radius snaps to fine grid (0: free), 0 ≤ Parameter(3) ≤ 1, 2 steps */
if (LN.getNumberOfParameters() >= 4)
res = LN.getParameter(4); /* Resolution, 20 ≤ Parameter(4) ≤ 50, 7 steps */

width = LN.getWidth();
scale = LN.getScale();
step = width / 150 + scale * width / 25;
finestep = step / 20;

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

red = LN.getRed();
green = LN.getGreen();
blue = LN.getBlue();

radius = Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
r = Math.floor(radius / finestep + 0.5) * finestep;

xmin = x1 - r;
ymin = y1 - r;
xmax = x1 + r;
ymax = y1 + r;
LN.setClip(xmin, ymin, xmax, ymax);
xp = x1 - r * xf / 2;
yp = y1 - r * yf / 2;
LN.setSoftness(0.3);
for (i = 0; i < res; i++) {
p = 1 - i / res;
LN.setColor((red -1) * p + 1, (green -1) * p + 1, (blue -1) * p + 1);
LN.drawFilledCircle(x1 + (xp - x1) * i * i / (res -1) / (res - 1), y1 + (yp - y1) * i * i / (res -1) / (res - 1) , r * Math.sin(p * Math.PI/2));
}