Skip to content

Conversation

@BonesYT
Copy link

@BonesYT BonesYT commented Jan 11, 2025

I couldn't find an extension dedicated to complex numbers, you know... sqrt(-1) and stuff like that, so I made one.
This is also my first extension, and it kinda works pretty well!

All features:

  • Construct a complex number with real and/or imaginary component

  • Get the real and imaginary components of that value

  • Boolean to check if a number is real or not

  • Addition, subtraction, multiplication, division and exponentiation. And modulo.

  • Functions with single input, with extra: conjugate, flip, sign, atan2.

  • Toggle between simple and advanced syntax, for perfomance reasons. Maybe simple mode is at least slightly faster.

Examples

  1. Mandelbrot Set
    image
  2. Julia Set
    image

}
Scratch.extensions.register(new ScratchComplex());
})(Scratch);
})(Scratch);
Copy link
Author

Choose a reason for hiding this comment

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

what do you mean format only works if the very last line is empty??????????????????????

@penta-quark-neutro
Copy link

Interesting, I also made one of the same thing, but for personal use.
Your extension is quite good, but slow.
It takes almost 2.57 seconds to exponentiate 1000000 complex numbers.
Approximately 4 times slower than mine.
I think you should optimize it.

@GarboMuffin GarboMuffin added pr: other Pull requests that neither add new extensions or change existing ones pr: new extension Pull requests that add a new extension and removed pr: other Pull requests that neither add new extensions or change existing ones labels Jan 13, 2025
GarboMuffin added a commit that referenced this pull request Jan 13, 2025
- fix breakage when diff contains very long line (#1861)
- unhardcode repository
- add more logging
jexjws pushed a commit to 40codeTeam/tw-extensions that referenced this pull request Mar 17, 2025
- fix breakage when diff contains very long line (TurboWarp#1861)
- unhardcode repository
- add more logging
Copy link
Contributor

@Brackets-Coder Brackets-Coder left a comment

Choose a reason for hiding this comment

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

Haven't tested this fully yet, but it loads and seems to work
If this is your first extension, nice job! Here's just a few tips to make it better:

Avoid using the master branch, create a new branch for each pull request you'd like to submit for organization purposes.

}

class ScratchComplex {
constructor() {}
Copy link
Contributor

Choose a reason for hiding this comment

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

if constructor is empty may I ask why it's here? Maybe just a clarification thing

complexSyntaxMode: {
acceptReporters: false,
items: ["simple (faster)", "advanced (slower)"],
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Menus should be translated as well, use this structure for each item:

item: {
   text: Scratch.translate("simple"),
   value: "simple",
}

"itchio",
"gamejolt",
"obviousAlexC/newgroundsIO",
"BonesYT/ScratchComplex",
Copy link
Contributor

Choose a reason for hiding this comment

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

Why'd you put this at the bottom? It doesn't really matter but you could put it near other similar extensions

Copy link
Contributor

Choose a reason for hiding this comment

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

Images aren't supposed to have text because of translation but I guess this is okay...

Copy link
Contributor

Choose a reason for hiding this comment

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

Github did something weird with displaying the diff... but sure

@Kenay555
Copy link

Kenay555 commented Sep 19, 2025

Hi @BonesYT ! I may or may not made something similar (like, with more blocks and such...) see #2113 for more :D Anyways, I'm working on updating my extension, because it's wierd with every letter. Plus, I found how to implement Quaternions, and maybe have more optimization ideas for it, maybe too many... I liked how you tackled some problems in the file. But that's not why I am here.

I was recently told about your existence, and looks like your extension has more power than mine (altho I have more blocks >:D but that's not the point either). From mathematician to cool guy, wanna work together?
image

(or maybe we should call @penta-quark-neutro to see what optimizations he used!)

@penta-quark-neutro
Copy link

There are fairly simple ways to get better performance. In the case of my extension, I simply rewrote the operations to avoid classes or calling functions. Using vectors is very efficient, but I imagine that your extension should return a string.
This is an example of a way to implement octonions and have them calculate quickly: "octa3(ar){const v1=ar.a,v2=ar.b;return [(v1[0]*v2[0])-(v1[1]*v2[1])-(v1[2]*v2[2])-(v1[3]*v2[3])-(v1[4]*v2[4])-(v1[5]*v2[5])-(v1[6]*v2[6])-(v1[7]*v2[7]) ,(v1[0]*v2[1])+(v1[1]*v2[0])-(v1[2]*v2[3])+(v1[3]*v2[2])-(v1[4]*v2[5])+(v1[5]*v2[4])+(v1[6]*v2[7])-(v1[7]*v2[6]) ,(v1[0]*v2[2])+(v1[1]*v2[3])+(v1[2]*v2[0])-(v1[3]*v2[1])-(v1[4]*v2[6])-(v1[5]*v2[7])+(v1[6]*v2[4])+(v1[7]*v2[5]) ,(v1[0]*v2[3])-(v1[1]*v2[2])+(v1[2]*v2[1])+(v1[3]*v2[0])-(v1[4]*v2[7])+(v1[5]*v2[6])-(v1[6]*v2[5])+(v1[7]*v2[4]), (v1[0]*v2[4])+(v1[1]*v2[5])+(v1[2]*v2[6])+(v1[3]*v2[7])+(v1[4]*v2[0])-(v1[5]*v2[1])-(v1[6]*v2[2])-(v1[7]*v2[3]), (v1[0]*v2[5])-(v1[1]*v2[4])+(v1[2]*v2[7])-(v1[3]*v2[6])+(v1[4]*v2[1])+(v1[5]*v2[0])+(v1[6]*v2[3])-(v1[7]*v2[2]),( v1[0]*v2[6])-(v1[1]*v2[7])-(v1[2]*v2[4])+(v1[3]*v2[5])+(v1[4]*v2[2])-(v1[5]*v2[3])+(v1[6]*v2[0])+(v1[7]*v2[1]),( v1[0]*v2[7])+(v1[1]*v2[6])-(v1[2]*v2[5])-(v1[3]*v2[4])+(v1[4]*v2[3])+(v1[5]*v2[2])-(v1[6]*v2[1])+(v1[7]*v2[0])]}"
Avoid calling functions and creating intermediate steps, avoid creating more variables than necessary, and chaining uses more resources and should be minimized.
Even the example I provided could be optimized further, but I'm currently working on an object extension and adding sedenions to my vector extension.
Good luck.

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

Labels

pr: new extension Pull requests that add a new extension

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants