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

126 lines
2.8 KiB
JavaScript
Raw Permalink Normal View History

2022-11-22 10:40:56 +01:00
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;
}
/**
2022-12-02 14:29:12 +01:00
* Change the state of the animation
*/
2022-12-02 14:29:12 +01:00
changeState = () => {
this.state = !this.state;
};
/**
* 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;
};
}
2022-11-24 19:45:20 +01:00
export class Quality {
static ultra = 1;
static medium = 2;
static low = 3;
/**
* Build an object of the settings panel
* @param {Quality} defaultValue Default quality
* @returns An object for dat.gui
*/
static buildGUI = (defaultValue) => {
const res = {
Ultra: false,
2022-12-01 22:28:14 +01:00
Medium: false,
Low: false,
2022-11-24 19:45:20 +01:00
};
// Update the default value to true
switch (defaultValue) {
2022-12-01 22:28:14 +01:00
case this.ultra:
res.Ultra = true;
2022-11-24 19:45:20 +01:00
break;
case this.medium:
res.Medium = true;
break;
2022-12-01 22:28:14 +01:00
case this.low:
res.Low = true;
2022-11-24 19:45:20 +01:00
break;
}
// Return the object
return res;
};
/**
* Update the quality of the renderer
* @param {property} fnQuality
* @param {{string: boolean}} menu
* @param {string} quality
*/
static update = (fnQuality, menu, quality) => {
// All the field to false
for (const field in menu) {
menu[field] = false;
}
// The select field to true
menu[quality] = true;
// Update the quality
switch (quality) {
2022-12-01 22:28:14 +01:00
case "Ultra":
fnQuality(this.ultra);
2022-11-24 19:45:20 +01:00
break;
case "Medium":
fnQuality(this.medium);
break;
2022-12-01 22:28:14 +01:00
case "Low":
fnQuality(this.low);
2022-11-24 19:45:20 +01:00
break;
}
};
}