Skip to content

Commit

Permalink
Add a block to graphics2d
Browse files Browse the repository at this point in the history
  • Loading branch information
NexusKitten authored Jul 12, 2023
1 parent 61353ff commit 1d29de1
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions extensions/NOname-awa/graphics2d.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
zh: {
name: '图形 2D',
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: '四边形([x1],[y1])([x2],[y2])([x3],[y3])([x4],[y4])的 [CS]',
Expand Down Expand Up @@ -48,6 +49,29 @@
},
}
},
{
opcode: 'ray_direction',
blockType: Scratch.BlockType.REPORTER,
text: Scratch.translate({ id: 'ray_direction', default: 'direction from ([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 @@ -237,6 +261,15 @@
line_section(args) {
return Math.sqrt(Math.pow(args.x1 - args.x2, 2) + Math.pow(args.y1 - args.y2, 2));
}
ray_direction(args) {
// Added by NexusKitten
// 由 NexusKitten 添加
if (args.y1 > args.y2) {
return ((180 / Math.PI) * Math.atan((args.x2 - args.x1) / (args.y2 - args.y1))) + 180;
} else {
return ((180 / Math.PI) * Math.atan((args.x2 - args.x1) / (args.y2 - args.y1)));
}
}
vertical(args) {
if (isNaN(args.a) || isNaN(args.b)) {
return false;
Expand Down

0 comments on commit 1d29de1

Please sign in to comment.