├── .gitignore
├── static
├── audio
│ ├── loop.mp3
│ └── loop.ogg
├── imgs
│ ├── title_bg.png
│ ├── border_left.png
│ ├── title_left.png
│ ├── title_right.png
│ ├── cluster_sprites.png
│ ├── right_scroll_bar.png
│ └── top_right_scroll.png
├── index.html
├── style.css
├── defrag.coffee
└── defrag.js
├── server.coffee
├── README.md
├── server.js
└── package.json
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | *.swp
3 |
--------------------------------------------------------------------------------
/static/audio/loop.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/uberscientist/win95-defrag-simulation/HEAD/static/audio/loop.mp3
--------------------------------------------------------------------------------
/static/audio/loop.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/uberscientist/win95-defrag-simulation/HEAD/static/audio/loop.ogg
--------------------------------------------------------------------------------
/static/imgs/title_bg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/uberscientist/win95-defrag-simulation/HEAD/static/imgs/title_bg.png
--------------------------------------------------------------------------------
/server.coffee:
--------------------------------------------------------------------------------
1 | connect = require 'connect'
2 |
3 | app = connect()
4 | app.use connect.static 'static'
5 | app.listen(8008)
6 |
--------------------------------------------------------------------------------
/static/imgs/border_left.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/uberscientist/win95-defrag-simulation/HEAD/static/imgs/border_left.png
--------------------------------------------------------------------------------
/static/imgs/title_left.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/uberscientist/win95-defrag-simulation/HEAD/static/imgs/title_left.png
--------------------------------------------------------------------------------
/static/imgs/title_right.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/uberscientist/win95-defrag-simulation/HEAD/static/imgs/title_right.png
--------------------------------------------------------------------------------
/static/imgs/cluster_sprites.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/uberscientist/win95-defrag-simulation/HEAD/static/imgs/cluster_sprites.png
--------------------------------------------------------------------------------
/static/imgs/right_scroll_bar.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/uberscientist/win95-defrag-simulation/HEAD/static/imgs/right_scroll_bar.png
--------------------------------------------------------------------------------
/static/imgs/top_right_scroll.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/uberscientist/win95-defrag-simulation/HEAD/static/imgs/top_right_scroll.png
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Windows 95 defrag simulator
2 | =============================
3 |
4 | Pour yourself a drink and relax to soothing experience of a Windows 95 disk defragmentation.
5 |
--------------------------------------------------------------------------------
/server.js:
--------------------------------------------------------------------------------
1 | // Generated by CoffeeScript 1.4.0
2 | (function() {
3 | var app, connect;
4 |
5 | connect = require('connect');
6 |
7 | app = connect();
8 |
9 | app.use(connect["static"]('static'));
10 |
11 | app.listen(8008);
12 |
13 | }).call(this);
14 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "nko3-of-glob",
3 | "version": "0.0.0-3",
4 | "description": "of glob",
5 | "main": "server.js",
6 | "scripts": {
7 | "start": "node server.js"
8 | },
9 | "repository": {
10 | "type": "git",
11 | "url": "git@github.com:nko3/of-glob.git"
12 | },
13 | "dependencies": {
14 | "connect": "2.6.2"
15 | },
16 | "engines": {
17 | "node": "0.8.x"
18 | },
19 | "subdomain": "of-glob.nko3"
20 | }
--------------------------------------------------------------------------------
/static/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Defrag Simulator
5 |
6 |
7 |
8 |
9 |
10 |
12 |
13 |

14 |

15 |
16 |
17 |
23 |
24 |
25 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/static/style.css:
--------------------------------------------------------------------------------
1 | body, html {
2 | font-family: "System", sans-serif;
3 | background-color: green;
4 | height: 100%;
5 | }
6 |
7 | #header {
8 | padding: 10px;
9 | color: #fff;
10 | font-weight: bold;
11 | }
12 |
13 | #vote {
14 | position: relative;
15 | top: 6px;
16 | }
17 |
18 | #title-bar {
19 | background-color: #00007B;
20 | background-image: url('./imgs/title_bg.png');
21 | background-repeat: repeat-x;
22 | width: 100%;
23 | height: 24px;
24 | overflow: hidden;
25 | margin: 0px;
26 | padding: 0px;
27 | border: 0px;
28 | }
29 |
30 | #title-left {
31 | float: left;
32 | }
33 |
34 | #title-right {
35 | float: right;
36 | }
37 |
38 | #right-scroll {
39 | background-image: url('./imgs/right_scroll_bar.png');
40 | background-repeat: repeat-y;
41 | width: 23px;
42 | height: 100%;
43 | float: right;
44 | margin: 0px;
45 | block: none;
46 | }
47 |
48 | #viewer {
49 | position: relative;
50 | background-color: #fff;
51 | background-image: url('./imgs/border_left.png');
52 | background-repeat: repeat-y;
53 | min-height: 100%;
54 | height: 100%;
55 | bottom: 0px;
56 | }
57 |
58 | #cluster-canvas {
59 | position: absolute;
60 | top: 2px;
61 | left: 7px;
62 | }
63 |
--------------------------------------------------------------------------------
/static/defrag.coffee:
--------------------------------------------------------------------------------
1 | window = this
2 | randInt = (low, high) -> Math.round Math.random() * (high - 1) + low
3 |
4 | genHDD = (numCluster) ->
5 | # 0=beginning 1=middle 2=end 3=optimized 4=free 5=not moved 6=bad 7=read 8=write
6 | # Generates HDD data
7 | for i in [0..numCluster]
8 | rnd = randInt(1,600)
9 | switch rnd
10 | when 1
11 | run = randInt(1,10)
12 | val = 1
13 | when 2
14 | run = randInt(1,10)
15 | val = 2
16 | when 4 or 40 or 44
17 | run = randInt(20, 200)
18 | val = 4
19 | when 5
20 | run = randInt(1,10)
21 | val = 5
22 | when 6
23 | run = randInt(5,20)
24 | val = 6
25 |
26 | if run > 0
27 | run--
28 | val
29 | else
30 | 0
31 |
32 | $ ->
33 | canvas = document.getElementById 'cluster-canvas'
34 | ctx = canvas.getContext '2d'
35 |
36 | clusterW = 9
37 | clusterH = 11
38 |
39 | # Resize defrag viewer on window resize
40 | $(window).resize ->
41 | resizeCanvas()
42 |
43 | resizeCanvas = ->
44 |
45 | width = $('#viewer').width() - 30
46 | height = $('#viewer').height()
47 |
48 | canvas.width = width
49 | canvas.height = height
50 |
51 | # Canvas size in clusters
52 | rowSize = Math.floor(width/clusterW)
53 | columnSize = Math.floor(height/clusterH)
54 |
55 | numCluster = Math.floor rowSize * columnSize
56 |
57 | # Generate and draw new HD data
58 | hdd = genHDD(numCluster)
59 | drawHDD(hdd, rowSize, columnSize, width, height)
60 |
61 | drawHDD = (hdd, rowSize, columnSize, width, height) ->
62 | clusterSprite = new Image()
63 | clusterSprite.src = 'imgs/cluster_sprites.png'
64 | clusterSprite.onload = ->
65 |
66 | # Function takes cluster type and index, then draws to canvas
67 | drawCluster = (cluster, index) ->
68 | xOffset = (index % rowSize) * clusterW
69 | yOffset = Math.floor(index / rowSize) * clusterH
70 | ctx.drawImage clusterSprite, clusterW*cluster, 0, clusterW, clusterH, xOffset, yOffset, clusterW, clusterH
71 |
72 | # Draw the HDD data
73 | for cluster, i in hdd
74 | drawCluster(cluster, i)
75 |
76 | # Drawing Functions
77 | readCluster = (index) ->
78 | hdd[index] = 4
79 | drawCluster(7, index)
80 | setTimeout ->
81 | drawCluster(4, index)
82 | , 100
83 |
84 | # Write cluster type to disc
85 | writeCluster = (cluster, index) ->
86 | drawCluster(8, index) # make it red for write
87 | # Then write appropriate cluster
88 | setTimeout ->
89 | do (cluster, index) ->
90 | hdd[index] = cluster
91 | drawCluster(cluster, index)
92 | , 100
93 |
94 | animate = (hdd) ->
95 | if window.writer or window.reader
96 | clearInterval window.writer
97 | clearInterval window.reader
98 |
99 | readIndex = Math.floor(hdd.length/2)
100 | window.reader = setInterval ->
101 | setTimeout ->
102 | curCluster = hdd[readIndex]
103 | hdLen = hdd.length
104 | do (curCluster) ->
105 | if writeIndex >= hdLen
106 | clearInterval window.reader
107 | if curCluster < 3
108 | readCluster(readIndex)
109 | readIndex++
110 | , randInt(0, 1200)
111 | , 60
112 |
113 | writeIndex = 0
114 | window.writer = setInterval ->
115 | setTimeout ->
116 | curCluster = hdd[writeIndex]
117 | hdLen = hdd.length
118 | do (curCluster) ->
119 | if writeIndex >= hdLen
120 | # Reset after reaching end of data
121 | resizeCanvas()
122 |
123 | if curCluster not in [5,6]
124 | writeCluster(3, writeIndex)
125 | writeIndex++
126 |
127 | else
128 | writeIndex++
129 | , randInt(0, 1200)
130 | , 30
131 |
132 | animate(hdd)
133 |
134 | resizeCanvas()
135 |
--------------------------------------------------------------------------------
/static/defrag.js:
--------------------------------------------------------------------------------
1 | // Generated by CoffeeScript 1.3.3
2 | (function() {
3 | var genHDD, randInt, window;
4 |
5 | window = this;
6 |
7 | randInt = function(low, high) {
8 | return Math.round(Math.random() * (high - 1) + low);
9 | };
10 |
11 | genHDD = function(numCluster) {
12 | var i, rnd, run, val, _i, _results;
13 | _results = [];
14 | for (i = _i = 0; 0 <= numCluster ? _i <= numCluster : _i >= numCluster; i = 0 <= numCluster ? ++_i : --_i) {
15 | rnd = randInt(1, 600);
16 | switch (rnd) {
17 | case 1:
18 | run = randInt(1, 10);
19 | val = 1;
20 | break;
21 | case 2:
22 | run = randInt(1, 10);
23 | val = 2;
24 | break;
25 | case 4 || 40 || 44:
26 | run = randInt(20, 200);
27 | val = 4;
28 | break;
29 | case 5:
30 | run = randInt(1, 10);
31 | val = 5;
32 | break;
33 | case 6:
34 | run = randInt(5, 20);
35 | val = 6;
36 | }
37 | if (run > 0) {
38 | run--;
39 | _results.push(val);
40 | } else {
41 | _results.push(0);
42 | }
43 | }
44 | return _results;
45 | };
46 |
47 | $(function() {
48 | var canvas, clusterH, clusterW, ctx, drawHDD, resizeCanvas;
49 | canvas = document.getElementById('cluster-canvas');
50 | ctx = canvas.getContext('2d');
51 | clusterW = 9;
52 | clusterH = 11;
53 | $(window).resize(function() {
54 | return resizeCanvas();
55 | });
56 | resizeCanvas = function() {
57 | var columnSize, hdd, height, numCluster, rowSize, width;
58 | width = $('#viewer').width() - 30;
59 | height = $('#viewer').height();
60 | canvas.width = width;
61 | canvas.height = height;
62 | rowSize = Math.floor(width / clusterW);
63 | columnSize = Math.floor(height / clusterH);
64 | numCluster = Math.floor(rowSize * columnSize);
65 | hdd = genHDD(numCluster);
66 | return drawHDD(hdd, rowSize, columnSize, width, height);
67 | };
68 | drawHDD = function(hdd, rowSize, columnSize, width, height) {
69 | var clusterSprite;
70 | clusterSprite = new Image();
71 | clusterSprite.src = 'imgs/cluster_sprites.png';
72 | return clusterSprite.onload = function() {
73 | var animate, cluster, drawCluster, i, readCluster, writeCluster, _i, _len;
74 | drawCluster = function(cluster, index) {
75 | var xOffset, yOffset;
76 | xOffset = (index % rowSize) * clusterW;
77 | yOffset = Math.floor(index / rowSize) * clusterH;
78 | return ctx.drawImage(clusterSprite, clusterW * cluster, 0, clusterW, clusterH, xOffset, yOffset, clusterW, clusterH);
79 | };
80 | for (i = _i = 0, _len = hdd.length; _i < _len; i = ++_i) {
81 | cluster = hdd[i];
82 | drawCluster(cluster, i);
83 | }
84 | readCluster = function(index) {
85 | hdd[index] = 4;
86 | drawCluster(7, index);
87 | return setTimeout(function() {
88 | return drawCluster(4, index);
89 | }, 100);
90 | };
91 | writeCluster = function(cluster, index) {
92 | drawCluster(8, index);
93 | return setTimeout(function() {
94 | return (function(cluster, index) {
95 | hdd[index] = cluster;
96 | return drawCluster(cluster, index);
97 | })(cluster, index);
98 | }, 100);
99 | };
100 | animate = function(hdd) {
101 | var readIndex, writeIndex;
102 | if (window.writer || window.reader) {
103 | clearInterval(window.writer);
104 | clearInterval(window.reader);
105 | }
106 | readIndex = Math.floor(hdd.length / 2);
107 | window.reader = setInterval(function() {
108 | return setTimeout(function() {
109 | var curCluster, hdLen;
110 | curCluster = hdd[readIndex];
111 | hdLen = hdd.length;
112 | return (function(curCluster) {
113 | if (writeIndex >= hdLen) {
114 | clearInterval(window.reader);
115 | }
116 | if (curCluster < 3) {
117 | readCluster(readIndex);
118 | }
119 | return readIndex++;
120 | })(curCluster);
121 | }, randInt(0, 1200));
122 | }, 60);
123 | writeIndex = 0;
124 | return window.writer = setInterval(function() {
125 | return setTimeout(function() {
126 | var curCluster, hdLen;
127 | curCluster = hdd[writeIndex];
128 | hdLen = hdd.length;
129 | return (function(curCluster) {
130 | if (writeIndex >= hdLen) {
131 | resizeCanvas();
132 | }
133 | if (curCluster !== 5 && curCluster !== 6) {
134 | writeCluster(3, writeIndex);
135 | return writeIndex++;
136 | } else {
137 | return writeIndex++;
138 | }
139 | })(curCluster);
140 | }, randInt(0, 1200));
141 | }, 30);
142 | };
143 | return animate(hdd);
144 | };
145 | };
146 | return resizeCanvas();
147 | });
148 |
149 | }).call(this);
150 |
--------------------------------------------------------------------------------