Skip to content

Commit

Permalink
NOname-awa/graphics2d: add line direction (#733)
Browse files Browse the repository at this point in the history
  • Loading branch information
NexusKitten authored Aug 25, 2023
1 parent 46c0a37 commit be3127e
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion extensions/NOname-awa/graphics2d.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
Scratch.translate.setup({
zh: {
name: "图形 2D",
line_section: "线段([x1],[y1])到([x2],[y2])",
line_section: "([x1],[y1])到([x2],[y2])的距离",
ray_direction: "([x1],[y1])到([x2],[y2])的方向",
triangle: "三角形([x1],[y1])([x2],[y2])([x3],[y3])的 [CS]",
triangle_s: "三角形 [s1] [s2] [s3] 的面积",
quadrilateral:
Expand Down Expand Up @@ -57,6 +58,32 @@
},
},
},
{
opcode: "ray_direction",
blockType: Scratch.BlockType.REPORTER,
text: Scratch.translate({
id: "ray_direction",
default: "direction of ([x1],[y1]) to ([x2],[y2])",
}),
arguments: {
x1: {
type: Scratch.ArgumentType.NUMBER,
defaultValue: "0",
},
y1: {
type: Scratch.ArgumentType.NUMBER,
defaultValue: "0",
},
x2: {
type: Scratch.ArgumentType.NUMBER,
defaultValue: "100",
},
y2: {
type: Scratch.ArgumentType.NUMBER,
defaultValue: "0",
},
},
},
{
opcode: "vertical",
blockType: Scratch.BlockType.BOOLEAN,
Expand Down Expand Up @@ -270,6 +297,21 @@
Math.pow(args.x1 - args.x2, 2) + Math.pow(args.y1 - args.y2, 2)
);
}
ray_direction(args) {
// Added by NexusKitten
// 由 NexusKitten 添加
const dx =
Scratch.Cast.toNumber(args.x2) - Scratch.Cast.toNumber(args.x1);
const dy =
Scratch.Cast.toNumber(args.y2) - Scratch.Cast.toNumber(args.y1);
if (dx === 0 && dy === 0) {
return 0;
} else if (dy < 0) {
return (180 / Math.PI) * Math.atan(dx / dy) + 180;
} else {
return (180 / Math.PI) * Math.atan(dx / dy);
}
}
vertical(args) {
if (isNaN(args.a) || isNaN(args.b)) {
return false;
Expand Down

0 comments on commit be3127e

Please sign in to comment.