don't log theme with randomTheme
This commit is contained in:
191
src/API.ts
191
src/API.ts
@ -121,7 +121,7 @@ export class UserAPI {
|
|||||||
public currentSeed: string | undefined = undefined;
|
public currentSeed: string | undefined = undefined;
|
||||||
public localSeeds = new Map<string, Function>();
|
public localSeeds = new Map<string, Function>();
|
||||||
public patternCache = new LRUCache({ max: 10000, ttl: 10000 * 60 * 5 });
|
public patternCache = new LRUCache({ max: 10000, ttl: 10000 * 60 * 5 });
|
||||||
public invalidPatterns: {[key: string]: boolean} = {};
|
public invalidPatterns: { [key: string]: boolean } = {};
|
||||||
public cueTimes: { [key: string]: number } = {};
|
public cueTimes: { [key: string]: number } = {};
|
||||||
private errorTimeoutID: number = 0;
|
private errorTimeoutID: number = 0;
|
||||||
private printTimeoutID: number = 0;
|
private printTimeoutID: number = 0;
|
||||||
@ -757,9 +757,9 @@ export class UserAPI {
|
|||||||
this.patternCache.delete(id);
|
this.patternCache.delete(id);
|
||||||
};
|
};
|
||||||
|
|
||||||
maybeToNumber = (something: any): number|any => {
|
maybeToNumber = (something: any): number | any => {
|
||||||
// If something is BigInt
|
// If something is BigInt
|
||||||
if(typeof something === "bigint") {
|
if (typeof something === "bigint") {
|
||||||
return Number(something);
|
return Number(something);
|
||||||
} else {
|
} else {
|
||||||
return something;
|
return something;
|
||||||
@ -774,11 +774,11 @@ export class UserAPI {
|
|||||||
* @param value - The value to set
|
* @param value - The value to set
|
||||||
* @returns The value of the key
|
* @returns The value of the key
|
||||||
*/
|
*/
|
||||||
if(value !== undefined) {
|
if (value !== undefined) {
|
||||||
if(isGenerator(value)) {
|
if (isGenerator(value)) {
|
||||||
if(this.patternCache.has(key)) {
|
if (this.patternCache.has(key)) {
|
||||||
const cachedValue = (this.patternCache.get(key) as Generator<any>).next().value
|
const cachedValue = (this.patternCache.get(key) as Generator<any>).next().value
|
||||||
if(cachedValue!==0 && !cachedValue) {
|
if (cachedValue !== 0 && !cachedValue) {
|
||||||
const generator = value as unknown as Generator<any>
|
const generator = value as unknown as Generator<any>
|
||||||
this.patternCache.set(key, generator);
|
this.patternCache.set(key, generator);
|
||||||
return this.maybeToNumber(generator.next().value);
|
return this.maybeToNumber(generator.next().value);
|
||||||
@ -789,10 +789,10 @@ export class UserAPI {
|
|||||||
this.patternCache.set(key, generator);
|
this.patternCache.set(key, generator);
|
||||||
return this.maybeToNumber(generator.next().value);
|
return this.maybeToNumber(generator.next().value);
|
||||||
}
|
}
|
||||||
} else if(isGeneratorFunction(value)) {
|
} else if (isGeneratorFunction(value)) {
|
||||||
if(this.patternCache.has(key)) {
|
if (this.patternCache.has(key)) {
|
||||||
const cachedValue = (this.patternCache.get(key) as Generator<any>).next().value;
|
const cachedValue = (this.patternCache.get(key) as Generator<any>).next().value;
|
||||||
if(cachedValue || cachedValue===0 || cachedValue===0n) {
|
if (cachedValue || cachedValue === 0 || cachedValue === 0n) {
|
||||||
return this.maybeToNumber(cachedValue);
|
return this.maybeToNumber(cachedValue);
|
||||||
} else {
|
} else {
|
||||||
const generator = value();
|
const generator = value();
|
||||||
@ -842,18 +842,18 @@ export class UserAPI {
|
|||||||
|
|
||||||
if ((typeof input !== "string" || validSyntax) && (!player || replace)) {
|
if ((typeof input !== "string" || validSyntax) && (!player || replace)) {
|
||||||
const newPlayer = new Player(input, options, this.app, zid);
|
const newPlayer = new Player(input, options, this.app, zid);
|
||||||
if(newPlayer.isValid()) {
|
if (newPlayer.isValid()) {
|
||||||
player = newPlayer
|
player = newPlayer
|
||||||
this.patternCache.set(key, player);
|
this.patternCache.set(key, player);
|
||||||
} else if(typeof input === "string") {
|
} else if (typeof input === "string") {
|
||||||
this.invalidPatterns[input] = true;
|
this.invalidPatterns[input] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(player) {
|
if (player) {
|
||||||
|
|
||||||
if(player.atTheBeginning()) {
|
if (player.atTheBeginning()) {
|
||||||
if(typeof input === "string" && !validSyntax) this.app.api.log(`Invalid syntax: ${input}`);
|
if (typeof input === "string" && !validSyntax) this.app.api.log(`Invalid syntax: ${input}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player.ziffers.generator && player.ziffers.generatorDone) {
|
if (player.ziffers.generator && player.ziffers.generatorDone) {
|
||||||
@ -1394,7 +1394,7 @@ export class UserAPI {
|
|||||||
/**
|
/**
|
||||||
* Returns the number of pulses in a given bar
|
* Returns the number of pulses in a given bar
|
||||||
*/
|
*/
|
||||||
return (this.tempo()*this.ppqn()*this.nominator())/60;
|
return (this.tempo() * this.ppqn() * this.nominator()) / 60;
|
||||||
}
|
}
|
||||||
|
|
||||||
// =============================================================
|
// =============================================================
|
||||||
@ -2061,7 +2061,7 @@ export class UserAPI {
|
|||||||
// =============================================================
|
// =============================================================
|
||||||
|
|
||||||
register = (name: string, operation: EventOperation<AbstractEvent>): void => {
|
register = (name: string, operation: EventOperation<AbstractEvent>): void => {
|
||||||
AbstractEvent.prototype[name] = function (
|
AbstractEvent.prototype[name] = function(
|
||||||
this: AbstractEvent,
|
this: AbstractEvent,
|
||||||
...args: any[]
|
...args: any[]
|
||||||
) {
|
) {
|
||||||
@ -2249,7 +2249,7 @@ export class UserAPI {
|
|||||||
* Returns the current pulse location in the current bar.
|
* Returns the current pulse location in the current bar.
|
||||||
* @returns The current pulse location in the current bar
|
* @returns The current pulse location in the current bar
|
||||||
*/
|
*/
|
||||||
return ((this.epulse() / this.pulsesForBar())*this.w())%this.w()
|
return ((this.epulse() / this.pulsesForBar()) * this.w()) % this.w()
|
||||||
}
|
}
|
||||||
|
|
||||||
public clear = (): boolean => {
|
public clear = (): boolean => {
|
||||||
@ -2297,21 +2297,21 @@ export class UserAPI {
|
|||||||
return this.w() / 2;
|
return this.w() / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public background = (color: string|number, ...gb:number[]): boolean => {
|
public background = (color: string | number, ...gb: number[]): boolean => {
|
||||||
/**
|
/**
|
||||||
* Set background color of the canvas.
|
* Set background color of the canvas.
|
||||||
* @param color - The color to set. String or 3 numbers representing RGB values.
|
* @param color - The color to set. String or 3 numbers representing RGB values.
|
||||||
*/
|
*/
|
||||||
const canvas: HTMLCanvasElement = this.app.interface.drawings as HTMLCanvasElement;
|
const canvas: HTMLCanvasElement = this.app.interface.drawings as HTMLCanvasElement;
|
||||||
const ctx = canvas.getContext("2d")!;
|
const ctx = canvas.getContext("2d")!;
|
||||||
if(typeof color === "number") color = `rgb(${color},${gb[0]},${gb[1]})`;
|
if (typeof color === "number") color = `rgb(${color},${gb[0]},${gb[1]})`;
|
||||||
ctx.fillStyle = color;
|
ctx.fillStyle = color;
|
||||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bg = this.background;
|
bg = this.background;
|
||||||
|
|
||||||
public linearGradient = (x1: number, y1: number, x2: number, y2: number, ...stops: (number|string)[]) => {
|
public linearGradient = (x1: number, y1: number, x2: number, y2: number, ...stops: (number | string)[]) => {
|
||||||
/**
|
/**
|
||||||
* Set linear gradient on the canvas.
|
* Set linear gradient on the canvas.
|
||||||
* @param x1 - The x-coordinate of the start point
|
* @param x1 - The x-coordinate of the start point
|
||||||
@ -2324,15 +2324,15 @@ export class UserAPI {
|
|||||||
const ctx = canvas.getContext("2d")!;
|
const ctx = canvas.getContext("2d")!;
|
||||||
const gradient = ctx.createLinearGradient(x1, y1, x2, y2);
|
const gradient = ctx.createLinearGradient(x1, y1, x2, y2);
|
||||||
// Parse pairs of values from stops
|
// Parse pairs of values from stops
|
||||||
for(let i=0; i<stops.length; i+=2) {
|
for (let i = 0; i < stops.length; i += 2) {
|
||||||
let color = stops[i+1];
|
let color = stops[i + 1];
|
||||||
if(typeof color === "number") color = `rgb(${color},${stops[i+2]},${stops[i+3]})`;
|
if (typeof color === "number") color = `rgb(${color},${stops[i + 2]},${stops[i + 3]})`;
|
||||||
gradient.addColorStop((stops[i] as number), color);
|
gradient.addColorStop((stops[i] as number), color);
|
||||||
}
|
}
|
||||||
return gradient;
|
return gradient;
|
||||||
}
|
}
|
||||||
|
|
||||||
public radialGradient = (x1: number, y1: number, r1: number, x2: number, y2: number, r2: number, ...stops: (number|string)[]) => {
|
public radialGradient = (x1: number, y1: number, r1: number, x2: number, y2: number, r2: number, ...stops: (number | string)[]) => {
|
||||||
/**
|
/**
|
||||||
* Set radial gradient on the canvas.
|
* Set radial gradient on the canvas.
|
||||||
* @param x1 - The x-coordinate of the start circle
|
* @param x1 - The x-coordinate of the start circle
|
||||||
@ -2346,15 +2346,15 @@ export class UserAPI {
|
|||||||
const canvas: HTMLCanvasElement = this.app.interface.drawings as HTMLCanvasElement;
|
const canvas: HTMLCanvasElement = this.app.interface.drawings as HTMLCanvasElement;
|
||||||
const ctx = canvas.getContext("2d")!;
|
const ctx = canvas.getContext("2d")!;
|
||||||
const gradient = ctx.createRadialGradient(x1, y1, r1, x2, y2, r2);
|
const gradient = ctx.createRadialGradient(x1, y1, r1, x2, y2, r2);
|
||||||
for(let i=0; i<stops.length; i+=2) {
|
for (let i = 0; i < stops.length; i += 2) {
|
||||||
let color = stops[i+1];
|
let color = stops[i + 1];
|
||||||
if(typeof color === "number") color = `rgb(${color},${stops[i+2]},${stops[i+3]})`;
|
if (typeof color === "number") color = `rgb(${color},${stops[i + 2]},${stops[i + 3]})`;
|
||||||
gradient.addColorStop((stops[i] as number), color);
|
gradient.addColorStop((stops[i] as number), color);
|
||||||
}
|
}
|
||||||
return gradient;
|
return gradient;
|
||||||
}
|
}
|
||||||
|
|
||||||
public conicGradient = (x: number, y: number, angle: number, ...stops: (number|string)[]) => {
|
public conicGradient = (x: number, y: number, angle: number, ...stops: (number | string)[]) => {
|
||||||
/**
|
/**
|
||||||
* Set conic gradient on the canvas.
|
* Set conic gradient on the canvas.
|
||||||
* @param x - The x-coordinate of the center of the gradient
|
* @param x - The x-coordinate of the center of the gradient
|
||||||
@ -2365,9 +2365,9 @@ export class UserAPI {
|
|||||||
const canvas: HTMLCanvasElement = this.app.interface.drawings as HTMLCanvasElement;
|
const canvas: HTMLCanvasElement = this.app.interface.drawings as HTMLCanvasElement;
|
||||||
const ctx = canvas.getContext("2d")!;
|
const ctx = canvas.getContext("2d")!;
|
||||||
const gradient = ctx.createConicGradient(x, y, angle);
|
const gradient = ctx.createConicGradient(x, y, angle);
|
||||||
for(let i=0; i<stops.length; i+=2) {
|
for (let i = 0; i < stops.length; i += 2) {
|
||||||
let color = stops[i+1];
|
let color = stops[i + 1];
|
||||||
if(typeof color === "number") color = `rgb(${color},${stops[i+2]},${stops[i+3]})`;
|
if (typeof color === "number") color = `rgb(${color},${stops[i + 2]},${stops[i + 3]})`;
|
||||||
gradient.addColorStop((stops[i] as number), color);
|
gradient.addColorStop((stops[i] as number), color);
|
||||||
}
|
}
|
||||||
return gradient;
|
return gradient;
|
||||||
@ -2378,8 +2378,8 @@ export class UserAPI {
|
|||||||
* Draws on the canvas.
|
* Draws on the canvas.
|
||||||
* @param func - The function to execute
|
* @param func - The function to execute
|
||||||
*/
|
*/
|
||||||
if(typeof func === "string") {
|
if (typeof func === "string") {
|
||||||
this.drawText (func);
|
this.drawText(func);
|
||||||
} else {
|
} else {
|
||||||
const canvas: HTMLCanvasElement = this.app.interface.drawings as HTMLCanvasElement;
|
const canvas: HTMLCanvasElement = this.app.interface.drawings as HTMLCanvasElement;
|
||||||
const ctx = canvas.getContext("2d")!;
|
const ctx = canvas.getContext("2d")!;
|
||||||
@ -2389,20 +2389,20 @@ export class UserAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public balloid = (
|
public balloid = (
|
||||||
curves: number|ShapeObject = 6,
|
curves: number | ShapeObject = 6,
|
||||||
radius: number = this.hc()/2,
|
radius: number = this.hc() / 2,
|
||||||
curve: number = 1.5,
|
curve: number = 1.5,
|
||||||
fillStyle: string = "white",
|
fillStyle: string = "white",
|
||||||
secondary: string = "black",
|
secondary: string = "black",
|
||||||
x: number = this.wc(),
|
x: number = this.wc(),
|
||||||
y: number = this.hc(),
|
y: number = this.hc(),
|
||||||
): boolean => {
|
): boolean => {
|
||||||
if(typeof curves === "object") {
|
if (typeof curves === "object") {
|
||||||
fillStyle = curves.fillStyle || "white";
|
fillStyle = curves.fillStyle || "white";
|
||||||
x = curves.x || this.wc();
|
x = curves.x || this.wc();
|
||||||
y = curves.y || this.hc();
|
y = curves.y || this.hc();
|
||||||
curve = curves.curve || 1.5;
|
curve = curves.curve || 1.5;
|
||||||
radius = curves.radius || this.hc()/2;
|
radius = curves.radius || this.hc() / 2;
|
||||||
curves = curves.curves || 6;
|
curves = curves.curves || 6;
|
||||||
}
|
}
|
||||||
const canvas: HTMLCanvasElement = this.app.interface.drawings as HTMLCanvasElement;
|
const canvas: HTMLCanvasElement = this.app.interface.drawings as HTMLCanvasElement;
|
||||||
@ -2419,7 +2419,7 @@ export class UserAPI {
|
|||||||
ctx.fill();
|
ctx.fill();
|
||||||
} else if (curves === 1) {
|
} else if (curves === 1) {
|
||||||
// Draw a single curve (ellipse) if curves = 1
|
// Draw a single curve (ellipse) if curves = 1
|
||||||
ctx.ellipse(x, y, radius*0.8, (radius* curve)*0.7, 0, 0, 2 * Math.PI);
|
ctx.ellipse(x, y, radius * 0.8, (radius * curve) * 0.7, 0, 0, 2 * Math.PI);
|
||||||
ctx.closePath();
|
ctx.closePath();
|
||||||
ctx.fill();
|
ctx.fill();
|
||||||
} else if (curves === 2) {
|
} else if (curves === 2) {
|
||||||
@ -2456,7 +2456,7 @@ export class UserAPI {
|
|||||||
ctx.fillStyle = secondary;
|
ctx.fillStyle = secondary;
|
||||||
// Form the shape from points with straight lines and fill it
|
// Form the shape from points with straight lines and fill it
|
||||||
ctx.moveTo(points[0][0], points[0][1]);
|
ctx.moveTo(points[0][0], points[0][1]);
|
||||||
for(let point of points) ctx.lineTo(point[0], point[1]);
|
for (let point of points) ctx.lineTo(point[0], point[1]);
|
||||||
// Close and fill
|
// Close and fill
|
||||||
|
|
||||||
ctx.closePath();
|
ctx.closePath();
|
||||||
@ -2466,18 +2466,18 @@ export class UserAPI {
|
|||||||
};
|
};
|
||||||
|
|
||||||
public equilateral = (
|
public equilateral = (
|
||||||
radius: number|ShapeObject = this.hc()/3,
|
radius: number | ShapeObject = this.hc() / 3,
|
||||||
fillStyle: string = "white",
|
fillStyle: string = "white",
|
||||||
rotation: number = 0,
|
rotation: number = 0,
|
||||||
x: number = this.wc(),
|
x: number = this.wc(),
|
||||||
y: number = this.hc(),
|
y: number = this.hc(),
|
||||||
): boolean => {
|
): boolean => {
|
||||||
if(typeof radius === "object") {
|
if (typeof radius === "object") {
|
||||||
fillStyle = radius.fillStyle || "white";
|
fillStyle = radius.fillStyle || "white";
|
||||||
x = radius.x || this.wc();
|
x = radius.x || this.wc();
|
||||||
y = radius.y || this.hc();
|
y = radius.y || this.hc();
|
||||||
rotation = radius.rotation || 0;
|
rotation = radius.rotation || 0;
|
||||||
radius = radius.radius || this.hc()/3;
|
radius = radius.radius || this.hc() / 3;
|
||||||
}
|
}
|
||||||
const canvas: HTMLCanvasElement = this.app.interface.drawings as HTMLCanvasElement;
|
const canvas: HTMLCanvasElement = this.app.interface.drawings as HTMLCanvasElement;
|
||||||
const ctx = canvas.getContext("2d")!;
|
const ctx = canvas.getContext("2d")!;
|
||||||
@ -2496,20 +2496,20 @@ export class UserAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public triangular = (
|
public triangular = (
|
||||||
width: number|ShapeObject = this.hc()/3,
|
width: number | ShapeObject = this.hc() / 3,
|
||||||
height: number = this.hc()/3,
|
height: number = this.hc() / 3,
|
||||||
fillStyle: string = "white",
|
fillStyle: string = "white",
|
||||||
rotation: number = 0,
|
rotation: number = 0,
|
||||||
x: number = this.wc(),
|
x: number = this.wc(),
|
||||||
y: number = this.hc(),
|
y: number = this.hc(),
|
||||||
): boolean => {
|
): boolean => {
|
||||||
if(typeof width === "object") {
|
if (typeof width === "object") {
|
||||||
fillStyle = width.fillStyle || "white";
|
fillStyle = width.fillStyle || "white";
|
||||||
x = width.x || this.wc();
|
x = width.x || this.wc();
|
||||||
y = width.y || this.hc();
|
y = width.y || this.hc();
|
||||||
rotation = width.rotation || 0;
|
rotation = width.rotation || 0;
|
||||||
height = width.height || this.hc()/3;
|
height = width.height || this.hc() / 3;
|
||||||
width = width.width || this.hc()/3;
|
width = width.width || this.hc() / 3;
|
||||||
}
|
}
|
||||||
const canvas: HTMLCanvasElement = this.app.interface.drawings as HTMLCanvasElement;
|
const canvas: HTMLCanvasElement = this.app.interface.drawings as HTMLCanvasElement;
|
||||||
const ctx = canvas.getContext("2d")!;
|
const ctx = canvas.getContext("2d")!;
|
||||||
@ -2529,16 +2529,16 @@ export class UserAPI {
|
|||||||
pointy = this.triangular;
|
pointy = this.triangular;
|
||||||
|
|
||||||
public ball = (
|
public ball = (
|
||||||
radius: number|ShapeObject = this.hc()/3,
|
radius: number | ShapeObject = this.hc() / 3,
|
||||||
fillStyle: string = "white",
|
fillStyle: string = "white",
|
||||||
x: number = this.wc(),
|
x: number = this.wc(),
|
||||||
y: number = this.hc(),
|
y: number = this.hc(),
|
||||||
): boolean => {
|
): boolean => {
|
||||||
if(typeof radius === "object") {
|
if (typeof radius === "object") {
|
||||||
fillStyle = radius.fillStyle || "white";
|
fillStyle = radius.fillStyle || "white";
|
||||||
x = radius.x || this.wc();
|
x = radius.x || this.wc();
|
||||||
y = radius.y || this.hc();
|
y = radius.y || this.hc();
|
||||||
radius = radius.radius || this.hc()/3;
|
radius = radius.radius || this.hc() / 3;
|
||||||
}
|
}
|
||||||
const canvas: HTMLCanvasElement = this.app.interface.drawings as HTMLCanvasElement;
|
const canvas: HTMLCanvasElement = this.app.interface.drawings as HTMLCanvasElement;
|
||||||
const ctx = canvas.getContext("2d")!;
|
const ctx = canvas.getContext("2d")!;
|
||||||
@ -2582,11 +2582,11 @@ export class UserAPI {
|
|||||||
ctx.translate(x, y);
|
ctx.translate(x, y);
|
||||||
ctx.rotate((rotation * Math.PI) / 180);
|
ctx.rotate((rotation * Math.PI) / 180);
|
||||||
|
|
||||||
if(slices<2) {
|
if (slices < 2) {
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
ctx.arc(0, 0, radius, 0, 2 * Math.PI);
|
ctx.arc(0, 0, radius, 0, 2 * Math.PI);
|
||||||
ctx.closePath();
|
ctx.closePath();
|
||||||
ctx.fillStyle = slices<1 ? secondary : fillStyle;
|
ctx.fillStyle = slices < 1 ? secondary : fillStyle;
|
||||||
ctx.fill();
|
ctx.fill();
|
||||||
|
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
@ -2636,7 +2636,7 @@ export class UserAPI {
|
|||||||
|
|
||||||
|
|
||||||
public pie = (
|
public pie = (
|
||||||
slices: number|ShapeObject = 3,
|
slices: number | ShapeObject = 3,
|
||||||
eaten: number = 0,
|
eaten: number = 0,
|
||||||
radius: number = this.hc() / 3,
|
radius: number = this.hc() / 3,
|
||||||
fillStyle: string = "white",
|
fillStyle: string = "white",
|
||||||
@ -2664,11 +2664,11 @@ export class UserAPI {
|
|||||||
ctx.translate(x, y);
|
ctx.translate(x, y);
|
||||||
ctx.rotate((rotation * Math.PI) / 180);
|
ctx.rotate((rotation * Math.PI) / 180);
|
||||||
|
|
||||||
if(slices<2) {
|
if (slices < 2) {
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
ctx.arc(0, 0, radius, 0, 2 * Math.PI);
|
ctx.arc(0, 0, radius, 0, 2 * Math.PI);
|
||||||
ctx.closePath();
|
ctx.closePath();
|
||||||
ctx.fillStyle = slices<1 ? secondary : fillStyle;
|
ctx.fillStyle = slices < 1 ? secondary : fillStyle;
|
||||||
ctx.fill();
|
ctx.fill();
|
||||||
ctx.restore();
|
ctx.restore();
|
||||||
return true;
|
return true;
|
||||||
@ -2707,26 +2707,26 @@ export class UserAPI {
|
|||||||
|
|
||||||
|
|
||||||
public star = (
|
public star = (
|
||||||
points: number|ShapeObject = 5,
|
points: number | ShapeObject = 5,
|
||||||
radius: number = this.hc()/3,
|
radius: number = this.hc() / 3,
|
||||||
fillStyle: string = "white",
|
fillStyle: string = "white",
|
||||||
rotation: number = 0,
|
rotation: number = 0,
|
||||||
outerRadius: number = radius/100,
|
outerRadius: number = radius / 100,
|
||||||
x: number = this.wc(),
|
x: number = this.wc(),
|
||||||
y: number = this.hc(),
|
y: number = this.hc(),
|
||||||
): boolean => {
|
): boolean => {
|
||||||
if(typeof points === "object") {
|
if (typeof points === "object") {
|
||||||
radius = points.radius || this.hc()/3;
|
radius = points.radius || this.hc() / 3;
|
||||||
fillStyle = points.fillStyle || "white";
|
fillStyle = points.fillStyle || "white";
|
||||||
x = points.x || this.wc();
|
x = points.x || this.wc();
|
||||||
y = points.y || this.hc();
|
y = points.y || this.hc();
|
||||||
rotation = points.rotation || 0;
|
rotation = points.rotation || 0;
|
||||||
outerRadius = points.outerRadius || radius/100;
|
outerRadius = points.outerRadius || radius / 100;
|
||||||
points = points.points || 5;
|
points = points.points || 5;
|
||||||
}
|
}
|
||||||
const canvas: HTMLCanvasElement = this.app.interface.drawings as HTMLCanvasElement;
|
const canvas: HTMLCanvasElement = this.app.interface.drawings as HTMLCanvasElement;
|
||||||
if(points<1) return this.ball(radius, fillStyle, x, y);
|
if (points < 1) return this.ball(radius, fillStyle, x, y);
|
||||||
if(points==1) return this.equilateral(radius, fillStyle, 0, x, y);
|
if (points == 1) return this.equilateral(radius, fillStyle, 0, x, y);
|
||||||
const ctx = canvas.getContext("2d")!;
|
const ctx = canvas.getContext("2d")!;
|
||||||
ctx.save();
|
ctx.save();
|
||||||
ctx.translate(x, y);
|
ctx.translate(x, y);
|
||||||
@ -2747,19 +2747,19 @@ export class UserAPI {
|
|||||||
};
|
};
|
||||||
|
|
||||||
public stroke = (
|
public stroke = (
|
||||||
width: number|ShapeObject = 1,
|
width: number | ShapeObject = 1,
|
||||||
strokeStyle: string = "white",
|
strokeStyle: string = "white",
|
||||||
rotation: number = 0,
|
rotation: number = 0,
|
||||||
x1: number = this.wc()-this.wc()/10,
|
x1: number = this.wc() - this.wc() / 10,
|
||||||
y1: number = this.hc(),
|
y1: number = this.hc(),
|
||||||
x2: number = this.wc()+this.wc()/5,
|
x2: number = this.wc() + this.wc() / 5,
|
||||||
y2: number = this.hc(),
|
y2: number = this.hc(),
|
||||||
): boolean => {
|
): boolean => {
|
||||||
if(typeof width === "object") {
|
if (typeof width === "object") {
|
||||||
strokeStyle = width.strokeStyle || "white";
|
strokeStyle = width.strokeStyle || "white";
|
||||||
x1 = width.x1 || this.wc()-this.wc()/10;
|
x1 = width.x1 || this.wc() - this.wc() / 10;
|
||||||
y1 = width.y1 || this.hc();
|
y1 = width.y1 || this.hc();
|
||||||
x2 = width.x2 || this.wc()+this.wc()/5;
|
x2 = width.x2 || this.wc() + this.wc() / 5;
|
||||||
y2 = width.y2 || this.hc();
|
y2 = width.y2 || this.hc();
|
||||||
rotation = width.rotation || 0;
|
rotation = width.rotation || 0;
|
||||||
width = width.width || 1;
|
width = width.width || 1;
|
||||||
@ -2771,7 +2771,7 @@ export class UserAPI {
|
|||||||
ctx.rotate((rotation * Math.PI) / 180);
|
ctx.rotate((rotation * Math.PI) / 180);
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
ctx.moveTo(0, 0);
|
ctx.moveTo(0, 0);
|
||||||
ctx.lineTo(x2-x1, y2-y1);
|
ctx.lineTo(x2 - x1, y2 - y1);
|
||||||
ctx.lineWidth = width;
|
ctx.lineWidth = width;
|
||||||
ctx.strokeStyle = strokeStyle;
|
ctx.strokeStyle = strokeStyle;
|
||||||
ctx.stroke();
|
ctx.stroke();
|
||||||
@ -2780,20 +2780,20 @@ export class UserAPI {
|
|||||||
};
|
};
|
||||||
|
|
||||||
public box = (
|
public box = (
|
||||||
width: number|ShapeObject = this.wc()/4,
|
width: number | ShapeObject = this.wc() / 4,
|
||||||
height: number = this.wc()/4,
|
height: number = this.wc() / 4,
|
||||||
fillStyle: string = "white",
|
fillStyle: string = "white",
|
||||||
rotation: number = 0,
|
rotation: number = 0,
|
||||||
x: number = this.wc()-this.wc()/8,
|
x: number = this.wc() - this.wc() / 8,
|
||||||
y: number = this.hc()-this.hc()/8,
|
y: number = this.hc() - this.hc() / 8,
|
||||||
): boolean => {
|
): boolean => {
|
||||||
if(typeof width === "object") {
|
if (typeof width === "object") {
|
||||||
fillStyle = width.fillStyle || "white";
|
fillStyle = width.fillStyle || "white";
|
||||||
x = width.x || this.wc()-this.wc()/4;
|
x = width.x || this.wc() - this.wc() / 4;
|
||||||
y = width.y || this.hc()-this.hc()/2;
|
y = width.y || this.hc() - this.hc() / 2;
|
||||||
rotation = width.rotation || 0;
|
rotation = width.rotation || 0;
|
||||||
height = width.height || this.wc()/4;
|
height = width.height || this.wc() / 4;
|
||||||
width = width.width || this.wc()/4;
|
width = width.width || this.wc() / 4;
|
||||||
}
|
}
|
||||||
const canvas: HTMLCanvasElement = this.app.interface.drawings as HTMLCanvasElement;
|
const canvas: HTMLCanvasElement = this.app.interface.drawings as HTMLCanvasElement;
|
||||||
const ctx = canvas.getContext("2d")!;
|
const ctx = canvas.getContext("2d")!;
|
||||||
@ -2807,27 +2807,27 @@ export class UserAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public smiley = (
|
public smiley = (
|
||||||
happiness: number|ShapeObject = 0,
|
happiness: number | ShapeObject = 0,
|
||||||
radius: number = this.hc()/3,
|
radius: number = this.hc() / 3,
|
||||||
eyeSize: number = 3.0,
|
eyeSize: number = 3.0,
|
||||||
fillStyle: string = "yellow",
|
fillStyle: string = "yellow",
|
||||||
rotation: number = 0,
|
rotation: number = 0,
|
||||||
x: number = this.wc(),
|
x: number = this.wc(),
|
||||||
y: number = this.hc(),
|
y: number = this.hc(),
|
||||||
): boolean => {
|
): boolean => {
|
||||||
if(typeof happiness === "object") {
|
if (typeof happiness === "object") {
|
||||||
fillStyle = happiness.fillStyle || "yellow";
|
fillStyle = happiness.fillStyle || "yellow";
|
||||||
x = happiness.x || this.wc();
|
x = happiness.x || this.wc();
|
||||||
y = happiness.y || this.hc();
|
y = happiness.y || this.hc();
|
||||||
rotation = happiness.rotation || 0;
|
rotation = happiness.rotation || 0;
|
||||||
eyeSize = happiness.eyeSize || 3.0;
|
eyeSize = happiness.eyeSize || 3.0;
|
||||||
radius = happiness.radius || this.hc()/3;
|
radius = happiness.radius || this.hc() / 3;
|
||||||
happiness = happiness.happiness || 0;
|
happiness = happiness.happiness || 0;
|
||||||
}
|
}
|
||||||
const canvas: HTMLCanvasElement = this.app.interface.drawings as HTMLCanvasElement;
|
const canvas: HTMLCanvasElement = this.app.interface.drawings as HTMLCanvasElement;
|
||||||
const ctx = canvas.getContext("2d")!;
|
const ctx = canvas.getContext("2d")!;
|
||||||
// Map the rotation value to an angle within the range of -PI to PI
|
// Map the rotation value to an angle within the range of -PI to PI
|
||||||
const rotationAngle = rotation/100 * Math.PI;
|
const rotationAngle = rotation / 100 * Math.PI;
|
||||||
ctx.save();
|
ctx.save();
|
||||||
ctx.translate(x, y);
|
ctx.translate(x, y);
|
||||||
ctx.rotate(rotationAngle);
|
ctx.rotate(rotationAngle);
|
||||||
@ -2882,7 +2882,7 @@ export class UserAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
drawText = (
|
drawText = (
|
||||||
text: string|ShapeObject,
|
text: string | ShapeObject,
|
||||||
fontSize: number = 24,
|
fontSize: number = 24,
|
||||||
rotation: number = 0,
|
rotation: number = 0,
|
||||||
font: string = "Arial",
|
font: string = "Arial",
|
||||||
@ -2891,7 +2891,7 @@ export class UserAPI {
|
|||||||
fillStyle: string = "white",
|
fillStyle: string = "white",
|
||||||
filter: string = "none",
|
filter: string = "none",
|
||||||
): boolean => {
|
): boolean => {
|
||||||
if(typeof text === "object") {
|
if (typeof text === "object") {
|
||||||
fillStyle = text.fillStyle || "white";
|
fillStyle = text.fillStyle || "white";
|
||||||
x = text.x || this.wc();
|
x = text.x || this.wc();
|
||||||
y = text.y || this.hc();
|
y = text.y || this.hc();
|
||||||
@ -2915,16 +2915,16 @@ export class UserAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
image = (
|
image = (
|
||||||
url: string|ShapeObject,
|
url: string | ShapeObject,
|
||||||
width: number = this.wc()/2,
|
width: number = this.wc() / 2,
|
||||||
height: number = this.hc()/2,
|
height: number = this.hc() / 2,
|
||||||
rotation: number = 0,
|
rotation: number = 0,
|
||||||
x: number = this.wc(),
|
x: number = this.wc(),
|
||||||
y: number = this.hc(),
|
y: number = this.hc(),
|
||||||
filter: string = "none",
|
filter: string = "none",
|
||||||
): boolean => {
|
): boolean => {
|
||||||
if(typeof url === "object") {
|
if (typeof url === "object") {
|
||||||
if(!url.url) return true;
|
if (!url.url) return true;
|
||||||
x = url.x || this.wc();
|
x = url.x || this.wc();
|
||||||
y = url.y || this.hc();
|
y = url.y || this.hc();
|
||||||
rotation = url.rotation || 0;
|
rotation = url.rotation || 0;
|
||||||
@ -2941,12 +2941,12 @@ export class UserAPI {
|
|||||||
ctx.filter = filter;
|
ctx.filter = filter;
|
||||||
const image = new Image();
|
const image = new Image();
|
||||||
image.src = url;
|
image.src = url;
|
||||||
ctx.drawImage(image, -width/2, -height/2, width, height);
|
ctx.drawImage(image, -width / 2, -height / 2, width, height);
|
||||||
ctx.restore();
|
ctx.restore();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
randomChar = (length: number= 1, min: number = 0, max: number = 65536): string => {
|
randomChar = (length: number = 1, min: number = 0, max: number = 65536): string => {
|
||||||
return Array.from(
|
return Array.from(
|
||||||
|
|
||||||
{ length }, () => String.fromCodePoint(Math.floor(Math.random() * (max - min) + min))
|
{ length }, () => String.fromCodePoint(Math.floor(Math.random() * (max - min) + min))
|
||||||
@ -3058,7 +3058,7 @@ export class UserAPI {
|
|||||||
this.app.clock.time_signature = [numerator, denominator];
|
this.app.clock.time_signature = [numerator, denominator];
|
||||||
};
|
};
|
||||||
|
|
||||||
public cue = (functionName: string|Function): void => {
|
public cue = (functionName: string | Function): void => {
|
||||||
functionName = typeof functionName === "function" ? functionName.name : functionName;
|
functionName = typeof functionName === "function" ? functionName.name : functionName;
|
||||||
this.cueTimes[functionName] = this.app.clock.pulses_since_origin;
|
this.cueTimes[functionName] = this.app.clock.pulses_since_origin;
|
||||||
};
|
};
|
||||||
@ -3076,7 +3076,6 @@ export class UserAPI {
|
|||||||
let theme_names = this.getThemes();
|
let theme_names = this.getThemes();
|
||||||
let selected_theme = theme_names[Math.floor(Math.random() * theme_names.length)];
|
let selected_theme = theme_names[Math.floor(Math.random() * theme_names.length)];
|
||||||
this.app.readTheme(selected_theme);
|
this.app.readTheme(selected_theme);
|
||||||
this.app.api.log(selected_theme);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public nextTheme = (): void => {
|
public nextTheme = (): void => {
|
||||||
|
|||||||
Reference in New Issue
Block a user