Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

period slider works

  • Loading branch information...
commit 8efe010487a068ad7b71e25e9a164496ebc1421a 1 parent ed2f188
@shamansir shamansir authored
Showing with 39 additions and 24 deletions.
  1. +4 −0 sandbox/sandbox.css
  2. +1 −1  sandbox/sandbox.html
  3. +34 −23 sandbox/sandbox.js
View
4 sandbox/sandbox.css
@@ -160,4 +160,8 @@ select#examples-list {
font-family: monospace;
font-size: 12px;
width: 400px;
+}
+
+#refresh-calc {
+ font-size: .8em;
}
View
2  sandbox/sandbox.html
@@ -59,7 +59,7 @@
<canvas id="my-canvas" width="400" height="300"></canvas> <!-- canvas -->
</div>
- <div><p id="refresh-calc">Current refresh period: <span data-var="secPeriod" class="TKAdjustableNumber" data-max="60"> seconds</span>. It will be reloaded <span data-var="perMinute"> times</span> per minute</p></div>
+ <div><p id="refresh-calc">Current refresh period: <span data-var="secPeriod" class="TKAdjustableNumber" data-max="60"> seconds</span>.<br/>Animation will be reloaded <span data-var="perMinute"> times</span> per minute</p></div>
<div id="errors" style="display: none;">&nbsp;</div> <!-- errors -->
View
57 sandbox/sandbox.js
@@ -98,27 +98,36 @@ function sandbox() {
//this.cm.setValue('return <your code here>;');
var s = this;
-
- setTimeout(function() {
- setInterval(function() {
- s.errorsElm.style.display = 'none';
+ var curInterval = null;
+ var refreshRate = 3000;
+ function refresh() {
+ s.errorsElm.style.display = 'none';
+ s.player.stop();
+ try {
+ var code = ['(function(){',
+ ' '+s.cm.getValue(),
+ '})();'].join('\n');
+ var scene = eval(code);
+ player.load(scene);
+ player.play();
+ } catch(e) {
s.player.stop();
- try {
- var code = ['(function(){',
- ' '+s.cm.getValue(),
- '})();'].join('\n');
- var scene = eval(code);
- player.load(scene);
- player.play();
- } catch(e) {
- s.player.stop();
- s.player.drawSplash();
- s.errorsElm.style.display = 'block';
- s.errorsElm.innerHTML = '<strong>Error:&nbsp;</strong>'+e.message;
- throw e;
- };
- }, 3000); // TODO: ability to change timeout value
- }, 1);
+ s.player.drawSplash();
+ s.errorsElm.style.display = 'block';
+ s.errorsElm.innerHTML = '<strong>Error:&nbsp;</strong>'+e.message;
+ //throw e;
+ };
+ };
+
+ function updateInterval(to) {
+ if (curInterval) clearInterval(curInterval);
+ setTimeout(function() {
+ refreshRate = to;
+ curInterval = setInterval(refresh, to);
+ }, 1);
+ }
+
+
setTimeout(function() {
store_examples(); // store current examples, it will skip if their versions match
@@ -132,14 +141,16 @@ function sandbox() {
var tangleModel = {
initialize: function () {
- this.secPeriod = 3;
- this.perMinute = 20;
+ this.secPeriod = refreshRate / 1000;
},
update: function () {
- this.perMinute = 60 / this.secPeriod;
+ this.perMinute = Math.floor((60 / this.secPeriod) * 100) / 100;
+ updateInterval(this.secPeriod * 1000);
}
};
+ updateInterval(refreshRate);
+
new Tangle(this.tangleElm, tangleModel);
}
Please sign in to comment.
Something went wrong with that request. Please try again.