From 96e35f4c2eaaa88ac9dfc3a9922fe485be6473a0 Mon Sep 17 00:00:00 2001 From: Raphael Forment Date: Sun, 27 Aug 2023 18:44:27 +0200 Subject: [PATCH 01/26] another fix --- src/main.ts | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/main.ts b/src/main.ts index d180bff..b06cc24 100644 --- a/src/main.ts +++ b/src/main.ts @@ -967,12 +967,8 @@ export class Editor { } } -// Creating the application const app = new Editor(); - - -// When the user leaves the page, all the universes should be saved in the localStorage window.addEventListener("beforeunload", () => { // @ts-ignore event.preventDefault(); @@ -983,11 +979,3 @@ window.addEventListener("beforeunload", () => { app.clock.stop(); return null; }); - -// function reportMouseCoordinates(event: MouseEvent) { -// app._mouseX = event.clientX; -// app._mouseY = event.clientY; -// } - -onmousemove = function(e){console.log("mouse location:", e.clientX, e.clientY)} - From 1e0a0d12685125b1d3a8f064c09656b4bab8f965 Mon Sep 17 00:00:00 2001 From: Raphael Forment Date: Sun, 27 Aug 2023 19:29:38 +0200 Subject: [PATCH 02/26] making plans --- src/API.ts | 11 +++++++- src/ArrayExtensions.ts | 64 ++++++++++++++++++++++++++++++++++++++---- 2 files changed, 69 insertions(+), 6 deletions(-) diff --git a/src/API.ts b/src/API.ts index 9f4b09d..4033437 100644 --- a/src/API.ts +++ b/src/API.ts @@ -958,7 +958,16 @@ export class UserAPI { */ return this._euclidean_cycle(pulses, length, rotate)[iterator % length]; }; - ec = this.euclid; + ec: Function = this.euclid; + + public rhythm = ( + div: number, + pulses: number, + length: number, + rotate: number = 0 + ): boolean => { + return this.mod(div) && this._euclidean_cycle(pulses, length, rotate).div(div); + } _euclidean_cycle( pulses: number, diff --git a/src/ArrayExtensions.ts b/src/ArrayExtensions.ts index c8c6e72..b715fa9 100644 --- a/src/ArrayExtensions.ts +++ b/src/ArrayExtensions.ts @@ -3,6 +3,10 @@ export {}; declare global { interface Array { + add(amount: number): number[]; + sub(amount: number): number[]; + mult(amount: number): number[]; + division(amount: number): number[]; palindrome(): T[]; random(index: number): T; rand(index: number): T; @@ -20,6 +24,8 @@ declare global { rotate(steps: number): this; unique(): this; in(value: T): boolean; + square(): number[]; + sqrt(): number[]; } } @@ -27,6 +33,54 @@ export const makeArrayExtensions = (api: UserAPI) => { Array.prototype.in = function (this: T[], value: T): boolean { return this.includes(value); }; + + Array.prototype.square = function (): number[] { + /** + * @returns New array with squared values. + */ + return this.map((x: number) => x * x); + }; + + Array.prototype.sqrt = function (): number[] { + /** + * @returns New array with square roots of values. Throws if any element is negative. + */ + if (this.some(x => x < 0)) throw new Error('Cannot take square root of negative number'); + return this.map((x: number) => Math.sqrt(x)); + }; + + Array.prototype.add = function (amount: number): number[] { + /** + * @param amount - The value to add to each element in the array. + * @returns New array with added values. + */ + return this.map((x: number) => x + amount); + }; + + Array.prototype.sub = function (amount: number): number[] { + /** + * @param amount - The value to subtract from each element in the array. + * @returns New array with subtracted values. + */ + return this.map((x: number) => x - amount); + }; + + Array.prototype.mult = function (amount: number): number[] { + /** + * @param amount - The value to multiply with each element in the array. + * @returns New array with multiplied values. + */ + return this.map((x: number) => x * amount); + }; + + Array.prototype.division = function (amount: number): number[] { + /** + * @param amount - The value to divide each element in the array by. + * @returns New array with divided values. Throws if division by zero. + */ + if (amount === 0) throw new Error('Division by zero'); + return this.map((x: number) => x / amount); + }; Array.prototype.pick = function () { /** @@ -37,13 +91,13 @@ export const makeArrayExtensions = (api: UserAPI) => { return this[Math.floor(api.randomGen() * this.length)]; }; - Array.prototype.beat = function () { + Array.prototype.beat = function (beat: number = 1) { /** * Returns the element corresponding to the current beat * * @returns The element corresponding to the current beat */ - return this[api.ebeat() % this.length]; + return this[(api.ebeat() / beat) % this.length]; }; Array.prototype.bar = function () { @@ -160,7 +214,7 @@ export const makeArrayExtensions = (api: UserAPI) => { return this; }; - Array.prototype.repeatAll = function (this: T[], amount: number) { + Array.prototype.repeatAll = function (this: T[], amount: number = 1) { /** * Repeats all elements in the array n times. * @@ -181,7 +235,7 @@ export const makeArrayExtensions = (api: UserAPI) => { return this; }; - Array.prototype.repeatPair = function (this: T[], amount: number) { + Array.prototype.repeatPair = function (this: T[], amount: number = 1) { /** * Repeats all elements in the array n times, except for the * elements at odd indexes. @@ -211,7 +265,7 @@ export const makeArrayExtensions = (api: UserAPI) => { return this; }; - Array.prototype.repeatOdd = function (this: T[], amount: number) { + Array.prototype.repeatOdd = function (this: T[], amount: number = 1) { /** * Repeats all elements in the array n times, except for the * elements at even indexes. From 13300b698e20d6f2161b84271798d2f5efdbbc22 Mon Sep 17 00:00:00 2001 From: Raphael Forment Date: Sun, 27 Aug 2023 19:35:49 +0200 Subject: [PATCH 03/26] making button font smaller --- src/Documentation.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Documentation.ts b/src/Documentation.ts index 1a2af7c..ac71c70 100644 --- a/src/Documentation.ts +++ b/src/Documentation.ts @@ -28,7 +28,7 @@ const samples_to_markdown = (application: Editor) => { markdownList += ` -`; - }); - final_html = final_html + ""; - existing_universes!.innerHTML = final_html; + this.updateKnownUniversesView(); this.openBuffersModal(); } @@ -668,6 +654,21 @@ export class Editor { return JSON.parse(hash); }; + updateKnownUniversesView = () => { + let existing_universes = document.getElementById("existing-universes"); + let known_universes = Object.keys(this.universes); + let final_html = "
    "; + known_universes.forEach((name) => { + final_html += ` +
  • +

    ${name}

    + +
  • `; + }); + final_html = final_html + "
"; + existing_universes!.innerHTML = final_html; + } + share() { const hashed_table = btoa( JSON.stringify({ From 44d1c5e201a9c696b4d9f17be590d1d03e96d355 Mon Sep 17 00:00:00 2001 From: Raphael Forment Date: Mon, 28 Aug 2023 00:10:35 +0200 Subject: [PATCH 12/26] small interface cosmetic fix --- index.html | 12 ++++++------ src/main.ts | 1 + 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/index.html b/index.html index a163d7b..50e81c2 100644 --- a/index.html +++ b/index.html @@ -222,27 +222,27 @@ dark:border-neutral-700 border-none" >