ExMathSpiral.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /**
  2. * Copyright (c) 2011-2018 by Andrew Mustun. All rights reserved.
  3. *
  4. * This file is part of the QCAD project.
  5. *
  6. * QCAD is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * QCAD is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with QCAD.
  18. */
  19. include("../MathExamples.js");
  20. /**
  21. * \ingroup ecma_misc_examples_mathexamples
  22. * \class ExMathSpiral
  23. * This action draws a simple spiral (center at 0/0).
  24. */
  25. function ExMathSpiral(guiAction) {
  26. MathExamples.call(this, guiAction);
  27. }
  28. ExMathSpiral.prototype = new MathExamples();
  29. /**
  30. * Draws a spiral and terminates.
  31. */
  32. ExMathSpiral.prototype.beginEvent = function() {
  33. MathExamples.prototype.beginEvent.call(this);
  34. var document = this.getDocument();
  35. var di = this.getDocumentInterface();
  36. var operation = new RAddObjectsOperation(true);
  37. var r = 0;
  38. var aDelta = 2 * Math.PI / 100;
  39. var rDelta = 0.01;
  40. var c = 0;
  41. for (var a = 0.0; a < 10 * Math.PI; a += aDelta) {
  42. var lineData = new RLineData(
  43. new RVector(
  44. Math.cos(a) * r,
  45. Math.sin(a) * r
  46. ),
  47. new RVector(
  48. Math.cos(a + aDelta) * (r+rDelta),
  49. Math.sin(a + aDelta) * (r+rDelta)
  50. )
  51. );
  52. var line = new RLineEntity(document, lineData);
  53. operation.addObject(line);
  54. ++c;
  55. r += rDelta;
  56. }
  57. di.applyOperation(operation);
  58. this.terminate();
  59. };
  60. /**
  61. * Adds a menu for this action to Examples/Math Examples/Spiral.
  62. */
  63. ExMathSpiral.init = function(basePath) {
  64. var action = new RGuiAction(qsTr("&Spiral"), RMainWindowQt.getMainWindow());
  65. action.setRequiresDocument(true);
  66. action.setScriptFile(basePath + "/ExMathSpiral.js");
  67. action.setGroupSortOrder(79700);
  68. action.setSortOrder(100);
  69. action.setWidgetNames(["MathExamplesMenu"]);
  70. };