Skip to content

Commit 91dcd65

Browse files
true-fantom/math: Add true sin/cos/tan block. (TurboWarp#1959)
sorry mio In Scratch/Turbowarp, the sin/cos/tan/asin/acos/atan blocks don't return as expected-- they're run through several other equations to deal with rounding, and to make the blocks compatible with degrees. ![chrome_eTFJtRFaWZ](https://github.com/user-attachments/assets/b474b477-7ce1-479e-9af0-3bfe223f9ba3) While this makes the blocks more user-friendly, it can be annoying for people who want the original functions to have to essentially undo the extra calculations. This PR adds a new block to the Math extension which introduces a new block, featuring all the same trig functions, but returning exactly what their Javascript Math counterpart does. ![chrome_zkk2vNonX3](https://github.com/user-attachments/assets/9506267f-0f02-4e5e-a239-cf1c6c7ecc3c) --------- Co-authored-by: DangoCat[bot] <[email protected]>
1 parent 9980c77 commit 91dcd65

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

extensions/true-fantom/math.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,21 @@
497497
},
498498
extensions: ["colours_operators"],
499499
},
500+
{
501+
opcode: "true_math_op",
502+
blockType: Scratch.BlockType.REPORTER,
503+
text: Scratch.translate("true [OPERATOR] [NUM]"),
504+
arguments: {
505+
OPERATOR: {
506+
type: Scratch.ArgumentType.STRING,
507+
menu: "OPERATOR",
508+
},
509+
NUM: {
510+
type: Scratch.ArgumentType.NUMBER,
511+
},
512+
},
513+
extensions: ["colours_operators"],
514+
},
500515
"---",
501516
/* eslint-disable extension/should-translate */
502517
{
@@ -569,6 +584,12 @@
569584
extensions: ["colours_operators"],
570585
},
571586
],
587+
menus: {
588+
OPERATOR: {
589+
acceptReporters: true,
590+
items: ["sin", "cos", "tan", "asin", "acos", "atan"],
591+
},
592+
},
572593
};
573594
}
574595

@@ -662,6 +683,26 @@
662683
log_with_base_block({ A, B }) {
663684
return Math.log(cast.toNumber(A)) / Math.log(cast.toNumber(B));
664685
}
686+
true_math_op(args) {
687+
const operator = cast.toString(args.OPERATOR).toLowerCase();
688+
const n = cast.toNumber(args.NUM);
689+
switch (operator) {
690+
case "sin":
691+
return Math.sin(n);
692+
case "cos":
693+
return Math.cos(n);
694+
case "tan":
695+
return Math.tan(n);
696+
case "asin":
697+
return Math.asin(n);
698+
case "acos":
699+
return Math.acos(n);
700+
case "atan":
701+
return Math.atan(n);
702+
default:
703+
return 0;
704+
}
705+
}
665706
pi_block() {
666707
return Math.PI;
667708
}

0 commit comments

Comments
 (0)