NEWS Forum Wiki XDA TV

# [APP][3.0+] LectureNotes - custom pattern JavaScript codes

Tip us?
 acadoid 14th October 2012, 01:11 PM (Last edited by acadoid; 31st March 2013 at 04:55 PM.) Senior Member - OP Thanks Meter 675 Posts: 1,299 Join Date: Apr 2012 [APP][3.0+] LectureNotes - custom pattern JavaScript codes As I receive numerous questions concerning the custom pattern JavaScript interface of LectureNotes and how to implement specific patterns, I thought that it might be helpful to post my replies here, which should allow to easily copy them. Please feel invited to post additional ones! First, a so-called isometric pattern that is quoted at the app's help page (where the code lines are commented) Code: ```width = LN.getWidth(); height = LN.getHeight(); scale = LN.getScale(); step = width / 150 + scale * width / 25; LN.setStrokeWidth(width / 1000); for (x = 0; x < width; x += step) LN.drawLine(x, 0, x, height); stepX = 2 * step; stepY = 1.1547 * step; x1 = 0; y1 = step; x2 = stepX; y2 = 0; while ((x1 < width) && (y2 < height)) { LN.drawLine(x1, y1, x2, y2); if (y1 < height) y1 += stepY; else x1 += stepX; if (x2 < width) x2 += stepX; else y2 += stepY; } x1 = x2 - stepX; y1 = 0; y2 = step; while ((x2 > 0) && (y1 < height)) { LN.drawLine(x1, y1, x2, y2); if (x1 > 0) x1 -= stepX; else y1 += stepY; if (y2 < height) y2 += stepY; else x2 -= stepX; }``` and a simple additional one that places a page number centered at the page bottom Code: ```width = LN.getWidth(); height = LN.getHeight(); page = LN.getPage(); LN.setTextSize(0.02 * width); LN.setTextAlign(0); LN.drawText("Page " + page, 0.5 * width, 0.95 * height);``` REPLY
 The Following 5 Users Say Thank You to acadoid For This Useful Post: [ Click to Expand ]
 acadoid 15th October 2012, 10:12 AM (Last edited by acadoid; 19th November 2012 at 10:41 PM.) Reason: CODE macro Senior Member - OP Thanks Meter 675 Posts: 1,299 Join Date: Apr 2012 Some more, an eternal calender, one month per page, starting January 2012 Code: ```year = 2012; months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; monthdays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; weekdays = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; month = LN.getPage() - 1; year += Math.floor(month / 12); month2 = month % 12; month = month + 1; days = monthdays[month2]; if ((month == 2) && (year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0))) days++; if (month <= 2) year2 = year - 1; else year2 = year; c = Math.floor(year2 / 100); y = year2 % 100; m = ((month + 9) % 12) + 1; w = (1 + Math.floor(2.6 * m - 0.2) + y + Math.floor(y / 4) + Math.floor(c / 4) - 2 * c + 7 * 100) % 7; width = LN.getWidth(); height = LN.getHeight(); size = Math.min(width, height); stepx = width / 8; stepy = height / 8; LN.setTextSize(0.025 * size); for (d = 0; d < 7; d++) LN.drawText(weekdays[d], (d + 0.6) * stepx, 1.4 * stepy); LN.setTextSize(0.05 * size); LN.setTextAlign(-1); LN.drawText(months[month2] + " " + year, 7.5 * stepx, 0.25 * stepy + 0.05 * size); LN.setTextAlign(1); l = 0; for (d = 1; d <= days; d++) { LN.drawText(d, stepx * (w + 0.6), stepy * (l + 2.4)); if ((++w == 7) && (d != days)) { w = 0; l++; } } for (x = 0.5 * stepx; x < width; x += stepx) LN.drawLine(x, 1.5 * stepy, x, (l + 2.5) * stepy); for (y = 1.5 * stepy; y < (l + 3) * stepy; y += stepy) LN.drawLine(0.5 * stepx, y, 7.5 * stepx, y);``` and another simple one, a checkered pattern in which every fifth line is thicker Code: ```width = LN.getWidth(); height = LN.getHeight(); scale = LN.getScale(); LN.drawCheckeredPattern(scale, false); LN.setStrokeWidth(0.002 * width); step = width / 150 + scale * width / 25; for(y = step / 2; y < height; y += 5 * step) { LN.drawLine(0, y, width, y); } for(x = step / 2; x < width; x += 5 * step) { LN.drawLine(x, 0, x, height); }``` REPLY
 The Following 4 Users Say Thank You to acadoid For This Useful Post: [ Click to Expand ]
 acadoid 17th October 2012, 01:05 PM (Last edited by acadoid; 19th November 2012 at 10:41 PM.) Reason: CODE macro Senior Member - OP Thanks Meter 675 Posts: 1,299 Join Date: Apr 2012 Today two examples for writing music, a simple one Code: ```width = LN.getWidth(); height = LN.getHeight(); LN.setStrokeWidth(0.001 * width); left = 0.05 * width; right = 0.95 * width; step = 0.005 * height; for(y = 0.05 * height; y < 0.95 * height; y += 0.05 * height) { LN.drawLine(left, y, right, y); LN.drawLine(left, y + step, right, y + step); LN.drawLine(left, y + 2 * step, right, y + 2 * step); LN.drawLine(left, y + 3 * step, right, y + 3 * step); LN.drawLine(left, y + 4 * step, right, y + 4 * step); LN.drawLine(left, y, left, y + 4 * step); LN.drawLine(right, y, right, y + 4 * step); }``` and a double one Code: ```width = LN.getWidth(); height = LN.getHeight(); LN.setStrokeWidth(0.001 * width); left = 0.05 * width; right = 0.95 * width; step = 0.005 * height; for(y = 0.05 * height; y < 0.9 * height; y += 0.1 * height) { LN.drawLine(left, y, right, y); LN.drawLine(left, y + step, right, y + step); LN.drawLine(left, y + 2 * step, right, y + 2 * step); LN.drawLine(left, y + 3 * step, right, y + 3 * step); LN.drawLine(left, y + 4 * step, right, y + 4 * step); LN.drawLine(left, y + 9 * step, right, y + 9 * step); LN.drawLine(left, y + 10 * step, right, y + 10 * step); LN.drawLine(left, y + 11 * step, right, y + 11 * step); LN.drawLine(left, y + 12 * step, right, y + 12 * step); LN.drawLine(left, y + 13 * step, right, y + 13 * step); LN.drawLine(left, y, left, y + 13 * step); LN.drawLine(right, y, right, y + 4 * step); LN.drawLine(right, y + 9 * step, right, y + 13 * step); }``` (step size etc. can easily be adjusted). REPLY
 The Following 2 Users Say Thank You to acadoid For This Useful Post: [ Click to Expand ]
 acadoid 21st October 2012, 06:31 PM (Last edited by acadoid; 19th November 2012 at 10:40 PM.) Reason: CODE macro Senior Member - OP Thanks Meter 675 Posts: 1,299 Join Date: Apr 2012 Since v1.16.13, there is an additional JavaScript command LN.setColor(r, g, b) that allows to use colors other then the one chosen in the dialog. This allows now, for instance, a ruled pattern with a red line on the left side Code: ```width = LN.getWidth(); height = LN.getHeight(); LN.drawRuledPattern(LN.getScale(), false); LN.setStrokeWidth(0.002 * width); LN.setColor(1, 0, 0); LN.drawLine(0.05 * width, 0, 0.05 * width, height);``` REPLY
 The Following 3 Users Say Thank You to acadoid For This Useful Post: [ Click to Expand ]

RETIEF
Senior Member
Thanks Meter 11
Posts: 123
Join Date: Sep 2007
isometric problems

Quote:
 Originally Posted by acadoid As I receive numerous questions concerning the custom pattern JavaScript interface of LectureNotes and how to implement specific patterns, I thought that it might be helpful to post my replies here, which should allow to easily copy them. Please fell invited to post additional on;

I love this app. I am using it on a Galaxy Note 10.1. The isometric script give an error message that it takes too long and aborts. Thought you would want to know.

By the way, I tested it three times using cut ans paste. Once from the help page, and twice from here.

Keep up the good work.
 The Following User Says Thank You to RETIEF For This Useful Post: [ Click to Expand ]
 acadoid 27th October 2012, 08:12 PM Senior Member - OP Thanks Meter 675 Posts: 1,299 Join Date: Apr 2012 @RETIEF: To double-check, I copied and paste the content shown in this thread, and it works. Note, however, that on my Samsung Galaxy Note 10.1 (for instance in difference to my Lenovo ThinkPad Tablet), the copy/paste converts a `new line´ into nothing (instead of a space), this causes problems, for instance `else y1´ becomes `elsey1´, which is wrong. Please check whether this is causing the problem in your case. REPLY
 The Following User Says Thank You to acadoid For This Useful Post: [ Click to Expand ]

RETIEF
Senior Member
Thanks Meter 11
Posts: 123
Join Date: Sep 2007
Attempt to fix calendar

Quote:
 Originally Posted by acadoid @RETIEF: To double-check, I copied and paste the content shown in this thread, and it works. Note, however, that on my Samsung Galaxy Note 10.1 (for instance in difference to my Lenovo ThinkPad Tablet), the copy/paste converts a `new line´ into nothing (instead of a space), this causes problems, for instance `else y1´ becomes `elsey1´, which is wrong. Please check whether this is causing the problem in your case.
I didn't have that exact problem, but the if else structures left out lines in the paste so that that all read if (xxxxx); else ;next line.

I manually edited the script to match exactly what was posted here and I still get the same error message. This is for the isometric code.

On the calendar code, if I use a task killer (I use the factory Samsung one), I can get the code to load and execute if I stopped on January. But if I left the document later in the year, I get the same error message.

I'm no coder (at least not since the Fortran G and Turbo Pascal days), but I wounder if extending the process time a second would solve the problem.
Like I said. I'm no coder.

In any case, I appreciate your help. I'm sure you have better things to do.
 acadoid 29th October 2012, 04:14 PM Senior Member - OP Thanks Meter 675 Posts: 1,299 Join Date: Apr 2012 @RETIEF: All the posted codes work fine on my Samsung Galaxy Note 10.1. I can increase the maximal time, but I do not think that this is the problem. Have you tried to share such page or export it to PDF? In these cases, the maximal waiting time is ten times longer (these operations are not time critical), so if you get an abort message there, then something is wrong in your code. If you drop me an email, I can send the code as email attachment to you, this will exclude all possible sources of error. REPLY
 The Following User Says Thank You to acadoid For This Useful Post: [ Click to Expand ]

RETIEF
(Last edited by RETIEF; 29th October 2012 at 04:59 PM.)
Senior Member
Thanks Meter 11
Posts: 123
Join Date: Sep 2007