Skip to content

Commit

Permalink
Adds DNA
Browse files Browse the repository at this point in the history
  • Loading branch information
samagra14 committed Mar 5, 2018
1 parent 0dd73a2 commit 8fd3079
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
7 changes: 7 additions & 0 deletions DNA.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function DNA(lifespan){
this.genes = [];
for (var i = 0; i < lifespan; i++) {
this.genes[i] = p5.Vector.random2D();

}
}
4 changes: 2 additions & 2 deletions Population.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
function Population(){
function Population(lifespan){
this.rockets = [];
this.size = 100;
for (var i = 0; i <this.size; i++) {
this.rockets[i] = new Rocket();
this.rockets[i] = new Rocket(lifespan);
}

this.run = function(){
Expand Down
12 changes: 10 additions & 2 deletions Rocket.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
function Rocket(){


function Rocket(lifespan){
this.pos = createVector(width/2,height);
this.vel = p5.Vector.random2D();
this.vel = createVector();
this.acc = createVector();
this.dna = new DNA(lifespan);
this.count = 0;

this.applyForce = function(force){
this.acc.add(force);
}

this.update = function(){
this.applyForce(this.dna.genes[this.count]);
//console.log(this.dna.genes[this.count]);
//console.log(this.count);
this.count++;
this.vel.add(this.acc);
this.pos.add(this.vel);
this.acc.mult(0);
Expand Down
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<script src="./logic.js"></script>
<script src="./Rocket.js"></script>
<script src="./Population.js"></script>
<script src="./DNA.js"></script>
</head>
<body>
</body>
Expand Down
3 changes: 2 additions & 1 deletion logic.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
var population;
var lifespan = 200;
function setup(){
createCanvas(window.innerWidth,window.innerHeight);
population = new Population();
population = new Population(lifespan);
}


Expand Down

0 comments on commit 8fd3079

Please sign in to comment.