Commit 121f8746 authored by Jens-Christian Fischer's avatar Jens-Christian Fischer
Browse files

Grow boid on acceleration

parent cddfc939
...@@ -3,7 +3,7 @@ defmodule Grains.Mixfile do ...@@ -3,7 +3,7 @@ defmodule Grains.Mixfile do
def project do def project do
[app: :grains, [app: :grains,
version: "0.0.47", version: "0.0.48",
elixir: "~> 1.2", elixir: "~> 1.2",
elixirc_paths: elixirc_paths(Mix.env), elixirc_paths: elixirc_paths(Mix.env),
compilers: [:phoenix, :gettext] ++ Mix.compilers, compilers: [:phoenix, :gettext] ++ Mix.compilers,
......
...@@ -110,6 +110,7 @@ visuals.on("velocity", state => { ...@@ -110,6 +110,7 @@ visuals.on("velocity", state => {
visuals.on("acceleration", state => { visuals.on("acceleration", state => {
console.log("acceleration: ", state); console.log("acceleration: ", state);
PresenceSketch.set_acceleration(state.user, state.z);
}); });
visuals.join().receive("ok", resp => { visuals.join().receive("ok", resp => {
......
...@@ -11,13 +11,18 @@ function Boid(p, x, y) { ...@@ -11,13 +11,18 @@ function Boid(p, x, y) {
this.velocity = p5.Vector.random2D(); this.velocity = p5.Vector.random2D();
this.position = this.p.createVector(x, y); this.position = this.p.createVector(x, y);
this.r = 3.0; this.r = 3.0;
this.radius = 16;
this.maxspeed = 3; // Maximum speed this.maxspeed = 3; // Maximum speed
this.maxforce = 0.05; // Maximum steering force this.maxforce = 0.05; // Maximum steering force
}; };
Boid.prototype.set_velocity = function(dx, dy) { Boid.prototype.set_velocity = function(dx, dy) {
this.velocity = this.p.createVector(dx, dy); this.velocity = this.p.createVector(dx, dy);
} };
Boids.prototype.set_acceleration = function(z) {
this.r = 32;
};
Boid.prototype.run = function(boids) { Boid.prototype.run = function(boids) {
...@@ -73,9 +78,10 @@ Boid.prototype.seek = function(target) { ...@@ -73,9 +78,10 @@ Boid.prototype.seek = function(target) {
// Draw boid as a circle // Draw boid as a circle
Boid.prototype.render = function() { Boid.prototype.render = function() {
this.p.fill(127, 127); this.p.fill((this.radius * 8) - 1);
this.p.stroke(200); this.p.stroke(200);
this.p.ellipse(this.position.x, this.position.y, 16, 16); this.p.ellipse(this.position.x, this.position.y, this.radius, this.radius);
if (this.radius > 16) { this.radius = this.radius - 1; }
}; };
// Wraparound // Wraparound
...@@ -180,6 +186,10 @@ let PresenceSketch = { ...@@ -180,6 +186,10 @@ let PresenceSketch = {
PresenceSketch.boids[name].set_velocity(dx, dy); PresenceSketch.boids[name].set_velocity(dx, dy);
}, },
set_acceleration(name, z) {
PresenceSketch.boids[name].set_acceleration(z);
},
addBoids(joins) { addBoids(joins) {
if (!PresenceSketch.p5) { return; }; if (!PresenceSketch.p5) { return; };
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment