-
Notifications
You must be signed in to change notification settings - Fork 303
Vectors #2074
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
unknown07724
wants to merge
50
commits into
TurboWarp:master
Choose a base branch
from
unknown07724:vectors
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+181
−0
Open
Vectors #2074
Changes from all commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
e437ea9
Create timeutills.js
unknown07724 f0f99b6
Rename extensions/timeutills.js to extensions/unknown/timeutills.js
unknown07724 17680ea
Update timeutills.js
unknown07724 af93815
Update timeutills.js
unknown07724 5d4882b
Update timeutills.js
unknown07724 b9ad34e
Update timeutills.js
unknown07724 8cd2ad5
Create mailutils.js
unknown07724 c8ba421
Update mailutils.js
unknown07724 1425e97
Update mailutils.js
unknown07724 bafa172
Merge branch 'TurboWarp:master' into master
unknown07724 c83d9f4
Delete extensions/unknown/mailutils.js
unknown07724 080e790
Delete extensions/unknown/timeutills.js
unknown07724 957cc7f
Merge branch 'TurboWarp:master' into api-toolbox
unknown07724 293efd2
Create api-toolbox.js
unknown07724 84784db
Rename api-toolbox.js to api-toolbox.js
unknown07724 2bdeb70
Update extensions.json
unknown07724 fe8abcc
Update api-toolbox.js
unknown07724 6c6085d
Update api-toolbox.js
unknown07724 766784d
Update api-toolbox.js
unknown07724 58b0eca
Create vectors.js
unknown07724 6587f1b
Delete extensions/unknown/api-toolbox.js
unknown07724 215bcf8
Update extensions.json
unknown07724 7f5daee
Update vectors.js
unknown07724 094a242
[Automated] Format code
DangoCat 7dfa05a
Update vectors.js
unknown07724 db0edbd
[Automated] Format code
DangoCat 86ddd01
Update vectors.js
unknown07724 fa0d902
[Automated] Format code
DangoCat abbdf2f
Update vectors.js
unknown07724 a481dcb
Update vectors.js
unknown07724 14cdecc
Update vectors.js
unknown07724 7e9c6fc
Update vectors.js
unknown07724 d422aff
Merge branch 'TurboWarp:master' into vectors
unknown07724 2c7e9da
Update vectors.js
unknown07724 38f99bf
Update vectors.js
unknown07724 7fe7b1a
Update vectors.js
unknown07724 1d505e4
Update vectors.js
unknown07724 f374566
Update vectors.js
unknown07724 30b67f0
[Automated] Format code
DangoCat 605495f
Update vectors.js
unknown07724 84a6583
[Automated] Format code
DangoCat 6b220ab
Update vectors.js
unknown07724 b48d9cf
Merge branch 'TurboWarp:master' into vectors
unknown07724 41bd715
Update vectors.js
unknown07724 9a0b0d1
Update vectors.js
unknown07724 3b7f9d8
Update vectors.js
unknown07724 9b0792b
[Automated] Format code
DangoCat e262c63
Update vectors.js
unknown07724 36b4423
Merge branch 'TurboWarp:master' into vectors
unknown07724 9e5e58b
Return empty string for undefined vector magnitudes
unknown07724 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,180 @@ | ||
| // Name: Vectors | ||
| // ID: unknownvectors | ||
| // Description: variables with a direction. | ||
| // By: Unknown07724 <https://scratch.mit.edu/users/Unknown07724/> | ||
| // License: MPL-2.0 | ||
|
|
||
| (function (Scratch) { | ||
| "use strict"; | ||
|
|
||
| const Vectoricon = | ||
| "data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3c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mFtaWx5PSJTYW5zIFNlcmlmIiBmb250LXdlaWdodD0ibm9ybWFsIiB0ZXh0LWFuY2hvcj0ic3RhcnQiPjx0c3BhbiB4PSIwIiBkeT0iMCI+MS4yPC90c3Bhbj48L3RleHQ+PC9nPjwvc3ZnPg=="; | ||
|
|
||
| // Unsandboxed check | ||
| if (!Scratch.extensions.unsandboxed) { | ||
| throw new Error("This extension must run unsandboxed"); | ||
| } | ||
|
|
||
| const ids = []; | ||
This comment was marked as abuse.
Sorry, something went wrong. |
||
| const directions = {}; | ||
This comment was marked as abuse.
Sorry, something went wrong. |
||
| const magnitudes = {}; | ||
|
|
||
| class UnknownVectors { | ||
| getInfo() { | ||
| return { | ||
| id: "unknownvectors", | ||
| name: Scratch.translate("Vectors"), | ||
| color1: "#3495eb", | ||
| blocksIconURL: Vectoricon, | ||
| blocks: [ | ||
| { | ||
| opcode: "vectorCreate", | ||
| blockType: Scratch.BlockType.COMMAND, | ||
| text: Scratch.translate( | ||
| "create vector with ID [ID], direction [DIRECTION] and magnitude [MAGNITUDE]" | ||
This comment was marked as abuse.
Sorry, something went wrong. |
||
| ), | ||
| arguments: { | ||
| ID: { type: Scratch.ArgumentType.STRING, defaultValue: "vec1" }, | ||
| DIRECTION: { | ||
| type: Scratch.ArgumentType.NUMBER, | ||
| defaultValue: 90, | ||
| }, | ||
| MAGNITUDE: { | ||
| type: Scratch.ArgumentType.NUMBER, | ||
| defaultValue: 10, | ||
| }, | ||
| }, | ||
| }, | ||
| { | ||
| opcode: "vectorChangeMag", | ||
| blockType: Scratch.BlockType.COMMAND, | ||
| text: Scratch.translate( | ||
| "change vector [ID]'s magnitude to [MAGNITUDE]" | ||
| ), | ||
| arguments: { | ||
| ID: { type: Scratch.ArgumentType.STRING, defaultValue: "vec1" }, | ||
| MAGNITUDE: { | ||
| type: Scratch.ArgumentType.NUMBER, | ||
| defaultValue: 10, | ||
| }, | ||
| }, | ||
| }, | ||
| { | ||
| opcode: "vectorChange", | ||
| blockType: Scratch.BlockType.COMMAND, | ||
| text: Scratch.translate( | ||
| "change vector [ID] to direction [DIRECTION] and magnitude [MAGNITUDE]" | ||
| ), | ||
| arguments: { | ||
| ID: { type: Scratch.ArgumentType.STRING, defaultValue: "vec1" }, | ||
| DIRECTION: { | ||
| type: Scratch.ArgumentType.NUMBER, | ||
| defaultValue: 90, | ||
| }, | ||
| MAGNITUDE: { | ||
| type: Scratch.ArgumentType.NUMBER, | ||
| defaultValue: 10, | ||
| }, | ||
| }, | ||
| }, | ||
| { | ||
| opcode: "vectorDelete", | ||
| blockType: Scratch.BlockType.COMMAND, | ||
| text: Scratch.translate("delete vector with [ID]"), | ||
| arguments: { | ||
| ID: { type: Scratch.ArgumentType.STRING, defaultValue: "vec1" }, | ||
| }, | ||
| }, | ||
| { | ||
| opcode: "vectorChangedir", | ||
| blockType: Scratch.BlockType.COMMAND, | ||
| text: Scratch.translate( | ||
| "change vector [ID]'s direction to [DIRECTION]" | ||
| ), | ||
| arguments: { | ||
| ID: { type: Scratch.ArgumentType.STRING, defaultValue: "vec1" }, | ||
| DIRECTION: { | ||
| type: Scratch.ArgumentType.NUMBER, | ||
| defaultValue: 90, | ||
| }, | ||
| }, | ||
| }, | ||
| { | ||
| opcode: "vectorMag", | ||
| blockType: Scratch.BlockType.REPORTER, | ||
| text: Scratch.translate("magnitude of vector [ID]"), | ||
| arguments: { | ||
| ID: { type: Scratch.ArgumentType.STRING, defaultValue: "vec1" }, | ||
| }, | ||
| }, | ||
| { | ||
| opcode: "listOfIDs", | ||
| blockType: Scratch.BlockType.REPORTER, | ||
| text: Scratch.translate("List of IDs"), | ||
| }, | ||
| { | ||
| opcode: "vectorDir", | ||
| blockType: Scratch.BlockType.REPORTER, | ||
| text: Scratch.translate("direction of vector [ID]"), | ||
| arguments: { | ||
| ID: { type: Scratch.ArgumentType.STRING, defaultValue: "vec1" }, | ||
| }, | ||
| }, | ||
| ], | ||
| }; | ||
| } | ||
|
|
||
| vectorCreate(args) { | ||
| const id = Scratch.Cast.toString(args.ID); | ||
| if (!ids.includes(id)) ids.push(id); | ||
| directions[id] = Scratch.Cast.toNumber(args.DIRECTION); | ||
| magnitudes[id] = Scratch.Cast.toNumber(args.MAGNITUDE); | ||
| } | ||
|
|
||
| vectorChange(args) { | ||
| const id = Scratch.Cast.toString(args.ID); | ||
| directions[id] = Scratch.Cast.toNumber(args.DIRECTION); | ||
| magnitudes[id] = Scratch.Cast.toNumber(args.MAGNITUDE); | ||
| } | ||
|
|
||
| vectorChangedir(args) { | ||
| const id = Scratch.Cast.toString(args.ID); | ||
| directions[id] = Scratch.Cast.toNumber(args.DIRECTION); | ||
| } | ||
|
|
||
| vectorChangeMag(args) { | ||
| const id = Scratch.Cast.toString(args.ID); | ||
| magnitudes[id] = Scratch.Cast.toNumber(args.MAGNITUDE); | ||
| } | ||
|
|
||
| vectorMag(args) { | ||
| const id = Scratch.Cast.toString(args.ID); | ||
| return magnitudes[id] !== undefined | ||
| ? magnitudes[id] | ||
| : ""; | ||
| } | ||
|
|
||
| vectorDelete(args) { | ||
| const id = Scratch.Cast.toString(args.ID); | ||
| const index = ids.indexOf(id); | ||
| if (index !== -1) { | ||
| ids.splice(index, 1); | ||
| delete directions[id]; | ||
| delete magnitudes[id]; | ||
| } | ||
| } | ||
|
|
||
| vectorDir(args) { | ||
| const id = Scratch.Cast.toString(args.ID); | ||
| return directions[id] !== undefined | ||
| ? directions[id] | ||
| : Scratch.translate("null"); | ||
| } | ||
|
|
||
| listofIDs() { | ||
| return ids.join(", "); | ||
| } | ||
| } | ||
|
|
||
| Scratch.extensions.register(new UnknownVectors()); | ||
| })(Scratch); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.