<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-1510520971560438082</id><updated>2020-07-13T11:07:21.847-07:00</updated><title type='text'>TG</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='https://lcvn2020.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/1510520971560438082/posts/default'/><link rel='alternate' type='text/html' href='https://lcvn2020.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>1</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-1510520971560438082.post-835707563581302734</id><published>2020-07-12T14:34:00.000-07:00</published><updated>2020-07-12T14:34:07.832-07:00</updated><title type='text'></title><content type='html'>&lt;br /&gt;&lt;html&gt;  &lt;head&gt;    &lt;meta charset=&quot;UTF-8&quot;&gt;    &lt;script language=&quot;javascript&quot; type=&quot;text/javascript&quot; src=&quot;https://cdn.jsdelivr.net/npm/p5@1.0.0/lib/p5.min.js&quot;&gt;&lt;/script&gt;     &lt;script language=&quot;javascript&quot; src=&quot;https://cdn.jsdelivr.net/npm/p5@1.0.0/lib/addons/p5.sound.min.js&quot;&gt;&lt;/script&gt;    &lt;script language=&quot;javascript&quot; type=&quot;text/javascript&quot;&gt;           // Daniel Shiffman       // The Coding Train       // Coding Challenge 69: Steering Evolution       // Part 1: https://youtu.be/flxOkx0yLrY       // Part 2: https://youtu.be/XaOVH8ZSRNA       // Part 3: https://youtu.be/vZUWTlK7D2Q       // Part 4: https://youtu.be/ykOcaInciBI       // Part 5: https://youtu.be/VnFF5V5DS8s        // https://editor.p5js.org/codingtrain/sketches/xgQNXkxx1        var mr = 0.01;        function Vehicle(x, y, dna) {         this.acceleration = createVector(0, 0);         this.velocity = createVector(0, -2);         this.position = createVector(x, y);         this.r = 4;         this.maxspeed = 5;         this.maxforce = 0.5;          this.health = 1;          this.dna = [];         if (dna === undefined) {           // Food weight           this.dna[0] = random(-2, 2);           // Poison weight           this.dna[1] = random(-2, 2);           // Food perception           this.dna[2] = random(0, 100);           // Poision Percepton           this.dna[3] = random(0, 100);         } else {           // Mutation           this.dna[0] = dna[0];           if (random(1) &lt; mr) {             this.dna[0] += random(-0.1, 0.1);           }           this.dna[1] = dna[1];           if (random(1) &lt; mr) {             this.dna[1] += random(-0.1, 0.1);           }           this.dna[2] = dna[2];           if (random(1) &lt; mr) {             this.dna[2] += random(-10, 10);           }           this.dna[3] = dna[3];           if (random(1) &lt; mr) {             this.dna[3] += random(-10, 10);           }         }          // Method to update location         this.update = function() {           this.health -= 0.005;            // Update velocity           this.velocity.add(this.acceleration);           // Limit speed           this.velocity.limit(this.maxspeed);           this.position.add(this.velocity);           // Reset accelerationelertion to 0 each cycle           this.acceleration.mult(0);         };          this.applyForce = function(force) {           // We could add mass here if we want A = F / M           this.acceleration.add(force);         };          this.behaviors = function(good, bad) {           var steerG = this.eat(good, 0.2, this.dna[2]);           var steerB = this.eat(bad, -1, this.dna[3]);            steerG.mult(this.dna[0]);           steerB.mult(this.dna[1]);            this.applyForce(steerG);           this.applyForce(steerB);         };          this.clone = function() {           if (random(1) &lt; 0.002) {             return new Vehicle(this.position.x, this.position.y, this.dna);           } else {             return null;           }         };          this.eat = function(list, nutrition, perception) {           var record = Infinity;           var closest = null;           for (var i = list.length - 1; i &gt;= 0; i--) {             var d = this.position.dist(list[i]);              if (d &lt; this.maxspeed) {               list.splice(i, 1);               this.health += nutrition;             } else {               if (d &lt; record &amp;&amp; d &lt; perception) {                 record = d;                 closest = list[i];               }             }           }            // This is the moment of eating!            if (closest != null) {             return this.seek(closest);           }            return createVector(0, 0);         };          // A method that calculates a steering force towards a target         // STEER = DESIRED MINUS VELOCITY         this.seek = function(target) {           var desired = p5.Vector.sub(target, this.position); // A vector pointing from the location to the target            // Scale to maximum speed           desired.setMag(this.maxspeed);            // Steering = Desired minus velocity           var steer = p5.Vector.sub(desired, this.velocity);           steer.limit(this.maxforce); // Limit to maximum steering force            return steer;           //this.applyForce(steer);         };          this.dead = function() {           return this.health &lt; 0;         };          this.display = function() {           // Draw a triangle rotated in the direction of velocity           var angle = this.velocity.heading() + PI / 2;            push();           translate(this.position.x, this.position.y);           rotate(angle);            if (debug.checked()) {             strokeWeight(3);             stroke(0, 255, 0);             noFill();             line(0, 0, 0, -this.dna[0] * 25);             strokeWeight(2);             ellipse(0, 0, this.dna[2] * 2);             stroke(255, 0, 0);             line(0, 0, 0, -this.dna[1] * 25);             ellipse(0, 0, this.dna[3] * 2);           }            var gr = color(0, 255, 0);           var rd = color(255, 0, 0);           var col = lerpColor(rd, gr, this.health);            fill(col);           stroke(col);           strokeWeight(1);           beginShape();           vertex(0, -this.r * 2);           vertex(-this.r, this.r * 2);           vertex(this.r, this.r * 2);           endShape(CLOSE);            pop();         };          this.boundaries = function() {           var d = 25;            var desired = null;            if (this.position.x &lt; d) {             desired = createVector(this.maxspeed, this.velocity.y);           } else if (this.position.x &gt; width - d) {             desired = createVector(-this.maxspeed, this.velocity.y);           }            if (this.position.y &lt; d) {             desired = createVector(this.velocity.x, this.maxspeed);           } else if (this.position.y &gt; height - d) {             desired = createVector(this.velocity.x, -this.maxspeed);           }            if (desired !== null) {             desired.normalize();             desired.mult(this.maxspeed);             var steer = p5.Vector.sub(desired, this.velocity);             steer.limit(this.maxforce);             this.applyForce(steer);           }         };       }     &lt;/script&gt;              &lt;script language=&quot;javascript&quot; type=&quot;text/javascript&quot;&gt;      // Daniel Shiffman       // The Coding Train       // Coding Challenge 69: Steering Evolution       // Part 1: https://youtu.be/flxOkx0yLrY       // Part 2: https://youtu.be/XaOVH8ZSRNA       // Part 3: https://youtu.be/vZUWTlK7D2Q       // Part 4: https://youtu.be/ykOcaInciBI       // Part 5: https://youtu.be/VnFF5V5DS8s        // https://editor.p5js.org/codingtrain/sketches/xgQNXkxx1        var vehicles = [];       var food = [];       var poison = [];        var debug;        function setup() {         createCanvas(640, 360);         for (var i = 0; i &lt; 50; i++) {           var x = random(width);           var y = random(height);           vehicles[i] = new Vehicle(x, y);         }          for (var i = 0; i &lt; 40; i++) {           var x = random(width);           var y = random(height);           food.push(createVector(x, y));         }          for (var i = 0; i &lt; 20; i++) {           var x = random(width);           var y = random(height);           poison.push(createVector(x, y));         }          debug = createCheckbox();       }        function mouseDragged() {         vehicles.push(new Vehicle(mouseX, mouseY));       }        function draw() {         background(51);          if (random(1) &lt; 0.1) {           var x = random(width);           var y = random(height);           food.push(createVector(x, y));         }          if (random(1) &lt; 0.01) {           var x = random(width);           var y = random(height);           poison.push(createVector(x, y));         }          for (var i = 0; i &lt; food.length; i++) {           fill(0, 255, 0);           noStroke();           ellipse(food[i].x, food[i].y, 4, 4);         }          for (var i = 0; i &lt; poison.length; i++) {           fill(255, 0, 0);           noStroke();           ellipse(poison[i].x, poison[i].y, 4, 4);         }          for (var i = vehicles.length - 1; i &gt;= 0; i--) {           vehicles[i].boundaries();           vehicles[i].behaviors(food, poison);           vehicles[i].update();           vehicles[i].display();            var newVehicle = vehicles[i].clone();           if (newVehicle != null) {             vehicles.push(newVehicle);           }            if (vehicles[i].dead()) {             var x = vehicles[i].position.x;             var y = vehicles[i].position.y;             food.push(createVector(x, y));             vehicles.splice(i, 1);           }         }       }      &lt;/script&gt;  &lt;/head&gt;   &lt;body&gt;  &lt;/body&gt;&lt;/html&gt;</content><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/1510520971560438082/posts/default/835707563581302734'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/1510520971560438082/posts/default/835707563581302734'/><link rel='alternate' type='text/html' href='https://lcvn2020.blogspot.com/2020/07/daniel-shiffman-coding-train-coding.html' title=''/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author></entry></feed>