html5卡片平行视差效果,HTML5/Canvas平行视差的多层星光

HTML

导入代码模板:

this.x = x || 0;

this.y = y || 0;

return this;

};

Vector2.prototype.add = function(vector){

this.x += vector.x;

this.y += vector.y;

return this;

};

Vector2.prototype.sub = function(vector){

this.x -= vector.x;

this.y -= vector.y;

return this;

};

Vector2.prototype.mult = function(a){

if(typeof a == "object"){

this.x *= a.x;

this.y *= a.y;

} else if (typeof a == "number"){

this.x *= a;

this.y *= a;

}

return this;

};

Vector2.prototype.norm = function(){

var mag = this.mag()

this.x /= mag;

this.y /= mag;

return this;

};

Vector2.prototype.setMag = function(e){

this.normalize();

this.mult(e);

return this;

};

Vector2.prototype.direction = function(e){

return Math.atan2(this.y, this.x);

};

Vector2.prototype.rotate = function(e){

var newDirection = this.direction() + e,

mag = this.mag();

this.x = Math.cos(newDirection) * mag;

this.y = Math.sin(newDirection) * mag;

return this;

};

Vector2.prototype.mag = function(){

return Math.sqrt((this.x*this.x) + (this.y*this.y));

};

Vector2.prototype.angleTo = function(vector){

var angle = Math.atan2(vector.x - this.x, vector.y - this.y);

return angle;

};

Vector2.prototype.distanceTo = function(vector){

return Math.sqrt(Math.pow(vector.x - this.x, 2) + Math.pow(vector.y - this.y, 2));

};

Vector2.prototype.copy = function(){

return new Vector2(this.x, this.y);

};

Vector2.prototype.set = function(){

var args = arguments

if(args.length == 1){

if(typeof args[0] == "object"){

this.x = args[0].x;

this.y = args[0].y;

} else if (typeof args[0] == "number"){

this.x = args[0];

this.y = args[0];

}

} else if (args.length == 2){

this.x = args[0];

this.y = args[1];

}

return this;

};

Vector2.prototype.map = function(vXmin, vXmax, vYmin, vYmax){

if(vXmin < this.x < vXmax && vYmin < this.y < vYmax){

return this;

}

this.x < vXmin ? this.x = vXmin : this;

this.x > vXmax ? this.x = vXmax : this;

this.y < vYmin ? this.y = vYmin : this;

this.y > vYmax ? this.y = vYmax : this;

};

Math.radians = function(deg){

return deg * (Math.PI / 180);

};

Math.degrees = function(rad){

return rad * (180 / Math.PI);

};

random = function(){

if(arguments){

var arg = arguments;

if(arg.length == 1){

return Math.random()*arg[0];

}

if(arg.length == 2){

return Math.random()*( Math.max(arg[0], arg[1])-(Math.min(arg[0], arg[1])) )+Math.min(arg[0], arg[1]);

}

} else {

return Math.random();

}

};

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值