Skip to content

Commit 98cd43e

Browse files
committed
finish 01-02
完成【百人分钱|允许负债】算法实验
1 parent 1c76933 commit 98cd43e

File tree

22 files changed

+412
-9
lines changed

22 files changed

+412
-9
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,30 @@ npm install
1313
node app/bin/www.js --harmony
1414
```
1515

16-
Then open Browser at 'http://localhost:3000'
16+
Then open Browser at 'http://localhost:9009'
1717

1818
## 修改算法代码
1919

20-
Step 1. 编译 TypeScript
20+
### Step 1. 编译 TypeScript
2121

2222
```
2323
tsc
2424
```
2525

26-
Step 2. 打包 js 文件
26+
### Step 2. 打包 js 文件
2727

2828
需要先安装 browserify
2929

3030
```
3131
npm install -g browserify
3232
```
3333

34-
再进入对应的算法输出目录
34+
再进入对应的算法输出目录,打包代码
3535

3636
```
3737
browserify main.js -o bundle.js
3838
```
3939

4040
## Screenshots
4141

42-
![](https://airing.ursb.me/image/cover/lib-sreenshots.png)
42+
![](http://airing.ursb.me/image/cover/lib-sreenshots.png)

app/bin/www.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/public/javascripts/01-02-A-Money-Experiment-Extends/AlgoFrame.js

Lines changed: 44 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/public/javascripts/01-02-A-Money-Experiment-Extends/AlgoFrame.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/public/javascripts/01-02-A-Money-Experiment-Extends/AlgoVisHelper.js

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/public/javascripts/01-02-A-Money-Experiment-Extends/AlgoVisHelper.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/public/javascripts/01-02-A-Money-Experiment-Extends/AlgoVisualizer.js

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/public/javascripts/01-02-A-Money-Experiment-Extends/AlgoVisualizer.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
2+
"use strict";
3+
Object.defineProperty(exports, "__esModule", { value: true });
4+
var AlgoFrame = (function () {
5+
function AlgoFrame(canvasWidth, canvasHeight) {
6+
this.canvasWidth = canvasWidth;
7+
this.canvasHeight = canvasHeight;
8+
this.count = 0;
9+
this.rounds = document.getElementById('rounds');
10+
this.canvas = document.getElementById('canvas');
11+
this.canvas.width = canvasWidth;
12+
this.canvas.height = canvasHeight;
13+
}
14+
AlgoFrame.prototype.getCanvasWidth = function () {
15+
return this.canvasWidth;
16+
};
17+
AlgoFrame.prototype.getCanvasHeight = function () {
18+
return this.canvasHeight;
19+
};
20+
AlgoFrame.prototype.render = function (money) {
21+
this.money = money;
22+
this.repaint();
23+
};
24+
AlgoFrame.prototype.repaint = function () {
25+
this.count++;
26+
this.rounds.innerHTML = this.count;
27+
var ctx = this.canvas.getContext('2d');
28+
ctx.fillStyle = '#fff';
29+
ctx.fillRect(0, 0, this.canvasWidth, this.canvasHeight);
30+
var w = this.canvasWidth / this.money.length;
31+
for (var i = 0; i < this.money.length; i++) {
32+
if (this.money[i] > 0) {
33+
ctx.fillStyle = '#2196F3';
34+
ctx.fillRect(i * w + 1, this.canvasHeight / 2 - this.money[i], w - 1, this.money[i]);
35+
}
36+
else {
37+
ctx.fillStyle = '#F44336';
38+
ctx.fillRect(i * w + 1, this.canvasHeight / 2, w - 1, -this.money[i]);
39+
}
40+
}
41+
};
42+
return AlgoFrame;
43+
}());
44+
exports.AlgoFrame = AlgoFrame;
45+
46+
},{}],2:[function(require,module,exports){
47+
"use strict";
48+
Object.defineProperty(exports, "__esModule", { value: true });
49+
var AlgoFrame_1 = require("./AlgoFrame");
50+
var AlgoVisualizer = (function () {
51+
function AlgoVisualizer(sceneWidth, sceneHeight) {
52+
this.DELAY = 10;
53+
this.money = [];
54+
for (var i = 0; i < 100; i++) {
55+
this.money[i] = 100;
56+
}
57+
this.frame = new AlgoFrame_1.AlgoFrame(sceneWidth, sceneHeight);
58+
this.run();
59+
}
60+
AlgoVisualizer.prototype.run = function () {
61+
var _this = this;
62+
setInterval(function () {
63+
_this.frame.render(_this.money);
64+
for (var i = 0; i < _this.money.length; i++) {
65+
var j = Math.floor(Math.random() * _this.money.length);
66+
_this.money[i] -= 1;
67+
_this.money[j] += 1;
68+
}
69+
}, this.DELAY);
70+
};
71+
return AlgoVisualizer;
72+
}());
73+
exports.AlgoVisualizer = AlgoVisualizer;
74+
75+
},{"./AlgoFrame":1}],3:[function(require,module,exports){
76+
"use strict";
77+
Object.defineProperty(exports, "__esModule", { value: true });
78+
var AlgoVisualizer_1 = require("./AlgoVisualizer");
79+
var containerWidth = document.getElementById('container').clientWidth;
80+
var sceneWidth = containerWidth - 20;
81+
var sceneHeight = 800;
82+
var vis_01 = new AlgoVisualizer_1.AlgoVisualizer(sceneWidth, sceneHeight);
83+
84+
},{"./AlgoVisualizer":2}]},{},[3]);

app/public/javascripts/01-02-A-Money-Experiment-Extends/main.js

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)