not really known
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

385 lines
8.8 KiB

  1. //* comment *//
  2. Copyright (C) 2017 Hitesh Agarwal
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. //* arg-globals *//
  14. var block = logo.blocks.blockList[blk];
  15. var conns = block.connections;
  16. //* block-globals *//
  17. var convertBlock = function (name, label, arg1, arg2) {
  18. var protoblock = new ProtoBlock(name);
  19. protoblock.palette = palettes.dict['converter'];
  20. blocks.protoBlockDict[name] = protoblock;
  21. protoblock.staticLabels.push(label, _('number'), _('unit to convert'));
  22. protoblock.adjustWidthToLabel();
  23. protoblock.twoArgMathBlock();
  24. protoblock.dockTypes[2] = 'anyin';
  25. protoblock.defaults.push(arg1);
  26. protoblock.defaults.push(arg2);
  27. };
  28. //* block:from_mm *//
  29. convertBlock('from_mm', 'from mm', 1000, 'mm');
  30. //* arg:from_mm *//
  31. var arg = logo.parseArg(logo, turtle, conns[1]);
  32. var unit = logo.parseArg(logo, turtle, conns[2]);
  33. switch (unit) {
  34. case 'mm':
  35. block.value = (arg);
  36. break;
  37. case'cm':
  38. block.value = (arg*1/10);
  39. break;
  40. case 'm':
  41. block.value = (arg*1/1000);
  42. break;
  43. case 'km':
  44. block.value = (arg*1/1000000);
  45. break;
  46. case 'in':
  47. block.value = (arg*1/25.4);
  48. break;
  49. case 'ft':
  50. block.value = (arg*1/304.8);
  51. break;
  52. case 'yd':
  53. block.value = (arg*1/914.4);
  54. break;
  55. case 'mi':
  56. block.value = (arg*1/1609344);
  57. break;
  58. case 'nmi':
  59. block.value = (arg*1/1852000);
  60. break;
  61. }
  62. //* block:from_cm *//
  63. convertBlock('from_cm', 'from cm', 1000, 'cm');
  64. //* arg:from_cm *//
  65. var arg = logo.parseArg(logo, turtle, conns[1]);
  66. var unit = logo.parseArg(logo, turtle, conns[2]);
  67. switch (unit){
  68. case 'mm':
  69. block.value = (arg*1/0.1);
  70. break;
  71. case 'cm':
  72. block.value = (arg);
  73. break;
  74. case 'm':
  75. block.value = (arg*1/100);
  76. break;
  77. case 'km':
  78. block.value = (arg*1/100000);
  79. break;
  80. case 'in':
  81. block.value = (arg*1/2.54);
  82. break;
  83. case 'ft':
  84. block.value = (arg*1/30.48);
  85. break;
  86. case 'yd':
  87. block.value = (arg*1/91.44);
  88. break;
  89. case 'mi':
  90. block.value = (arg*1/160934.4);
  91. break;
  92. case 'nmi':
  93. block.value = (arg*1/185200);
  94. break;
  95. }
  96. //* block:from_m *//
  97. convertBlock('from_m', 'from m', 1000, 'm');
  98. //* arg:from_m *//
  99. var arg = logo.parseArg(logo, turtle, conns[1]);
  100. var unit = logo.parseArg(logo, turtle, conns[2]);
  101. switch (unit) {
  102. case 'mm':
  103. block.value = (arg*1/0.001);
  104. break;
  105. case 'cm':
  106. block.value = (arg*1/0.01);
  107. break;
  108. case 'm':
  109. block.value = (arg*1/1);
  110. break;
  111. case 'km':
  112. block.value = (arg*1/1000);
  113. break;
  114. case 'in':
  115. block.value = (arg*1/0.0254);
  116. break;
  117. case 'ft':
  118. block.value = (arg*1/0.3048);
  119. break;
  120. case 'yd':
  121. block.value = (arg*1/0.9144);
  122. break;
  123. case 'mi':
  124. block.value = (arg*1/1609.344);
  125. break;
  126. case 'nmi':
  127. block.value = (arg*1/1852);
  128. break;
  129. }
  130. //* block:from_km *//
  131. convertBlock('from_km', 'from km', 1000, 'km');
  132. //* arg:from_km *//
  133. var arg = logo.parseArg(logo, turtle, conns[1]);
  134. var unit = logo.parseArg(logo, turtle, conns[2]);
  135. switch (unit) {
  136. case 'mm':
  137. block.value = (arg*1/0.000001);
  138. break;
  139. case 'cm':
  140. block.value = (arg*1/0.00001);
  141. break;
  142. case 'm':
  143. block.value = (arg*1/0.001);
  144. break;
  145. case 'km':
  146. block.value = (arg*1/1);
  147. break;
  148. case 'in':
  149. block.value = (arg*1/0.0000254);
  150. break;
  151. case 'ft':
  152. block.value = (arg*1/0.0003048);
  153. break;
  154. case 'yd':
  155. block.value = (arg*1/0.0009144);
  156. break;
  157. case 'mi':
  158. block.value = (arg*1/1.609344);
  159. break;
  160. case 'nmi':
  161. block.value = (arg*1/1.852);
  162. break;
  163. }
  164. //* block:from_in *//
  165. convertBlock('from_in', 'from in', 1000, 'in');
  166. //* arg:from_in *//
  167. var arg = logo.parseArg(logo, turtle, conns[1]);
  168. var unit = logo.parseArg(logo, turtle, conns[2]);
  169. switch (unit) {
  170. case 'mm':
  171. block.value = (arg*1/0.039370078740157);
  172. break;
  173. case 'cm':
  174. block.value = (arg*1/0.39370078740157);
  175. break;
  176. case 'm':
  177. block.value = (arg*1/39.370078740157);
  178. break;
  179. case 'km':
  180. block.value = (arg*1/39370.078740157);
  181. break;
  182. case 'in':
  183. block.value = (arg*1/1);
  184. break;
  185. case 'ft':
  186. block.value = (arg*1/12);
  187. break;
  188. case 'yd':
  189. block.value = (arg*1/36);
  190. break;
  191. case 'mi':
  192. block.value = (arg*1/63360);
  193. break;
  194. case 'nmi':
  195. block.value = (arg*1/72913.385826772);
  196. break;
  197. }
  198. //* block:from_ft *//
  199. convertBlock('from_ft', 'from ft', 1000, 'ft');
  200. //* arg:from_ft *//
  201. var arg = logo.parseArg(logo, turtle, conns[1]);
  202. var unit = logo.parseArg(logo, turtle, conns[2]);
  203. switch (unit) {
  204. case 'mm':
  205. block.value = (arg*1/0.0032808398950131);
  206. break;
  207. case 'cm':
  208. block.value = (arg*1/0.032808398950131);
  209. break;
  210. case 'm':
  211. block.value = (arg*1/3.2808398950131);
  212. break;
  213. case 'km':
  214. block.value = (arg*1/3280.8398950131 );
  215. break;
  216. case 'in':
  217. block.value = (arg*1/0.083333333333333);
  218. break;
  219. case 'ft':
  220. block.value = (arg*1/1);
  221. break;
  222. case 'yd':
  223. block.value = (arg*1/3);
  224. break;
  225. case 'mi':
  226. block.value = (arg*1/5280);
  227. break;
  228. case 'nmi':
  229. block.value = (arg*1/ 6076.1154855643);
  230. break;
  231. }
  232. //* block:from_yd *//
  233. convertBlock('from_yd', 'from yd', 1000, 'yd');
  234. //* arg:from_yd *//
  235. var arg = logo.parseArg(logo, turtle, conns[1]);
  236. var unit = logo.parseArg(logo, turtle, conns[2]);
  237. switch (unit) {
  238. case 'mm':
  239. block.value = (arg*1/0.0010936132983377);
  240. break;
  241. case 'cm':
  242. block.value = (arg*1/0.0.010936132983377);
  243. break;
  244. case 'm':
  245. block.value = (arg*1/1.0936132983377);
  246. break;
  247. case 'km':
  248. block.value = (arg*1/1093.6132983377);
  249. break;
  250. case 'in':
  251. block.value = (arg*1/0.027777777777778);
  252. break;
  253. case 'ft':
  254. block.value = (arg*1/0.33333333333333);
  255. break;
  256. case 'yd':
  257. block.value = (arg*1/1);
  258. break;
  259. case 'mi':
  260. block.value = (arg*1/1760);
  261. break;
  262. case 'nmi':
  263. block.value = (arg*1/ 2025.3718285214);
  264. break;
  265. }
  266. //* block:from_mi *//
  267. convertBlock('from_mi', 'from mi', 1000, 'mi');
  268. //* arg:from_mi *//
  269. var arg = logo.parseArg(logo, turtle, conns[1]);
  270. var unit = logo.parseArg(logo, turtle, conns[2]);
  271. switch (unit) {
  272. case 'mm':
  273. block.value = (arg*1/0.00000062137119223733);
  274. break;
  275. case 'cm':
  276. block.value = (arg*1/0.0000062137119223733);
  277. break;
  278. case 'm':
  279. block.value = (arg*1/0.00062137119223733);
  280. break;
  281. case 'km':
  282. block.value = (arg*1/0.62137119223733);
  283. break;
  284. case 'in':
  285. block.value = (arg*1/0.000015782828282828);
  286. break;
  287. case 'ft':
  288. block.value = (arg*1/0.00018939393939394);
  289. break;
  290. case 'yd':
  291. block.value = (arg*1/0.00056818181818182);
  292. break;
  293. case 'mi':
  294. block.value = (arg*1/1);
  295. break;
  296. case 'nmi':
  297. block.value = (arg*1/1.1507794480235);
  298. break;
  299. }
  300. //* block:from_nmi *//
  301. convertBlock('from_nmi', 'from nmi', 1000, 'nmi');
  302. //* arg:from_nmi *//
  303. var arg = logo.parseArg(logo, turtle, conns[1]);
  304. var unit = logo.parseArg(logo, turtle, conns[2]);
  305. switch (unit) {
  306. case 'mm':
  307. block.value = (arg*1/0.00000053995680345572);
  308. break;
  309. case 'cm':
  310. block.value = (arg*1/0.0000053995680345572);
  311. break;
  312. case 'm':
  313. block.value = (arg*1/0.00053995680345572);
  314. break;
  315. case 'km':
  316. block.value = (arg*1/0.53995680345572);
  317. break;
  318. case 'in':
  319. block.value = (arg*1/0.000013714902807775);
  320. break;
  321. case 'ft':
  322. block.value = (arg*1/0.0001645788336933);
  323. break;
  324. case 'yd':
  325. block.value = (arg*1/0.00049373650107991);
  326. break;
  327. case 'mi':
  328. block.value = (arg*1/0.86897624190065);
  329. break;
  330. case 'nmi':
  331. block.value = (arg*1/1);
  332. break;
  333. }
  334. //* palette-icon:converter *//
  335. <svg xmlns="http://www.w3.org/2000/svg" width="55" height="55" viewBox="0 0 55 55"><g transform="matrix(1.25 0 0 1.25-7.5-6.25)"><g font-family="Sans" word-spacing="0" line-height="125%" letter-spacing="0" font-size="20"><text x="10" y="10"><tspan x="20" y="35" fill="#fff">len</tspan></text></g></g><g fill="#fff" stroke="#fff"><path d="m10.5 14.5h35"/><path d="m15.5 44.5v-35"/></g></svg>
  336. //* palette-fill:converter *// #ff00ff
  337. //* palette-stroke:converter *// #C700D3
  338. //* palette-highlight:converter *// #FF9FFF
  339. //* palette-stroke-highlight:converter *// #000000