Skip to content

Complexify!: The world of complex numbers. - #2113

Open
Kenay555 wants to merge 39 commits into
TurboWarp:masterfrom
Kenay555:patch-2
Open

Complexify!: The world of complex numbers.#2113
Kenay555 wants to merge 39 commits into
TurboWarp:masterfrom
Kenay555:patch-2

Conversation

@Kenay555

@Kenay555 Kenay555 commented May 9, 2025

Copy link
Copy Markdown

A better extension for complex numbers, fixing all the issues with the original Complexity! See the first one at #2091
More motion, vectors, decimals and trig functions!

A better extension for complex numbers, fixing all the issues with the original Complexity!
@github-actions github-actions Bot added the pr: new extension Pull requests that add a new extension label May 9, 2025
@Kenay555

Kenay555 commented May 9, 2025

Copy link
Copy Markdown
Author

What do you think, @Brackets-Coder and @yuri-kiss?

@Brackets-Coder Brackets-Coder left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally speaking you should try to follow formatting best practices so your code doesn't look cluttered. Additionally, try to avoid opening new pull requests when it isn't necessary and you could just update the original :)

Comment thread extensions/Kenay-With-a-Y-At-The-End/Complexify!.js Outdated
'use strict';
//Just in case:
if (!Scratch.extensions.unsandboxed) {
alert("We don't like sand");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice allusion to Anakin Skywalker's famous opinion, but generally you should avoid alerts and just throw the error

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, i'll avoid alerts. also who's Anakin Skywalker?

@Brackets-Coder Brackets-Coder May 9, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, i'll avoid alerts. also who's Anakin Skywalker?

I'm just going to assume you've never watched the masterpiece of Star Wars

}
}

function jsCode() { /**Again, thanks Rawify*/

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First, you're putting the library (which is already inside an Immediately Invoked Function Expression) inside a function that is just executed elsewhere, and you're also re-declaring "use-strict" again which is totally redundant. Why can't you just minify the library and put it inside the class constructor?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're saying i can just insert the complex code in the constructor?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're saying i can just insert the complex code in the constructor?

That's how JS works, if you're just executing the function once inside the try catch block than might as well not have the function and reduce line count

Comment on lines +371 to +375
{
filter: [Scratch.TargetType.SPRITE], //Just in case
blockType: Scratch.BlockType.LABEL,
text: Scratch.translate("Motion"),
},

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so this section seems to be restricted to sprites, but let's check to make sure you're also filtering the block code so it doesn't return an error if these blocks are dragged from a sprite into the backdrop

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how to do that, but i'll try

@Brackets-Coder Brackets-Coder May 9, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how to do that, but i'll try

You're correctly filtering the block pallet in the stage, but the sprite-exclusive blocks can be dragged into the stage and may cause errors. You should check to see if the block's target is the stage, it works like this:

blockOpcode({ Arg1, Arg2 }, { target }) {
   console.log(target);
}

just console log target and you'll see how to detect the stage

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok i'll if (util.target.isStage) return; to each movement block

Comment on lines +411 to +429
filter: [Scratch.TargetType.SPRITE],
opcode: 'goToPolar', //A block no one asked for, and I fear no one needs
blockType: Scratch.BlockType.COMMAND,
text: 'Go polar [RADII] ∠ [ANGLY]',
arguments: {
RADII: { type: Scratch.ArgumentType.STRING, defaultValue: 50 },
ANGLY: { type: Scratch.ArgumentType.STRING, defaultValue: '0.9272952180016123' }
},
},
{
filter: [Scratch.TargetType.SPRITE],
opcode: 'glideComplex', //My favourite block [I love it]
blockType: Scratch.BlockType.COMMAND,
text: 'Glide [SECS] secs to [COMPLEX]',
arguments: {
COMPLEX: { type: Scratch.ArgumentType.STRING, defaultValue: '30+40i' },
SECS: { type: Scratch.ArgumentType.NUMBER, defaultValue: 1 }
},
},

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the offhand comments here really necessary? I think they just distract from the code

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, just some nice details. i'll delete them

Comment on lines +588 to +593
/**
We'll use toString() to return the Complex number with math notation.
If you wonder why, remember Complex is a class, and hence, returns objects.
So, we don't want "{re: -5, im: 1}", "[-5,1]" or "[object Object]". We want "-5+i" as is
Thus, no Scratch.Cast.toString() or anything like that, because toString() will always do.
*/

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May I ask why this is the case? If everything is returned as objects then shouldn't you just parse them and return their properties instead of the whole object? The reason Scratch.Cast.toString() exists is because scratch has weird quirks that it has to account for which the normal javascript toString doesn't

This comment was marked as abuse.

This comment was marked as abuse.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the tip, @yuri-kiss! also @Brackets-Coder, the true reason we used .toString() is because no other function will output the strings we want

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update: this.strBuild is the new string maker, it's equivalent to the old Complex.prototype.toString in (almost) every way.

Comment on lines +829 to +859
glideComplex (args, util) { //Do you recognize this? Answer at the end!
if (util.stackFrame.timer) {
const timeElapsed = util.stackFrame.timer.timeElapsed();
if (timeElapsed < util.stackFrame.duration * 1000) {
// We've moving! And we'll move again.
const frac = timeElapsed / (util.stackFrame.duration * 1000);
const dx = frac * (util.stackFrame.endX - util.stackFrame.startX);
const dy = frac * (util.stackFrame.endY - util.stackFrame.startY);
util.target.setXY(util.stackFrame.startX + dx, util.stackFrame.startY + dy);
util.yield();
} else {
// We're done! Now, lets end this
util.target.setXY(util.stackFrame.endX, util.stackFrame.endY);
}
} else {
// We're starting! So, new Timer!
util.stackFrame.timer = new Timer();
util.stackFrame.timer.start();
util.stackFrame.duration = args.SECS;
util.stackFrame.startX = util.target.x;
util.stackFrame.startY = util.target.y;
util.stackFrame.endX = Complex(args.COMPLEX).re; //A little edit
util.stackFrame.endY = Complex(args.COMPLEX).im;
if (util.stackFrame.duration <= 0) {
// We can't glide -1 seconds, can we?
util.target.setXY(util.stackFrame.endX, util.stackFrame.endY);
return;
}
util.yield();
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems really unoptimized

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea i just copied the code from Scratch-vm because we didn't know how to glide it ourselves

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

even asked ChatGPT, we couldn't find any optimization

Comment on lines +878 to +896
convertComplex({ ANGLE, TOSMTH }) {
try {
if (ANGLE == "") {
return 0;
}
const cInstance = Complex(ANGLE);
switch (TOSMTH) {
case 'degs to rads': if (cInstance.im == 0) return (cInstance.re * 0.017453292519943295) % twoPi;
return cInstance.mul(0.017453292519943295).toString(); break;
case '𝜋': return cInstance.mul(3.141592653589793).toString(); break;
case 'rads to degs': if (cInstance.im == 0) return (cInstance.re * 57.29577951308232) % 360;
return cInstance.mul(57.29577951308232).toString(); break;
default: return NaN
}
} catch (e) {
console.log(e);
return 0;
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh my gosh the formatting is crazy I'll see if I can fix it

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's not suppoded to happen
image

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just learn I can !format

@Brackets-Coder

Copy link
Copy Markdown
Member

!format

@yuri-kiss

This comment was marked as abuse.

Kenay555 added 2 commits May 9, 2025 13:31
I'll add a better glideComplex, more Scratch.Cast and the minified code later. For now, small changes first
Still working on some thing though. I'll tell you when it's ready.
@Kenay555

Kenay555 commented May 10, 2025

Copy link
Copy Markdown
Author

Generally speaking you should try to follow formatting best practices so your code doesn't look cluttered. Additionally, try to avoid opening new pull requests when it isn't necessary and you could just update the original :)

@Brackets-Coder, I'm new to JS and GitHub and that sort of stuff. I don't know a lot of things. Some things, but not all of them. I didn't knew that you could edit pull-requesting files until recently, after I created this new pull request.
But don't take me like an ignorant either. I may be learning English and JS, but I learned enough to understand what you're saying. I'll always try my best to reach my goal, even if it takes me a new set of rules to learn.
So don't expect me to be a perfect coder, nor be a random guy that has a laptop and asks ChatGPT and other coders to do all work for him. Just wanting to point that out.
Also, @yuri-kiss, what's wrong about the licence? ClickerTale_2 used MPL-2.0, as reccomended by the CONTRIBUTING.md,

This is riddled with licensing issues, poor code formatting, horrible practices and lots of spelling mistakes, I am making this a draft until further notice...

And which are the horrible practices? Now that I know how to edit files, maybe I can correct Complexify!.js

@CubesterYT

Copy link
Copy Markdown
Member

!format

@Brackets-Coder

Copy link
Copy Markdown
Member

Generally speaking you should try to follow formatting best practices so your code doesn't look cluttered. Additionally, try to avoid opening new pull requests when it isn't necessary and you could just update the original :)

@Brackets-Coder, I'm new to JS and GitHub and that sort of stuff. I don't know a lot of things. Some things, but not all of them. I didn't knew that you could edit pull-requesting files until recently, after I created this new pull request. But don't take me like an ignorant either. I may be learning English and JS, but I learned enough to understand what you're saying. I'll always try my best to reach my goal, even if it takes me a new set of rules to learn. So don't expect me to be a perfect coder, nor be a random guy that has a laptop and asks ChatGPT and other coders to do all work for him. Just wanting to point that out. Also, @yuri-kiss, what's wrong about the licence? ClickerTale_2 used MPL-2.0, as reccomended by the CONTRIBUTING.md,

This is riddled with licensing issues, poor code formatting, horrible practices and lots of spelling mistakes, I am making this a draft until further notice...

And which are the horrible practices? Now that I know how to edit files, maybe I can correct Complexify!.js

Absolutely not trying to be critical, we all were there once and it was only recently (in the past few months) that I really started with Github. It's an understandable situation, I'm just here to try to help you through it.

@Kenay555
Kenay555 marked this pull request as ready for review May 10, 2025 17:54
@Kenay555

Kenay555 commented May 21, 2025

Copy link
Copy Markdown
Author

!format (heard these fix smth idk)

@github-actions

Copy link
Copy Markdown

The formatting bot didn't find any formatting issues. It currently only checks the extensions folder. The author or a maintainer can run terminal command 'npm run format' manually to format all files.

Yep. MORE THINGIES. Thanks to every error you've found, it's better than ever. Can't wait to see it at the gallery!
@Kenay555

Kenay555 commented May 21, 2025

Copy link
Copy Markdown
Author

!format (for the update. two done, one to go)

@github-actions

Copy link
Copy Markdown

The formatting bot didn't find any formatting issues. It currently only checks the extensions folder. The author or a maintainer can run terminal command 'npm run format' manually to format all files.

@Kenay555

Copy link
Copy Markdown
Author

!format

@github-actions

Copy link
Copy Markdown

The formatting bot didn't find any formatting issues. It currently only checks the extensions folder. The author or a maintainer can run terminal command 'npm run format' manually to format all files.

@Kenay555

Kenay555 commented Sep 2, 2026

Copy link
Copy Markdown
Author

@Brackets-Coder never told me about my horrible practices :(

@Kenay555

Kenay555 commented Sep 2, 2026

Copy link
Copy Markdown
Author

!format

@Brackets-Coder

Copy link
Copy Markdown
Member

@Brackets-Coder never told me about my horrible practices :(

Contrary to popular opinion, I'm not very good at math. I usually just stick with the code.

@Kenay555

Kenay555 commented Sep 2, 2026

Copy link
Copy Markdown
Author

@Brackets-Coder yeah but there must be any code-related horrible practices, right? (It passed a year but some could still be stuck with me lol)
Edit: also i just realized you did answered the message but not answered the question. I'm not easily offended, btw (in the sense that you can tell me anything).
image

@Kenay555

Kenay555 commented Sep 3, 2026

Copy link
Copy Markdown
Author

@penta-quark-neutro I'll probably be updating the version soon, stay alert
image
image
image

@penta-quark-neutro

Copy link
Copy Markdown

"export [x] as [pentaquark]"? Wouldn't "compleX" be more accurate? I have two extensions that can handle complex numbers, and they don't accept the same inputs.
By the way, I applaud you for adding so much; I often don't add a lot of things to my own extensions out of sheer laziness.

@Kenay555

Kenay555 commented Sep 3, 2026

Copy link
Copy Markdown
Author

@penta-quark-neutro Thanks, and I didn't knew you had two complex number extensions. Before I seal the blocks, you can propose changes to their current names. Which block names seem counter-intuitive or wronged? (i'm so used to their current ones it's hard for me to spot places for changes in favor of understandment or consistency)

@penta-quark-neutro

Copy link
Copy Markdown

I think all the names are fine, but don't take my word for it—since I'm a mathematician, that's the sort of thing I understand.
However, I believe anyone interested in using extensions of this nature would already have some knowledge of the subject.

@Kenay555

Kenay555 commented Sep 3, 2026

Copy link
Copy Markdown
Author

@penta-quark-neutro estoy buscando tu otra extensión de números complejos, para añadir otra forma de exportarlos. De paso (y ya que ere matemático), dáme ideas de funciones para poner en mi extensión :3

@penta-quark-neutro

Copy link
Copy Markdown

la otra extension es "vector directo", sus entradas son vectores [re,im], directamente el objeto, no un string.
no sabría que ideas darte, pues mucho de lo que se haría con números complejos depende de construcciones algebraicas mas que de funciones, solo con las las funciones básicas se cubre muchísimo, yo creo que tu extensión esta ya bastante completa.

@Kenay555

Kenay555 commented Sep 3, 2026

Copy link
Copy Markdown
Author

@penta-quark-neutro Me alegra que lo apruebes. Estuve revisando tus otras extensiones, y al ojo se nota que eres matemático (no entiendo nada de lo que escribes pero funciona xD); sé que este no es el mejor lugar para decir esto, pero tu extensión de lógica trivalente sería ligeramente más legible y rápida si utilizas 1=verdad, 0=falsedad, y 0.5=desconocido (cuesta menos calcular ar.a<ar.b que crear nuevos objetos de un-sólo-uso cada vez, si sabes a lo que me refiero)

@penta-quark-neutro

penta-quark-neutro commented Sep 3, 2026

Copy link
Copy Markdown

si entiendo, pero logica trivalente no fue hecho con la misma intención que otros, fue un trabajo mas de aburrimiento.
igualmente, si quieres hablar de mis extensiones, este no es lugar, si no en mi repo.

@Kenay555

Kenay555 commented Sep 3, 2026

Copy link
Copy Markdown
Author

@penta-quark-neutro Con la nueva actualización, ¿tú que harías?

image image

y mi logro personal:
image

En estos no cambié nada, pero déjame presumirlos:
image

image

!format

@penta-quark-neutro

Copy link
Copy Markdown

¿como que "que haría"?

@Kenay555

Kenay555 commented Sep 3, 2026

Copy link
Copy Markdown
Author

@penta-quark-neutro no sé, pues ni yo conozco la razón detrás de crear Complexity. Bueno, te veré en tu repo por un rato, pues encuentro varios lugares para optimizar ;3

@penta-quark-neutro

Copy link
Copy Markdown

esto es un string, en lugar de un array.
Captura de pantalla (276)

@Kenay555

Kenay555 commented Sep 3, 2026

Copy link
Copy Markdown
Author

@penta-quark-neutro Pues claro, ese bloque de Export lo hice compatible con la naturaleza de Scratch (quien sólo sabe Strings, Numbers y Booleans), por esa misma razón los complejos de mi extensión se extraen de strings (hecho por mi función strParse) y se retornan como strings (gracias a strBuild). Si revisaras mi código con un editor de texto, te darías cuenta que lo hice a propósito.

image

@Kenay555

Kenay555 commented Sep 4, 2026

Copy link
Copy Markdown
Author

now if you excuse me, I'll work to add the Riemann's Zeta soon

@penta-quark-neutro

Copy link
Copy Markdown

I don't know if you'll believe me, but I actually imagined you would do it at some point.

@penta-quark-neutro

Copy link
Copy Markdown

I already have a weak approximation; I can now prove results.

@Kenay555

Kenay555 commented Sep 5, 2026

Copy link
Copy Markdown
Author

I don't know if you'll believe me, but I actually imagined you would do it at some point.

Nah, if so, you'd've told me when I asked for more functions. Además, dices tener una aproximación, ¿no, @penta-quark-neutro ? Sería útil compararlas con la mía.

@penta-quark-neutro

Copy link
Copy Markdown

no sugerí eso porque es una función "rara", con aplicaciones especificas.
¿acaso también pondrías cosas la función xigamma o la función lerch, o transformada de fourier?, no creo.
mucho ya es en extremo de nicho, y para programadores normales, eso esta mas que completo y de hecho con mas de lo esperado.
y sobre la aproximación, es por fuerza bruta, no quise esforzarme en algo mejor, pero converge muy rápido.

@Kenay555

Kenay555 commented Sep 5, 2026

Copy link
Copy Markdown
Author

@penta-quark-neutro I'm going to have a breakdown
(for context I tried practicing power series and failed too many times)
image

@Kenay555

Kenay555 commented Sep 5, 2026

Copy link
Copy Markdown
Author

Forget it, I loosened the flag
image

@Kenay555

Kenay555 commented Sep 5, 2026

Copy link
Copy Markdown
Author

Forget you fogot, the render just broke
image

@Kenay555

Kenay555 commented Sep 5, 2026

Copy link
Copy Markdown
Author

This is a hell of a roller coaster (of emotions)
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

duplicate This issue or pull request already exists pr: new extension Pull requests that add a new extension

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants