Permalink
Browse files

Split the stuff so that it's one class per file

  • Loading branch information...
1 parent 77047de commit cb862b151a5d145a5e4ceecb43ec96310dcc39bb @Gianfrancoalongi committed Mar 29, 2013
Showing with 119 additions and 118 deletions.
  1. +15 −0 edge_node.js
  2. +0 −118 engine.js
  3. +4 −0 index.html
  4. +84 −0 mutator.js
  5. +16 −0 output.js
View
@@ -0,0 +1,15 @@
+function new_edge_node(id,shape) {
+ var edgenode = {
+ id: id,
+ shape: shape,
+
+ generate_dot_code: function() {
+ return this.id;
+ },
+
+ generate_shape_dot_code: function(color) {
+ return this.id+'[shape='+this.shape+'];'
+ }
+ };
+ return edgenode;
+}
View
118 engine.js
@@ -5,124 +5,6 @@ var ADD_OUTPUT = 'add_output';
var REMOVE_MUTATOR_NODE = 'remove_mutator_node';
var REMOVE_OUTPUT_NODE = 'remove_output_node';
-function new_edge_node(id,shape) {
- var edgenode = {
- id: id,
- shape: shape,
-
- generate_dot_code: function() {
- return this.id;
- },
-
- generate_shape_dot_code: function(color) {
- return this.id+'[shape='+this.shape+'];'
- }
- };
- return edgenode;
-}
-
-function new_mutator(name) {
-
- var mutator = {
- id: name,
- buffer: 0,
- transform: "nothing",
- args: [],
-
- set_mutator_values: function() {
- this.buffer = random_buffer_size();
- this.transform = random_transform();
- this.args = this.random_arguments();
- },
-
- random_arguments: function() {
- var upto = this.buffer + 1;
- var a = sequence(1,upto);
- var b = shuffle(a);
- remove_some(b);
- return b;
- },
-
- generate_dot_code: function() {
- return this.id;
- },
-
- generate_shape_dot_code: function(color) {
- var label_text = this.generate_label_text();
- var result = this.id+'[label="'+label_text+'",color='+color+',shape=hexagon]';
- return result;
- },
-
- generate_label_text: function() {
- var txt = ["Buffer:"+this.buffer,
- "Transform:"+this.transform,
- "[x_i]:"+this.args];
- return txt.join('\\n');
- },
-
- get_name: function() {
- return this.id;
- }
-
- };
- mutator.set_mutator_values();
- return mutator;
-}
-
-function new_output(name) {
-
- var output = {
- id: name,
-
- generate_dot_code: function() {
- return this.id;
- },
-
- generate_shape_dot_code: function(color) {
- return this.id+'[shape=note,color='+color+']';
- }
-
- };
- return output;
-}
-
-function random_transform() {
- return choose_one_randomly(["order",
- "increase",
- "decrease",
- "type",
- "copy",
- "sum",
- "encode"]);
-}
-
-function random_buffer_size() {
- return Math.round(Math.random()*7)+1;
-}
-
-function shuffle(o){
- for(var j, x, i = o.length; i; j= parseInt(Math.random() * i),
- x = o[--i], o[i] = o[j], o[j] = x);
- return o;
-}
-
-function sequence(from,to) {
- var nums=[];
- for(var i = from; i <= to; i++) {
- nums.push(i);
- }
- return nums;
-}
-
-function remove_some(input) {
- var len = input.length - 1;
- while( len-- ) {
- if ( Math.round(Math.random()) == 0 ) {
- input.splice(len,1);
- }
- }
-}
-
function new_graph(img_id) {
var graph = {
View
@@ -2,6 +2,10 @@
<html>
<head>
<script language="javascript" type="text/javascript" src="./jquery-1.9.1.min.js"></script>
+ <script language="javascript" type="text/javascript" src="./edge_node.js"></script>
+ <script language="javascript" type="text/javascript" src="./output.js"></script>
+ <script language="javascript" type="text/javascript" src="./output.js"></script>
+ <script language="javascript" type="text/javascript" src="./mutator.js"></script>
<script language="javascript" type="text/javascript" src="./engine.js"></script>
</head>
<style type="text/css" media="screen, print, projection">
View
@@ -0,0 +1,84 @@
+function new_mutator(name) {
+
+ var mutator = {
+ id: name,
+ buffer: 0,
+ transform: "nothing",
+ args: [],
+
+ set_mutator_values: function() {
+ this.buffer = random_buffer_size();
+ this.transform = random_transform();
+ this.args = this.random_arguments();
+ },
+
+ random_arguments: function() {
+ var upto = this.buffer + 1;
+ var a = sequence(1,upto);
+ var b = shuffle(a);
+ remove_some(b);
+ return b;
+ },
+
+ generate_dot_code: function() {
+ return this.id;
+ },
+
+ generate_shape_dot_code: function(color) {
+ var label_text = this.generate_label_text();
+ var result = this.id+'[label="'+label_text+'",color='+color+',shape=hexagon]';
+ return result;
+ },
+
+ generate_label_text: function() {
+ var txt = ["Buffer:"+this.buffer,
+ "Transform:"+this.transform,
+ "[x_i]:"+this.args];
+ return txt.join('\\n');
+ },
+
+ get_name: function() {
+ return this.id;
+ }
+
+ };
+ mutator.set_mutator_values();
+ return mutator;
+}
+
+function random_transform() {
+ return choose_one_randomly(["order",
+ "increase",
+ "decrease",
+ "type",
+ "copy",
+ "sum",
+ "encode"]);
+}
+
+function random_buffer_size() {
+ return Math.round(Math.random()*7)+1;
+}
+
+function shuffle(o){
+ for(var j, x, i = o.length; i; j= parseInt(Math.random() * i),
+ x = o[--i], o[i] = o[j], o[j] = x);
+ return o;
+}
+
+function sequence(from,to) {
+ var nums=[];
+ for(var i = from; i <= to; i++) {
+ nums.push(i);
+ }
+ return nums;
+}
+
+function remove_some(input) {
+ var len = input.length - 1;
+ while( len-- ) {
+ if ( Math.round(Math.random()) == 0 ) {
+ input.splice(len,1);
+ }
+ }
+}
View
@@ -0,0 +1,16 @@
+function new_output(name) {
+
+ var output = {
+ id: name,
+
+ generate_dot_code: function() {
+ return this.id;
+ },
+
+ generate_shape_dot_code: function(color) {
+ return this.id+'[shape=note,color='+color+']';
+ }
+
+ };
+ return output;
+}

0 comments on commit cb862b1

Please sign in to comment.