Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactoring main

  • Loading branch information...
commit bce2c3709b4af8f092e33e50f2792196ab17dc95 1 parent 10f5271
@thiagotnunes authored
Showing with 22 additions and 26 deletions.
  1. +0 −1  index.html
  2. +22 −25 src/Main.js
View
1  index.html
@@ -22,7 +22,6 @@
var program = null;
$(document).ready(function() {
program = main($('#canvas')[0]);
- program.initialize();
});
</script>
View
47 src/Main.js
@@ -1,37 +1,34 @@
function main(canvas) {
- var self = {
- canvas : canvas
- };
-
- self.initialize = function() {
- var randomizer = locationRandomizer(self.canvas.width, self.canvas.height, 200);
- var creator = binaryNodeCreator(nodesCreator(12, randomizer));
- var repulsion = coulombRepulsion();
- var attraction = hookeAttraction();
- var nodeForces = forces(repulsion, attraction);
- self.locationCalculator = forceLocationCalculator(nodeForces);
- self.createNodesAndDraw(creator);
- }
+ var randomizer = locationRandomizer(canvas.width, canvas.height, 200);
+ var creator = binaryNodeCreator(nodesCreator(12, randomizer));
+ var repulsion = coulombRepulsion();
+ var attraction = hookeAttraction();
+ var nodeForces = forces(repulsion, attraction);
+ var locationCalculator = forceLocationCalculator(nodeForces);
- self.createNodesAndDraw = function(creator) {
- self.nodes = creator.nodes();
+ var nodes = function(creator) {
+ var nodes = creator.nodes();
- drawer = nodesDrawer(self.nodes, self.canvas);
+ drawer = nodesDrawer(nodes, canvas);
drawer.draw();
- }
- self.organize = function() {
- updateLocation(self.nodes);
- }
+ return nodes;
+ }(creator);
- function updateLocation(nodes) {
- self.locationCalculator.updateLocationOf(self.nodes, vector(0, 0));
+ var updateLocation = function(nodes) {
+ locationCalculator.updateLocationOf(nodes, vector(0, 0));
drawer.draw();
setTimeout(callback, 100);
function callback() {
- updateLocation(self.nodes);
+ updateLocation(nodes);
};
- }
+ };
- return self;
+ var organize = function() {
+ updateLocation(nodes);
+ };
+
+ return {
+ organize: organize
+ };
}
Please sign in to comment.
Something went wrong with that request. Please try again.