Basic breathing... needs more refinement
This commit is contained in:
parent
26d45774dc
commit
33be6008d2
|
@ -7,16 +7,13 @@ Engine.Point.Puller = function(id, x, y, shapeSize){
|
|||
this.id = id;
|
||||
|
||||
this.shapeSize = shapeSize;
|
||||
this.ref = new Vector(x, y);
|
||||
|
||||
this.ref = {
|
||||
x: x,
|
||||
y: y
|
||||
};
|
||||
this.pos = new Vector(
|
||||
x * shapeSize.x,
|
||||
y * shapeSize.y
|
||||
);
|
||||
|
||||
this.pos.x = x * shapeSize.x;
|
||||
this.pos.y = y * shapeSize.y;
|
||||
|
||||
this.pos = Vector.coerce(this.pos);
|
||||
this.home = this.pos.clone();
|
||||
this.accel = Vector.coerce(this.accel);
|
||||
this.vel = Vector.coerce(this.vel);
|
||||
|
|
|
@ -3,14 +3,22 @@
|
|||
Vector
|
||||
){ 'use strict';
|
||||
|
||||
Engine.Point = function(id, x, y, width, height){
|
||||
Engine.Point = function(id, x, y, shapeSize){
|
||||
this.id = id;
|
||||
this.pos = new Vector(x, y);
|
||||
|
||||
this.shapeSize = shapeSize;
|
||||
this.ref = new Vector(x, y);
|
||||
|
||||
this.pos = new Vector(
|
||||
x * shapeSize.x,
|
||||
y * shapeSize.y
|
||||
);
|
||||
|
||||
this.target = this.pos.clone();
|
||||
this.pos.x = width / 2;
|
||||
this.pos.y = height / 2;
|
||||
this.accel = Vector.coerce(this.accel);
|
||||
this.vel = Vector.coerce(this.vel);
|
||||
this.pos.x = shapeSize.x / 2;
|
||||
this.pos.y = shapeSize.y / 2;
|
||||
this.accel = Vector.coerce(this.accel);
|
||||
this.vel = Vector.coerce(this.vel);
|
||||
|
||||
this.stiffness = Engine.getRandomFloat(3, 6);
|
||||
this.friction = Engine.getRandomFloat(0.15, 0.3);
|
||||
|
@ -45,6 +53,27 @@ Engine.Point.prototype = {
|
|||
y: 0
|
||||
},
|
||||
|
||||
updateBreathingPhysics: function(){
|
||||
this.stiffness = 0.1;
|
||||
this.friction = 0.05;
|
||||
},
|
||||
|
||||
updateTarget: function(newSize){
|
||||
var diff;
|
||||
|
||||
this.target.x = this.ref.x * newSize.x;
|
||||
this.target.y = this.ref.y * newSize.y;
|
||||
|
||||
diff = Vector.sub(newSize, this.shapeSize).div(2);
|
||||
|
||||
this.target.sub(diff);
|
||||
|
||||
this.target.add({
|
||||
x: Engine.getRandomFloat(-8, 8),
|
||||
y: Engine.getRandomFloat(-8, 8)
|
||||
});
|
||||
},
|
||||
|
||||
update: function(engine){
|
||||
var newAccel;
|
||||
|
||||
|
|
|
@ -5,11 +5,12 @@
|
|||
Vector
|
||||
){
|
||||
|
||||
Engine.Shape = function(x, y, width, height, points, polygons, simple){
|
||||
Engine.Shape = function(x, y, width, height, points, polygons){
|
||||
var i, ref, point, poly;
|
||||
|
||||
this.pos = new Vector(x, y);
|
||||
this.pos = new Vector(x, y);
|
||||
this.size = new Vector(width, height);
|
||||
this.sizeRef = this.size.clone();
|
||||
|
||||
ref = {};
|
||||
this.points = [];
|
||||
|
@ -18,10 +19,9 @@ Engine.Shape = function(x, y, width, height, points, polygons, simple){
|
|||
for (i = 0; i < points.length; i++) {
|
||||
point = new Point(
|
||||
points[i].id,
|
||||
points[i].x * this.size.x,
|
||||
points[i].y * this.size.y,
|
||||
this.size.x,
|
||||
this.size.y
|
||||
points[i].x,
|
||||
points[i].y,
|
||||
this.size
|
||||
);
|
||||
ref[point.id] = point;
|
||||
this.points.push(point);
|
||||
|
@ -33,17 +33,63 @@ Engine.Shape = function(x, y, width, height, points, polygons, simple){
|
|||
ref[poly.points[0]],
|
||||
ref[poly.points[1]],
|
||||
ref[poly.points[2]],
|
||||
poly.color,
|
||||
simple
|
||||
poly.color
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
Engine.Shape.prototype = {
|
||||
|
||||
breathing: false,
|
||||
|
||||
breath: 0,
|
||||
breathLength: 1,
|
||||
breatheIn: false,
|
||||
|
||||
startBreathing: function(){
|
||||
var p;
|
||||
|
||||
this.breathing = true;
|
||||
this.breath = this.breathLength;
|
||||
|
||||
for (p = 0; p < this.points.length; p++) {
|
||||
this.points[p].updateBreathingPhysics();
|
||||
}
|
||||
},
|
||||
|
||||
breathe: function(tick){
|
||||
var p, scale, newSize;
|
||||
|
||||
this.breath += tick;
|
||||
|
||||
if (this.breath < this.breathLength) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.breatheIn) {
|
||||
scale = 1;
|
||||
} else {
|
||||
scale = 1.05;
|
||||
}
|
||||
|
||||
this.breatheIn = !this.breatheIn;
|
||||
|
||||
newSize = Vector.mult(this.sizeRef, scale);
|
||||
|
||||
for (p = 0; p < this.points.length; p++) {
|
||||
this.points[p].updateTarget(newSize);
|
||||
}
|
||||
|
||||
this.breath = 0;
|
||||
},
|
||||
|
||||
update: function(engine){
|
||||
var p;
|
||||
|
||||
if (this.breathing === true) {
|
||||
this.breathe(engine.tick);
|
||||
}
|
||||
|
||||
for (p = 0; p < this.points.length; p++) {
|
||||
this.points[p].update(engine);
|
||||
}
|
||||
|
|
|
@ -6,8 +6,6 @@ Engine.Typewriter = function(element){
|
|||
this.element = element;
|
||||
this.content = this.element.textContent.split('');
|
||||
this.element.innerHTML = '';
|
||||
|
||||
console.dir(this);
|
||||
};
|
||||
|
||||
Engine.Typewriter.prototype = {
|
||||
|
|
|
@ -97,6 +97,7 @@ Engine = Base.extend({
|
|||
.wait(1000)
|
||||
.then(function(){
|
||||
this.showGrid = true;
|
||||
this.logo.startBreathing();
|
||||
}, this)
|
||||
.wait(1000)
|
||||
.then(function(){
|
||||
|
|
Loading…
Reference in New Issue