This repository has been archived on 2022-12-05. You can view files and clone it, but cannot push or open issues or pull requests.
GeometryDash3D/js/utils.js
2022-11-24 17:34:00 +01:00

67 lines
1.5 KiB
JavaScript

export const textureGradient = (width, height, color1, color2) => {
const cnv = document.createElement("canvas");
const ctx = cnv.getContext("2d");
ctx.rect(0, 0, cnv.width, cnv.height);
const gradient = ctx.createLinearGradient(0, 0, width / 4, 15 * height);
gradient.addColorStop(0, color1);
gradient.addColorStop(1, color2);
ctx.fillStyle = gradient;
ctx.fill();
const texture = new THREE.Texture(cnv);
texture.needsUpdate = true;
return texture;
};
export class Rotation {
constructor(position) {
this.default = position.clone();
this.state = false;
this.rotation = 0;
this.jump = 0;
this.rotationVelocity = 0.03;
this.jumpVelocity = 0.06;
this.lastJump = 0;
}
/**
* Change the state of the animation and update the latest jump time
* @param {number} time
*/
changeState = (time) => {
this.state = !this.state;
if (time) {
this.lastJump = time;
}
};
/**
* Change the final rotation
* @param {number} rotation
*/
changeRotation = (rotation) => {
this.rotation = rotation;
};
/**
* Change the final position
* @param {number} jump
*/
changeJump = (jump) => {
this.jump = jump;
};
/**
* Return the state of the jump
* @returns boolean representing if the object is going up or down
*/
falling = () => {
return this.jump == this.default.y;
};
}