diff --git a/extensions/NOname-awa/graphics2d.js b/extensions/NOname-awa/graphics2d.js index cd6efa33e6..44bf8d5f3a 100644 --- a/extensions/NOname-awa/graphics2d.js +++ b/extensions/NOname-awa/graphics2d.js @@ -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: @@ -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, @@ -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;