Commit 2885bfde authored by Jens-Christian Fischer's avatar Jens-Christian Fischer
Browse files

Bouncing instead of wrapping & cut back on psychedelics

parent bfba927a
......@@ -3,7 +3,7 @@ defmodule Grains.Mixfile do
def project do
[app: :grains,
version: "0.0.64",
version: "0.0.65",
elixir: "~> 1.2",
elixirc_paths: elixirc_paths(Mix.env),
compilers: [:phoenix, :gettext] ++ Mix.compilers,
......
......@@ -23,6 +23,9 @@ function Boid(p, x, y, type) {
this.separation_f = 2.5;
this.alignment_f = 1.0;
this.cohesion_f = 2.0;
this.spin = parseInt(this.p.random(-50, 50));
this.saturation = this.p.random(50, 100);
this.color = this.p.color(this.p.random(359), 100, 100);
};
......@@ -108,10 +111,11 @@ Boid.prototype.render = function() {
// Wraparound
Boid.prototype.borders = function() {
if (this.position.x < -this.r) this.position.x = PresenceSketch.width + this.r;
if (this.position.y < -this.r) this.position.y = PresenceSketch.height + this.r;
if (this.position.x > PresenceSketch.width + this.r) this.position.x = -this.r;
if (this.position.y > PresenceSketch.height + this.r) this.position.y = -this.r;
let jitter = this.p.random(0.9, 1.1);
if (this.position.x < -this.r) this.velocity.x = -this.velocity.x * jitter;
if (this.position.y < -this.r) this.velocity.y = -this.velocity.y * jitter;
if (this.position.x > PresenceSketch.width + this.r) this.velocity.x = -this.velocity.x * jitter;
if (this.position.y > PresenceSketch.height + this.r) this.velocity.y = -this.velocity.y * jitter;
};
// Separation
......@@ -299,7 +303,7 @@ Master.prototype.send_osc = function() {
}
Boid.prototype.adjust_radius = function() {
if (this.radius > this.norm_radius) { this.radius = this.radius - 1; };
if (this.radius > this.norm_radius && (this.p.frameCount % 3 == 0)) { this.radius = this.radius - 1; };
}
Master.prototype.adjust_radius = function() {
......@@ -310,26 +314,26 @@ Boid.prototype.fillColor = function() {
let color;
switch(this.type) {
case 'square': color = this.p.color(0, 80+ Math.random() * 20, (this.radius* 3));
case 'square': color = this.p.color(0, this.saturation, (this.radius* 3));
break;
case 'circle': color = this.p.color(90, 80 + Math.random() * 20, (this.radius * 3));
case 'circle': color = this.p.color(90, this.saturation, (this.radius * 3));
break;
case 'triangle': color = this.p.color(180, 80 + Math.random() * 20, (this.radius * 3));
case 'triangle': color = this.p.color(210, this.saturation, (this.radius * 3));
break;
case 'star': color = this.p.color(270, 80 + Math.random() * 20, (this.radius * 3));
case 'star': color = this.p.color(270, this.saturation, (this.radius * 3));
break;
}
return color;
}
Boid.prototype.render = function() {
this.p.fill(this.fillColor());
this.p.fill(this.color);
this.p.stroke(200);
this.p.push();
this.p.translate(this.position.x, this.position.y);
this.p.rotate(this.p.frameCount / 50.0);
this.p.rotate(this.p.frameCount / this.spin);
switch (this.type) {
case 'square': this.render_square();
break;
......@@ -471,7 +475,7 @@ let PresenceSketch = {
};
s.draw = function() {
// s.background(88, 131, 120);
s.background(88, 131, 120);
// Run all the boids
_.each(PresenceSketch.boids, function(boid, key, list) {
......
Markdown is supported
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