yashsingh1/xdaforums huggingface dataset:
[Android Apps and Games] EE_student_noob:
How to create resistor, capacitor, inductor drawing tools.

Well I don't know any Javascript but I am trying to create my own basic set of drawing tools for sketching electrical circuits. Can anyone help me with what I did wrong. I don't need a full script, just need to know why this isn't drawing. After I can get this to work, I plan on converting to polar coordinates to allow it to be drawn in any direction. As it stands, I just want to be able to draw a simple resistor when dragging the pen left to right.

xs = LN.getX1();
ys = LN.getY1();
xf = LN.getX2();
yf = LN.getY2();

for (i = 0 ; i <= 7 ; i++){

ypos1 = Math.sin(90*i);
ypos2 = Math.sin(90*(i+1);

x1 = xs + ((i)*(xf-xs)/6);
y1 = ys + (i*(yf-ys)/6) + ypos1;
x2 = xs + ((i+1)*(xf-xs)/6);
y2 = ys + ((i+1)*(yf-ys)/6) + ypos2;

LN.drawLine(x1,y1, x2,y2);
}

Thanks.
[Android Apps and Games] acadoid:
[MENTION=6041722]EE_student_noob[/MENTION]: There is a syntax error

ypos2 = Math.sin(90*(i+1);

misses a closing bracket. Note that Math.sin() parameter is in radiant, not in degrees (http://www.w3schools.com/jsref/jsref_sin.asp).
[Android Apps and Games] EE_student_noob:
Ok well that fixed my drawing issue, now I just need to figure out why it is just a straight line. Thanks!

---------- Post added at 07:02 PM ---------- Previous post was at 06:36 PM ----------

xs = LN.getX1();
ys = LN.getY1();
xf = LN.getX2();
yf = LN.getY2();

yc = (yf-ys)/2;

n = 6;
m = 12;

LN.setStrokeWidth(LN.getStrokeWidth());

for (i = 1 ; i <= n ; i++){

ypos1 = Math.sin(1.570796*(i-1))*(xf-xs)/m;
ypos2 = Math.sin(1.570796*(i))*(xf-xs)/m;

x1 = (i)(xf-xs)/n;
y1 = yc + ypos1;
x2 = (i+1)(xf-xs)/n;
y2 = yc + ypos2;

LN.drawLine(x1,y1, x2,y2);
}

This is what I got now for drawing a simple resistor, apparently I have something messed up again as it is too much for lecture notes to draw.
[Android Apps and Games] acadoid:
[MENTION=6041722]EE_student_noob[/MENTION]:

x1 = (i)(xf-xs)/n;
y1 = yc + ypos1;
x2 = (i+1)(xf-xs)/n;
y2 = yc + ypos2;

You forgot multiplication character `*´ for x1 and x2; also, x1 and x2 are not necessarily in the visible area.

Besides that

LN.setStrokeWidth(LN.getStrokeWidth());

is redudant.
[Android Apps and Games] Tamasaka:
Stacked bar chart

This script draws a stacked bar chart of data in string parameters or in keywords of the page.

Type in values and labels as csv (comma-separated values) in string parameters at the parameter setting dialog. Tap ‘OK’ and drag your pen on a page. When string parameters are blank, this script gets data from keywords like previous ‘Table formatter’ and ‘Scatter plot’ tool.

Data format in the keyword file is;

[DATA] <title string>

csv with a leading comma

[/DATA] bar

This script has 4 numerical parameters.

Parameter 1 sets the width of bar.

Parameter 2 sets the thickness of link line between bars.

When you set parameter 1 = 0 and parameter 2 = 1.0, the chart looks like a stacked line chart.

Parameter 3 chooses color of sub-bar from unicolor, dark set of color, or light set of color. The unicolor is series of various opacity of current color. The dark set is series of ‘green’, ‘blue’, ‘red’, ‘orange’, ‘marine’, ‘indigo’, ‘magenta’, and ‘brown’. The light set is ‘lime’, ‘sky’, ‘salmon’, ‘yellow’, ‘cyan’, ‘violet’, ‘pink’, and ‘gold’.

Parameter 4 draws labels of sub-bar on the principal sub-bar or in legend.

If the leftmost column is non-numeric, that is labels for stacked bars.

The row just before [/DATA] tag can contain options that specify color of sub-bar and overwrite the color set by parameter 3.

The optional color is the color names in the dark set or the light set.

Depending on the data, a short help or error messages are shown.

The chart in screenshot attached is given by sample data as follows.

[DATA]Sample 3
,Food,Protein,Fat,Carbo-,Dietary
, , , , hydrate, fiber
,
,Egg,11.3,9,2.2,0
,Shrimp,21.1,11.7,11.7,0.3
,Beaf,27,25.8,0,0
,Peanut,23.2,45.8,21.2,8
,Chocolate,7.1,30.9,57.7,3.3
,Nutrition (wt%)
[/DATA] bar table
[Android Apps and Games] pnuker:
It would be great if this would snap to the grid. I'm trying to figure out how to change the code to do that. Any suggestions?
[Android Apps and Games] acadoid:
[MENTION=4226212]Tintinnuntius[/MENTION]: I just uploaded v2.6.1 into the app stores which allows to add a description and an author text to drawing tools; the description text is shown in the parameter dialog.
[Android Apps and Games] Mai Van Manh:
Thanks for your post
[Android Apps and Games] colorado109:
snap

now it snap:

width = LN.getWidth();

scale = LN.getScale();

step = width / 150 + scale * width / 25;

height = LN.getHeight();

x1 = LN.getX1();

y1 = LN.getY1();

x2 = LN.getX2();

y2 = LN.getY2();

//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;

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] Tamasaka:
Radar chart

This script draws a radar chart of data in string parameters or in keywords of the page.

Labels and scores can be given as csv (comma-separated values) in string parameters. When string parameters are blank, this script gets data from keywords as same as previous ‘Table formatter’, ‘Scatter plot’ and ‘Stacked bar chart’ tools.

Data format in the keyword file is;

[DATA] <title string>

csv with a leading comma

[/DATA] radar

This script has 7 numerical parameters.

Parameter 1 chooses color set from dark set or light set, those are same as the color sets for ‘Stacked bar chart’ tool.

Parameter 2 sets the color sequence. Value 0 gives the sequence of colors same for every chart. Value 1 chooses a rolling color sequence that gives different colors for 8 stars.

Parameter 3 is the number of stars overlay on a chart. Up to 6 stars can overlay on a chart, and up to 4 charts can be drawn in a page.

Parameter 4 draws legend labels of stars at various positions those are center, right or bottom of the chart. When a chart have only one star (then Parameter 3 is 1), exceptionally value 0 draws the label of the star above the chart.

Parameter 5 sets the scale of radial axis. When this parameter is 0, stars are drawn in raw scores, and the best score is the best of all items. Value 1 scales a percentage of the best score of the item.

Parameter 6 sets maximum steps of axis. Within this value, the best score determines the number of the steps.

Parameter 7 transposes data column and row. This switch exchanges items with stars. When the data transpose, labels of items are limited to only one line.

Insufficient data leads to show a short help or error messages.

The chart in the screenshot attached is given by the sample data as follows.

[DATA]Sample 4
,,Mathematics,Physics,Chemstry,Earth,Biology
,, , , ,Science,
,
,Alice,65,70,93,75,80
,Bob, 100,80,65,67,60
,Carol,72,80,70,97,63
,Dave, 85,75,55,78,67
[/DATA] radar table bar
[Android Apps and Games] Tintinnuntius:
I've just noticed that the discription text only spans about half the width of the parameter dialog box (only the part above the parameter names and not above the sliders).
[Android Apps and Games] acadoid:
[MENTION=4226212]Tintinnuntius[/MENTION]: The width of the comment box is currently fixed to about the width of the slider plus +/- buttons (or equally to about the width of the text field for a string parameter). Hence, if your parameter names are long (which make the dialog box wider), the comment box will look small in comparison. Good point, I will change that for the next update.
[Android Apps and Games] Tintinnuntius:
Sometimes the changes I make in drawing tools don't get saved. I always exit the editor by pressing the back button and I always get the "Use modified c.d.t." dialog and I choose "Yes" , but sometimes the changes just don't stick. When I get back in all the new code is gone. It seems to be quite random, so I don't know how you could reproduce it (I don't think I'm doing anything different, but maybe the tablet is doing something in the background?). I'd say it occurs about 1 in 10 times (very rough estimate), so you'd have to be editing tools for a while before you could catch it. Any ideas what could be causing this?
[Android Apps and Games] acadoid:
[MENTION=4226212]Tintinnuntius[/MENTION]: Many thanks for point this out to me, I will look into it.
[Android Apps and Games] acadoid:
[MENTION=4226212]Tintinnuntius[/MENTION]: I just uploaded v2.6.3 into the app stores. With this version, the width of the comment grows with the width of the parameter names. I also added a few extra precautions when entering and leaving the custom drawing tool editor.
[Android Apps and Games] Tintinnuntius:
Now it looks fine if there are only numerical parameters, but with string parameters there is a lot of empty space to the right of value fields (the dialog box gets streched out for no reason). It's hardly noticable in portrait mode but it is really obvious in landscape.
[Android Apps and Games] acadoid:
[MENTION=4226212]Tintinnuntius[/MENTION]: The width of the comment section is also correctly adjusted in the second example.

The width of the dialog, however, is a different issue. The width of the dialog is chosen by Android and follows a rather strange behavior, as it does not growth smoothly with the width of the content to be displayed. Instead, it `jumps´ if the width of the content to be displayed passes a threshold, stays constant until the width of the content to be displayed passes the next threshold, and so on (it might also be that the height of the content to be displayed enters somehow, maybe even the device orientation via the available display area). You can observe this strange behavior also with other dialogs.
[Android Apps and Games] Tamasaka:
Stacked bar chart update

Previous version was posted as http://xdaforums.com/showpost.php?p=55677464&postcount=115.

Bar chart (stacked) version 1.55:

1. Vertical bar (numerical parameter 5) added. Default is horizontal bar.

2. Alternation of vertical stack order of sub-bars (numerical parameter 6) added. Default order (the parameter = 0) is from top to bottom. Horizontal bars have nothing to do with this parameter.

3. Data transposing (numerical parameter 7) added. Columns and rows of data are exchangeable with this parameter. Even if the data column and row transpose, the row for color options (the last row) is valid.

4. Two lines of label for stacked bars added. Up to two leftmost columns can be the labels, if they are non-numeric.

5. Parser for quoted data with comma as a thousand separator improved.

6. Text size of numbers in axis adjusted.

7. Label ‘dummy’ for stacked bar (data row) added.

8. Effects of the strokewidth of current pencil on frame or ticks of axis modified.

9. Several minor modifications such as square corners of bars, headspace of the longest bar, and algorithm for the number of ticks of axis.

Drawing of the sample data in the post http://xdaforums.com/showpost.php?p=56638697&postcount=121 with parameter 5 = 1 and medium black pencil resulted in the screenshot attached.

Edit: Update to v1.56 for bug-fix.

Version 1.55 has a bug at drawing in unicolor.
[Android Apps and Games] katyacat1:
Phi spiral

Any help figuring out a code to draw a phi spiral . AKA a golden spiral ? I found this ... WWW dot davidxia dot com/2011/02/draw-golden-rectangle-using-javascript/ but I don't know how to use that info to do that in lecture notes.:confused:
[Android Apps and Games] acadoid:
[MENTION=3339143]katyacat1[/MENTION]: Such object can certainly be drawn as LectureNotes' custom drawing tool, but you will need to replace the HTML canvas drawing commands by LectureNotes' drawing commands: lines are drawn using LN.drawLine(), arcs are drawn using LN.drawArc() etc. Most custom drawing tools start with

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

so that the selection rectangle is stored in the variables x1, y1, x2, and y2. Note that both x1 < x2 and x1 > x2 as well as y1 < y2 and y1 > y2 can occur, so that the selected width and height is

width = Math.abs(x2 - x1);
height = Math.abs(y2 - y1);

etc.
[Android Apps and Games] Tintinnuntius:
Here's a script that draws the spiral using its parametric equation. It can be easily modified to draw other parametric curves.

A complete picture with rectangles would require a bit more work, you can try modifying the script as acadoid had suggested.
[Android Apps and Games] katyacat1:
Thanks. You guys gave me enough info, I think I can figure it out. You guys are awesome.
[Android Apps and Games] Tamasaka:
Grouped bar chart

Grouped bar chart tool is another version of the bar chart tool posted as

http://xdaforums.com/showpost.php?p=57911990&postcount=130

This tool has 7 numerical parameters.

Parameter 1 sets the space between bar groups. The value is multiple of bar width.

Parameter 2 sets the side margins of the chart. The value is multiple of bar width.

Parameter 5 selects background of chart. Value 0 is for transparent background. Value 1 is for white background with lines for coarse scale. Value 2 is for white background without lines. Value 3 is for light gray background with lines. Value 4 is for light gray background without lines.

Other parameters are similar to those of the stacked bar chart tool.

Other improvements:

1. Unlike the stacked bar chart, negative value can be plotted in grouped bar chart.

2. Dragging up or dragging to right snaps the chart to grid. When the background is transparent, the origin of the scale snaps to acadoid's standard grid, and the most significant upper tick snaps to 1/5 step grid. The snapping ticks are shown with long red lines at temporary rendering. When the background is opaque, the frame of chart snaps to grid. Dragging down or dragging to left draws a chart free from grid.

3. Colors changed to opaque.

4. Algorithm for ticks of axis changed.

Drawing of the sample data in the post http://xdaforums.com/showpost.php?p=56638697&postcount=121 resulted in the screenshot attached.
[Android Apps and Games] nickajeglin:
question

I'm having some problems with the custom drawing tools on my galaxy 9. I'm running android 5.0.1, with lecture notes 2.6.6

The issue is that temporary rendering of the tool doesn't happen at all, and most tools do not work. I see the dotted box outline of the custom tool, just with nothing in it. Very simple tools, like dotted lines, arrows, or horizontal/vertical lines will work if I lay them out, wait several seconds, then let go. But more complicated tools like grids or even bullet points won't work no matter how long I wait. Some tools (like the check boxes from earlier in this thread) will work inconsistently, but I can't really tell whether it's dependent on time or placement of the layout box.

I'm a new user so I'm not certain of how the custom tools should work, but since the issues are so inconsistent, I'm suspecting that this isn't entirely user error.

I've tried turning off/on all of the android developer options, especially ones relating to hardware rendering and animations. I've also tried every combination of fast temporary rendering that I can think of in the lecturenotes settings.

Is this a bug, or am I just missing something simple? Also, if this isn't the correct place for these type of questions, please let me know where they should go, and I'll take it there.

(Otherwise the app is amazing, I love how many options there are for customization.:))
[Android Apps and Games] acadoid:
[MENTION=6427999]nickajeglin[/MENTION]: Google has revised the threading machinery in Android 5.0 (LOLLIPOP). This has a couple of consequences, including the behavior of custom drawing tools in LectureNotes, as their execution is significantly slowed down with respect to older Android versions.

When you use a custom drawing tool, you first see the dashed rectangle (even if you disable `fast custom drawing tools´ in the app's tools settings); after a slight moment holding the position, the custom drawing tool appears; when you change the position by a significant amount, the dashed rectangle comes back; after a slight moment holding the new position, the custom drawing tool reappears; and so on.
[Android Apps and Games] nickajeglin:
Thanks for the clarification, I suspected that it was lollipop related. I do have a slight difference from the description above though:

I only ever see the dashed rectangle, the drawing tool doesn't render no matter how long I wait. There is a slight halt or lag in the rectangle's moving dashes if I don't change position for some time, and it seems like if I let go exactly timed with that lag the tool will actually apply to the page. If I let go before or after the lag happens, the tool does not draw.

Let me know if there is any testing I can do to help out with the issue, and thanks for the explanation!
[Android Apps and Games] acadoid:
[MENTION=6427999]nickajeglin[/MENTION]: (1) Which device do you use? You wrote `Galaxy 9´ in your first post, but I am not aware of such device.

(2) Are you using the stock ROM or a custom ROM?

(3) Which custom drawing tool do you use for your tests?

(4) If you wait until the `lag´ happens, then change the position and wait again, does the `lag´ happen a second time?

(5) If you enable `fast custom drawing tools rendering´ in the app's tools settings and use the custom drawing tool, does it get drawn (you might also need to hold a certain position for a slight moment)?
[Android Apps and Games] nickajeglin:
1) sorry, I meant nexus 9, the names of all these new devices drive me crazy.

2) stock Rom, it's a new device with almost nothing installed.

3) different tools give different results, if I use "x-y coordinate system", and wait for the lag to stop, the tool will apply to the layer. More complicated tools (anything with grid at the end) do not apply to the layer even if I wait upwards of 30 seconds. To clarify, no custom tools are ever drawn inside of the box, the difference is whether they work after releasing or not.

4) repositioning will cause the lag to happen again.

5) enabling "fast custom drawing tools rendering" does not make the tool draw inside of the layout box.

I suspect that the lag I'm seeing is happening as the tool tries to do the temporary rendering, and that I may not be waiting long enough for complicated tools to have time to render, so they abort when I let go.

Edit: most tools seem to work if I wait until after the lag stops. When I said I had to time releasing exactly with the end of the lag in my previous post, I was using the align to grid bullet tool from earlier in this thread. Now I think that may have been position related, but it's hard to tell without the temporary rendering.
[Android Apps and Games] acadoid:
[MENTION=6427999]nickajeglin[/MENTION]: Many thanks for your feedback.

Have you changed anything in the device's developer settings, in particular enabled the option `enforce GPU/hardware rendering´?
[Android Apps and Games] nickajeglin:
Happy to help!

I have tried both GPU/hardware rendering on and off. Whether it is on or off seems to have no effect on the custom tools issue described above.

The only developer options I have turned on are "enable OEM unlock" (although I have not yet actually unlocked), and USB debugging. Previously I had all of the animation scale settings turned to .5x, but I have since set them back to 1x.
[Android Apps and Games] acadoid:
[MENTION=6427999]nickajeglin[/MENTION]: Many thanks for performing the additional tests.

I went over the source code and added a couple additional precautions that hopefully solve this issue. I plan to ship the update v2.6.7 this weekend and I will appreciate your feedback.
[Android Apps and Games] acadoid:
[MENTION=6427999]nickajeglin[/MENTION]: I just uploaded v2.6.7 into the app stores which hopefully solves this issue. I will appreciate your feedback.
[Android Apps and Games] nickajeglin:
Unfortunately, 2.6.7 doesn't seem to help. The issue seems to be identical.

I downloaded lecturenotes on my phone (HTC DNA) for comparison purposes, and the custom drawing tools work exactly as you described they would.
[Android Apps and Games] acadoid:
[MENTION=6427999]nickajeglin[/MENTION]: There was no change at all? I did not expect that. I trust that you disable `use fast custom drawing tools rendering´ in the app's tools settings prior to your tests.

Which Android version is running on your phone? Android 5.0?
[Android Apps and Games] nickajeglin:
Ah, I did not turn off fast rendering. Now that I have, the tool will render if I hold for a sufficient amount of time.

Now that I can see the tool I think I have a much better idea of what is happening:

It seems like it is very hard to hold my finger or stylus still enough to prevent the tool from redrawing. Even if I do manage to hold still until the tool renders, the act of removing finger or stylus from the screen usually creates a small movement that is enough to cause the tool to redraw. Which of course fails since I just let go of the screen.

Is there some kind of "sensitivity" adjustment that could be temporarily decreased just after the tool renders to prevent the slight movement from releasing the screen messing up the drawing?

(The phone is 4.4.2, and not especially relevant. I just wanted to mention that I had seen how it was supposed to be working as well)

---------- Post added at 11:51 AM ---------- Previous post was at 11:45 AM ----------

Here's a quick code to draw a square root symbol, it uses the selected pen and the orientation is always correct no matter what direction you draw.

I'm also trying to work on an integral symbol that will take parameters for the limits of integration.

x1 = LN.getX1();
y1 = LN.getY1();
x2 = LN.getX2();
y2 = LN.getY2();
ybtm = Math.max(y1, y2);
ytop = Math.min(y1, y2);
xrt = Math.max( x1, x2);
xlft = Math.min(x1, x2);
strokewidth = LN.getStrokeWidth();
ym = (y1 + y2) / 2;
xpad = Math.abs(x2-x1)/30;
LN.drawLine(xlft, ym, xlft + xpad, ym);
LN.drawLine(xlft + xpad, ym, xlft + (2 * xpad), ybtm);
LN.drawLine(xlft + (2 * xpad), ybtm, xlft + (3 * xpad), ytop);
LN.drawLine(xlft + (3 * xpad), ytop, xrt, ytop);
[Android Apps and Games] anilff:
thanks it is lovely!
[Android Apps and Games] acadoid:
[MENTION=6427999]nickajeglin[/MENTION]: LectureNotes accepts small movements, the threshold cannot be adjusted. Let me think a moment about this problem.

EDIT: I added a mechanism which discards movements directly before lifting the finger/stylus if these movements result in the custom drawing tool to be discarded. This should solve the problem that you described. Since I updated the app last weekend, the next update will be around mid of March and I have to ask you for some patience.
[Android Apps and Games] nickajeglin:
Of course, thank you! I really appreciate you being so responsive when this is really a minor issue on a single device. I love the application and look forwards to putting it to good use in the future.
[Android Apps and Games] acadoid:
[MENTION=6427999]nickajeglin[/MENTION]: I just uploaded v2.6.8 into the app stores which discards movements directly before lifting the finger/stylus if these movements result in the custom drawing tool to be discarded.
[Android Apps and Games] nickajeglin:
Great, thanks! This is a noticeable improvement over the previous version. The majority of custom drawing tools work well for me now. :D
[Android Apps and Games] acadoid:
[MENTION=6427999]nickajeglin[/MENTION]: Which ones do not work for you? And in which sense do they fail?
[Android Apps and Games] Caramelia:
Dashed Rectangle

Hello!

First of all, thank you for this marvelous app, which made studying fun again!

Second: I'm a complete noob at Java and can't get the simplest thing to work. I want / need a custom drawing tool, that gives me a dashed rectangle. I thought it couldn't be too difficult to just get the rectangle lines dashed, but two hours later it still doesn't work and I'm out of ideas.

Could someone please make me a dashed rectangle tool? I'd be much obliged.