Download:
child 2:087472f67526
parent 0:74b863d85894
1:06d076da4395
Anton Shestakov <av6@dwimlabs.net>, Sat, 12 Mar 2016 22:33:23 +0800
js: add compiled code

1 файлов изменено, 161 вставок(+), 0 удалений(-) [+]
sierpinski.js file | annotate | diff | comparison | revisions
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sierpinski.js Sat Mar 12 22:33:23 2016 +0800
@@ -0,0 +1,161 @@
+// Generated by CoffeeScript 1.10.0
+(function() {
+ var L,
+ extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
+ hasProp = {}.hasOwnProperty;
+
+ L = (function() {
+ function L($el, width, height, order) {
+ this.$el = $el;
+ this.width = width;
+ this.height = height;
+ this.order = order;
+ this.init();
+ this;
+ }
+
+ L.prototype.init = function() {
+ var fillrow, i, j, ref, ref1;
+ this.pointer = 0;
+ this.rule = this.a;
+ this.rows = [];
+ fillrow = function(len) {
+ var i, ref, str;
+ str = [];
+ for (i = 1, ref = len; 1 <= ref ? i <= ref : i >= ref; 1 <= ref ? i++ : i--) {
+ str.push(' ');
+ }
+ return str.join('');
+ };
+ for (i = 1, ref = this.height; 1 <= ref ? i <= ref : i >= ref; 1 <= ref ? i++ : i--) {
+ this.rows.push(fillrow(this.width));
+ }
+ for (j = 1, ref1 = this.order; 1 <= ref1 ? j <= ref1 : j >= ref1; 1 <= ref1 ? j++ : j--) {
+ this.rule = this.rule.replace(/a/g, 'x').replace(/b/g, 'y').replace(/x/g, this.a).replace(/y/g, this.b);
+ }
+ };
+
+ L.prototype.putc = function(x, y, c) {
+ var replacec;
+ replacec = function(str, pos, c) {
+ return str.substr(0, pos) + c + str.substr(pos + c.length);
+ };
+ if ((0 <= x && x < this.width) && (0 <= y && y < this.height)) {
+ this.rows[y] = replacec(this.rows[y], x, c);
+ }
+ };
+
+ L.prototype.line = function() {
+ switch (this.angle) {
+ case 0:
+ this.putc(this.x, this.y, '__');
+ this.x += 2;
+ break;
+ case 60:
+ this.putc(this.x, this.y, '/');
+ this.x++;
+ this.y--;
+ break;
+ case 120:
+ this.x--;
+ this.putc(this.x, this.y, '\\');
+ this.y--;
+ break;
+ case 180:
+ this.x -= 2;
+ this.putc(this.x, this.y, '__');
+ break;
+ case 240:
+ this.x--;
+ this.y++;
+ this.putc(this.x, this.y, '/');
+ break;
+ case 300:
+ this.y++;
+ this.putc(this.x, this.y, '\\');
+ this.x++;
+ }
+ };
+
+ L.prototype.step = function(visible) {
+ var redraw;
+ if (this.pointer >= this.rule.length) {
+ return false;
+ }
+ redraw = false;
+ switch (this.rule[this.pointer]) {
+ case 'a':
+ case 'b':
+ this.line();
+ redraw = true;
+ break;
+ case '-':
+ this.angle = (this.angle + 60 + 360) % 360;
+ break;
+ case '+':
+ this.angle = (this.angle - 60 + 360) % 360;
+ }
+ this.pointer++;
+ if (visible) {
+ if (redraw) {
+ this.draw();
+ } else {
+ this.step(visible);
+ }
+ }
+ return true;
+ };
+
+ L.prototype.draw = function() {
+ return this.$el.text(this.rows.join('\n'));
+ };
+
+ return L;
+
+ })();
+
+ window.Sierpinski = (function(superClass) {
+ extend(Sierpinski, superClass);
+
+ function Sierpinski() {
+ return Sierpinski.__super__.constructor.apply(this, arguments);
+ }
+
+ Sierpinski.prototype.a = 'b-a-b';
+
+ Sierpinski.prototype.b = 'a+b+a';
+
+ Sierpinski.prototype.init = function() {
+ this.x = this.width - 2;
+ this.y = this.height - 2;
+ this.angle = 180;
+ return Sierpinski.__super__.init.apply(this, arguments);
+ };
+
+ return Sierpinski;
+
+ })(L);
+
+ window.Flowsnake = (function(superClass) {
+ extend(Flowsnake, superClass);
+
+ function Flowsnake() {
+ return Flowsnake.__super__.constructor.apply(this, arguments);
+ }
+
+ Flowsnake.prototype.a = 'a-b--b+a++aa+b-';
+
+ Flowsnake.prototype.b = '+a-bb--b-a++a+b';
+
+ Flowsnake.prototype.init = function() {
+ this.x = this.width / 2;
+ this.y = this.height;
+ this.angle = 0;
+ return Flowsnake.__super__.init.apply(this, arguments);
+ };
+
+ return Flowsnake;
+
+ })(L);
+
+}).call(this);