Web Interface For Lite Argus Control modules
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.

122 lines
4.0 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Future Splash</title>
  6. <link rel="stylesheet" href="../css/style.css">
  7. <script type="text/javascript" src="../../dist/paper-full.js"></script>
  8. <script type="text/paperscript" canvas="canvas">
  9. // Code ported to Paper.js from http://the389.com/9/1/
  10. // with permission.
  11. var values = {
  12. friction: 0.8,
  13. timeStep: 0.01,
  14. amount: 15,
  15. mass: 2,
  16. count: 0
  17. };
  18. values.invMass = 1 / values.mass;
  19. var path, springs;
  20. var size = view.size * [1.2, 1];
  21. var Spring = function(a, b, strength, restLength) {
  22. this.a = a;
  23. this.b = b;
  24. this.restLength = restLength || 80;
  25. this.strength = strength ? strength : 0.55;
  26. this.mamb = values.invMass * values.invMass;
  27. };
  28. Spring.prototype.update = function() {
  29. var delta = this.b - this.a;
  30. var dist = delta.length;
  31. var normDistStrength = (dist - this.restLength) /
  32. (dist * this.mamb) * this.strength;
  33. delta.y *= normDistStrength * values.invMass * 0.2;
  34. if (!this.a.fixed)
  35. this.a.y += delta.y;
  36. if (!this.b.fixed)
  37. this.b.y -= delta.y;
  38. };
  39. function createPath(strength) {
  40. var path = new Path({
  41. fillColor: 'black'
  42. });
  43. springs = [];
  44. for (var i = 0; i <= values.amount; i++) {
  45. var segment = path.add(new Point(i / values.amount, 0.5) * size);
  46. var point = segment.point;
  47. if (i == 0 || i == values.amount)
  48. point.y += size.height;
  49. point.px = point.x;
  50. point.py = point.y;
  51. // The first two and last two points are fixed:
  52. point.fixed = i < 2 || i > values.amount - 2;
  53. if (i > 0) {
  54. var spring = new Spring(segment.previous.point, point, strength);
  55. springs.push(spring);
  56. }
  57. }
  58. path.position.x -= size.width / 4;
  59. return path;
  60. }
  61. function onResize() {
  62. if (path)
  63. path.remove();
  64. size = view.bounds.size * [2, 1];
  65. path = createPath(0.1);
  66. }
  67. function onMouseMove(event) {
  68. var location = path.getNearestLocation(event.point);
  69. var segment = location.segment;
  70. var point = segment.point;
  71. if (!point.fixed && location.distance < size.height / 4) {
  72. var y = event.point.y;
  73. point.y += (y - point.y) / 6;
  74. var previous = segment.previous && segment.previous.point;
  75. var next = segment.next && segment.next.point;
  76. if (previous && !previous.fixed)
  77. previous.y += (y - previous.y) / 24;
  78. if (next && !next.fixed)
  79. next.y += (y - next.y) / 24;
  80. }
  81. }
  82. function onFrame(event) {
  83. updateWave(path);
  84. }
  85. function updateWave(path) {
  86. var force = 1 - values.friction * values.timeStep * values.timeStep;
  87. for (var i = 0, l = path.segments.length; i < l; i++) {
  88. var point = path.segments[i].point;
  89. var dy = (point.y - point.py) * force;
  90. point.py = point.y;
  91. point.y = Math.max(point.y + dy, 0);
  92. }
  93. for (var j = 0, l = springs.length; j < l; j++) {
  94. springs[j].update();
  95. }
  96. path.smooth({ type: 'continuous' });
  97. }
  98. function onKeyDown(event) {
  99. if (event.key == 'space') {
  100. path.fullySelected = !path.fullySelected;
  101. path.fillColor = path.fullySelected ? null : 'black';
  102. }
  103. }
  104. </script>
  105. </head>
  106. <body>
  107. <canvas id="canvas" resize hidpi="off"></canvas>
  108. </body>
  109. </html>