0
-function setup(canvasElement) {
0
- canvas = canvasElement;
0
- ctx = canvas.getContext("2d");
0
@@ -121,91 +115,100 @@ Graphics.prototype.setRGBA = function (rgba) {
0
this.ctx.globalAlpha = rgba[3];
0
- var sourceText = document.getElementById("sourceField").value;
0
- var err = lex(sourceText, new Parser(new Builder(model)));
0
- var msg = "syntax error at \'" + err.token + "\' on line " + err.lineno + ": " + err.message;
0
- drawingContext = new Context(model); // global
0
- drawingContext.transform.m[1][1] *= -1;
0
- model.randomGenerator = new RepeatableRandom;
0
- var graphics = drawingContext.graphics;
0
- graphics.setCanvas(document.getElementById("canvas"));
0
- graphics.rescale = 0.25;
0
- var tm = drawingContext.transform.m;
0
- //tm[0][0] = tm[1][1] = 20;
0
- //drawingContext.stats.cutoff *= Math.abs(tm[0][0] * tm[1][1]);
0
- //drawingContext.stats.cutoff /= 100;
0
- bounds = new Bounds(0, 0, 0, 0);
0
- drawingContext.graphics.setViewport(bounds);
0
- drawingContext.graphics.bounds = bounds;
0
- startTime: (new Date).getTime(),
0
- model.draw(drawingContext);
0
- document.getElementById('renderButton').style.display = 'none';
0
- document.getElementById('stopButton').style.display = 'inline';
0
- if (drawingContext == null) return; // if stopRendering has been called
0
- var graphics = drawingContext.graphics;
0
- var oldBounds = graphics.viewport;
0
- var newBounds = graphics.bounds;
0
- if (!newBounds.equals(oldBounds)) {
0
- var w = newBounds.xmax - newBounds.xmin;
0
- var h = newBounds.ymax - newBounds.ymin;
0
- var rescale = graphics.rescale;
0
- graphics.rescale += 0.05;
0
- if (newBounds.xmin < oldBounds.xmin) newBounds.xmin -= rescale * w;
0
- if (newBounds.ymin < oldBounds.ymin) newBounds.ymin -= rescale * h;
0
- if (newBounds.xmax > oldBounds.xmax) newBounds.xmax += rescale * w;
0
- if (newBounds.ymax > oldBounds.ymax) newBounds.ymax += rescale * h;
0
- //info("scale to " + Bounds.xmin + ", " + Bounds.ymin + ", " + Bounds.xmax + ", " + Bounds.ymax);
0
- w = newBounds.xmax - newBounds.xmin;
0
- h = newBounds.xmax - newBounds.xmin;
0
- var car = graphics.canvas.width / graphics.canvas.height;
0
- graphics.setViewport(newBounds);
0
- graphics.bounds = newBounds;
0
- drawingContext.queue = [];
0
- model.randomGenerator.rewind();
0
- Stats.resetCount += 1;
0
- model.draw(drawingContext);
0
- drawingContext.flush(100);
0
- var t0 = Stats.startTime;
0
- var t1 = (new Date).getTime();
0
- var msg = "Rendered " + Stats.shapeCount + " shapes in " + Math.round((t1-t0)/1000) + "s.";
0
- if (drawingContext.queue.length)
0
- msg += " " + drawingContext.queue.length + " expansions remaining.";
0
- if (Stats.resetCount) msg += " (Reset bounds " + Stats.resetCount + " time"+(Stats.resetCount==1?'':'s')+".)";
0
- $('#statusField').html(msg);
0
- if (drawingContext.queue.length)
0
- setTimeout(drawNext, 10);
0
-function stopRendering() {
0
- if (drawingContext.queue.length)
0
- $('#statusField').html("<font color='#ff0000'>Stopped rendering</font> at " + Stats.shapeCount + " shapes after " + Math.round(((new Date).getTime() - Stats.startTime)/1000) + "s, with " + drawingContext.queue.length + " expansions remaining.");
0
- drawingContext.queue = [];
0
- drawingContext = null;
0
- document.getElementById('renderButton').style.display = '';
0
- document.getElementById('stopButton').style.display = 'none';
0
+var CFDG = window.CFDG || {};
0
+ setup: function(options) {
0
+ this.options = options;
0
+ canvas = options.canvas;
0
+ ctx = canvas.getContext("2d");
0
+ start: function(sourceText) {
0
+ var err = lex(sourceText, new Parser(new Builder(model)));
0
+ var msg = "syntax error at \'" + err.token + "\' on line " + err.lineno + ": " + err.message;
0
+ this.options.onerror(msg);
0
+ drawingContext = new Context(model); // global
0
+ drawingContext.transform.m[1][1] *= -1;
0
+ model.randomGenerator = new RepeatableRandom;
0
+ var graphics = drawingContext.graphics;
0
+ graphics.setCanvas(canvas);
0
+ graphics.rescale = 0.25;
0
+ var tm = drawingContext.transform.m;
0
+ //tm[0][0] = tm[1][1] = 20;
0
+ //drawingContext.stats.cutoff *= Math.abs(tm[0][0] * tm[1][1]);
0
+ //drawingContext.stats.cutoff /= 100;
0
+ bounds = new Bounds(0, 0, 0, 0);
0
+ drawingContext.graphics.setViewport(bounds);
0
+ drawingContext.graphics.bounds = bounds;
0
+ startTime: (new Date).getTime(),
0
+ model.draw(drawingContext);
0
+ (this.options.onstart||function(){})();
0
+ if (drawingContext == null)
0
+ var graphics = drawingContext.graphics,
0
+ oldBounds = graphics.viewport,
0
+ newBounds = graphics.bounds;
0
+ if (!newBounds.equals(oldBounds)) {
0
+ var w = newBounds.xmax - newBounds.xmin;
0
+ var h = newBounds.ymax - newBounds.ymin;
0
+ var rescale = graphics.rescale;
0
+ graphics.rescale += 0.05;
0
+ if (newBounds.xmin < oldBounds.xmin) newBounds.xmin -= rescale * w;
0
+ if (newBounds.ymin < oldBounds.ymin) newBounds.ymin -= rescale * h;
0
+ if (newBounds.xmax > oldBounds.xmax) newBounds.xmax += rescale * w;
0
+ if (newBounds.ymax > oldBounds.ymax) newBounds.ymax += rescale * h;
0
+ w = newBounds.xmax - newBounds.xmin;
0
+ h = newBounds.xmax - newBounds.xmin;
0
+ var car = graphics.canvas.width / graphics.canvas.height;
0
+ graphics.setViewport(newBounds);
0
+ graphics.bounds = newBounds;
0
+ drawingContext.queue = [];
0
+ model.randomGenerator.rewind();
0
+ Stats.resetCount += 1;
0
+ model.draw(drawingContext);
0
+ drawingContext.flush(100);
0
+ var t0 = Stats.startTime,
0
+ t1 = new Date().getTime();
0
+ var msg = "Rendered " + Stats.shapeCount + " shapes in " + Math.round((t1-t0)/1000) + "s.";
0
+ if (drawingContext.queue.length)
0
+ msg += " " + drawingContext.queue.length + " expansions remaining.";
0
+ if (Stats.resetCount) msg += " (Reset bounds " + Stats.resetCount + " time"+(Stats.resetCount==1?'':'s')+".)";
0
+ this.options.onstatus(msg);
0
+ if (drawingContext.queue.length)
0
+ setTimeout(function() {CFDG.Driver.step()}, 10);
0
+ if (drawingContext.queue.length)
0
+ this.options.onstatus("<font color='#ff0000'>Stopped rendering</font> at " + Stats.shapeCount + " shapes after " + Math.round(((new Date).getTime() - Stats.startTime)/1000) + "s, with " + drawingContext.queue.length + " expansions remaining.");
0
+ drawingContext.queue = [];
0
+ drawingContext = null;
0
+ (this.options.onstop||function(){})();
0
\ No newline at end of file
Comments
No one has commented yet.