-
Notifications
You must be signed in to change notification settings - Fork 295
Extension: "SVG" #2005
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
base: master
Are you sure you want to change the base?
Extension: "SVG" #2005
Changes from 53 commits
d8d4660
950a9de
3d09c90
a1a7359
e7b0867
a33d0b2
ea8e1e5
e01604f
1188bb5
a2c43fb
537c8c7
5f6b77d
77c3421
4e77dc8
02ebdfd
e4e2c9f
db656c4
2411fe3
46abee7
1ff413f
568253c
8331ebd
bf6a38f
e198545
90d23ab
36f60c6
0831d51
4bfba54
d618b30
c66d90c
926a0b3
70d66d4
487e7ad
e3e9b88
a803ef6
38c8a1f
acecb61
669d9bd
b178019
ea6a2b2
dad2315
acd5f75
ae3eed2
618e2a0
4a4f4f3
f2f0f5a
147f340
fdd49ac
eaa65e7
9fb195b
808a8b5
d06fcd9
7afe800
385cc0f
4fdd134
41ea579
d9f1c7a
50a3324
2645267
0955787
a51e001
a9fa4e1
40cac2a
5b3ee0a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| # SVG | ||
|
|
||
| SVG - это XML язык, который преднозначен для рисования векторых изображений. Изображения бывают двух видов: растровыми и векторными, так вот с помощью SVG можно рисовать именно векторную графику. | ||
|
|
||
| Пример векторного и растрового изображения: | ||
|
|
||
| <img src="https://github.com/WAYLIVES/my-extensions/blob/main/extensions/SVG/doc/11.png"> | ||
|  <i>- Данное изображение принадлежит @WAYLIVES</i> | ||
|
|
||
| ## | ||
|
|
||
| С помощью расширения "SVG" Вы сможете создавать код простых SVG изображений, где будут доступны такие элементы: | ||
| - линия | ||
| - прямоугольник | ||
| - круг | ||
|
|
||
| ## Блоки | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's still a Russian heading here... |
||
| ### SVG-frame: | ||
| ```scratch | ||
| (SVG-frame // width:[100] height:[100] elements in svg:[...] :: #9823FF) | ||
| ``` | ||
| <img src="https://github.com/WAYLIVES/my-extensions/blob/main/extensions/SVG/doc/s1.svg"> | ||
|
|
||
| Без этого блока ничего не будет работать, он задаёт начало и конец векторным изображениям. | ||
|
|
||
| (width) - здесь вы задаёте ширину формата SVG | ||
|
|
||
| (height) - здесь вы задаёте высоту формата SVG | ||
|
|
||
| (elements in svg) - сюда вы можете вставлять SVG элементы, с помощью которых будете рисовать изображения | ||
|
|
||
| ### Line: | ||
|
|
||
| ```scratch | ||
| (LINE // x1, y1:[4][4] x2, y2:[96][96] width:[8] color:[#FF0000] opacity:[100]% dash, gap:[0][0] linecap:[round v] :: #9823FF) | ||
| ``` | ||
| <img src="https://github.com/WAYLIVES/my-extensions/blob/main/extensions/SVG/doc/s2.svg"> | ||
|
|
||
| ### Rect: | ||
|
|
||
| ```scratch | ||
| (RECT // x, y:[4][4] width:[92] height:[92] radius:[20] fill color:[#FF0000] fill opacity:[100]% stroke width:[8] stroke color[#000000] stroke opacity:[100]% dash, gap:[0][0] stroke linecap:[round v] :: #9823FF) | ||
| ``` | ||
| <img src="https://github.com/WAYLIVES/my-extensions/blob/main/extensions/SVG/doc/s3.svg"> | ||
|
|
||
| ### Ellipse: | ||
|
|
||
| ```scratch | ||
| (ELLIPSE // cx, cy:[50][50] width:[92] height:[92] fill color:[#FF0000] fill opacity:[100]% stroke width:[8] stroke color[#000000] stroke opacity:[100]% dash, gap:[0][0] stroke linecap:[round v] :: #9823FF) | ||
| ``` | ||
| <img src="https://github.com/WAYLIVES/my-extensions/blob/main/extensions/SVG/doc/s4.svg"> | ||
|
|
||
| ## Пример-проект | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here. |
||
|
|
||
| ```scratch | ||
| (SVG-frame // width:(100) height:(100) elements in svg:(...)) | ||
| ``` | ||
|
|
||
| <img src="https://github.com/WAYLIVES/my-extensions/blob/main/extensions/SVG/doc/12.png"> | ||
| <img src="https://github.com/WAYLIVES/my-extensions/blob/main/extensions/SVG/doc/13.png"> | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,271 @@ | ||||||
| // Name: SVG | ||||||
| // ID: WRsvg | ||||||
| // Description: Create SVG elements. | ||||||
| // By: WAYLIVES <https://scratch.mit.edu/users/WAYLIVES/> | ||||||
Brackets-Coder marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| // License: MIT | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you choose MIT out of personal preference? |
||||||
|
|
||||||
| // Version: 1.0.1 | ||||||
|
|
||||||
| (function (Scratch) { | ||||||
| "use strict"; | ||||||
|
|
||||||
| if (!Scratch.extensions.unsandboxed) { | ||||||
| throw new Error("This example must run unsandboxed"); | ||||||
|
||||||
| } | ||||||
|
|
||||||
| class svg { | ||||||
| getInfo() { | ||||||
| return { | ||||||
| id: "svg", | ||||||
|
Comment on lines
+16
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the extension ID and class name should match the ID in the given metadata There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| name: Scratch.translate("SVG"), | ||||||
| color1: "#9823FF", | ||||||
| color2: "#7C2DC1", | ||||||
| color3: "#2D3548", | ||||||
| blocks: [ | ||||||
| { | ||||||
| opcode: "svg", | ||||||
| blockType: Scratch.BlockType.REPORTER, | ||||||
| text: Scratch.translate( | ||||||
| "SVG-frame // width: [WIDTH] height: [HEIGHT] elements in svg: [ELEMENTS]" | ||||||
| ), | ||||||
| arguments: { | ||||||
| WIDTH: { | ||||||
| type: Scratch.ArgumentType.NUMBER, | ||||||
| defaultValue: "100", | ||||||
| }, | ||||||
| HEIGHT: { | ||||||
| type: Scratch.ArgumentType.NUMBER, | ||||||
| defaultValue: "100", | ||||||
| }, | ||||||
| ELEMENTS: { | ||||||
| type: Scratch.ArgumentType.STRING, | ||||||
| defaultValue: "<path ... />", | ||||||
| }, | ||||||
| }, | ||||||
| }, | ||||||
|
|
||||||
| "---", | ||||||
|
|
||||||
| { | ||||||
| opcode: "line", | ||||||
| blockType: Scratch.BlockType.REPORTER, | ||||||
| text: Scratch.translate( | ||||||
| "LINE // x1, y1: [XA][YA] x2, y2: [XB][YB] width: [WIDTH] color: [COLOR] opacity: [OPACITY]% dash, gap: [DASH][GAP] linecap: [LINECAP]" | ||||||
| ), | ||||||
| arguments: { | ||||||
| XA: { | ||||||
| type: Scratch.ArgumentType.NUMBER, | ||||||
| defaultValue: "4", | ||||||
| }, | ||||||
| YA: { | ||||||
| type: Scratch.ArgumentType.NUMBER, | ||||||
| defaultValue: "4", | ||||||
| }, | ||||||
| XB: { | ||||||
| type: Scratch.ArgumentType.NUMBER, | ||||||
| defaultValue: "96", | ||||||
| }, | ||||||
| YB: { | ||||||
| type: Scratch.ArgumentType.NUMBER, | ||||||
| defaultValue: "96", | ||||||
| }, | ||||||
| WIDTH: { | ||||||
| type: Scratch.ArgumentType.NUMBER, | ||||||
| defaultValue: "8", | ||||||
| }, | ||||||
| COLOR: { | ||||||
| type: Scratch.ArgumentType.COLOR, | ||||||
| defaultValue: "#ff0000", | ||||||
| }, | ||||||
| OPACITY: { | ||||||
| type: Scratch.ArgumentType.NUMBER, | ||||||
| defaultValue: "100", | ||||||
| }, | ||||||
| DASH: { | ||||||
| type: Scratch.ArgumentType.NUMBER, | ||||||
| defaultValue: "0", | ||||||
| }, | ||||||
| GAP: { | ||||||
| type: Scratch.ArgumentType.NUMBER, | ||||||
| defaultValue: "0", | ||||||
| }, | ||||||
| LINECAP: { | ||||||
| type: Scratch.ArgumentType.STRING, | ||||||
| menu: "LINECAPmenu", | ||||||
| }, | ||||||
| }, | ||||||
| }, | ||||||
|
|
||||||
| { | ||||||
| opcode: "rect", | ||||||
| blockType: Scratch.BlockType.REPORTER, | ||||||
| text: Scratch.translate( | ||||||
| "RECT // x, y: [X][Y] width: [WIDTH] height: [HEIGHT] radius: [RADIUS] fill color: [FILLCOLOR] fill opacity: [FILLOPACITY]% stroke width: [STROKEWIDTH] stroke color: [STROKECOLOR] stroke opacity: [STROKEOPACITY]% dash, gap: [DASH][GAP] stroke linecap: [LINECAP]" | ||||||
| ), | ||||||
| arguments: { | ||||||
| X: { | ||||||
| type: Scratch.ArgumentType.NUMBER, | ||||||
| defaultValue: "4", | ||||||
| }, | ||||||
| Y: { | ||||||
| type: Scratch.ArgumentType.NUMBER, | ||||||
| defaultValue: "4", | ||||||
| }, | ||||||
| WIDTH: { | ||||||
| type: Scratch.ArgumentType.NUMBER, | ||||||
| defaultValue: "92", | ||||||
| }, | ||||||
| HEIGHT: { | ||||||
| type: Scratch.ArgumentType.NUMBER, | ||||||
| defaultValue: "92", | ||||||
| }, | ||||||
| RADIUS: { | ||||||
| type: Scratch.ArgumentType.NUMBER, | ||||||
| defaultValue: "20", | ||||||
| }, | ||||||
| FILLCOLOR: { | ||||||
| type: Scratch.ArgumentType.COLOR, | ||||||
| defaultValue: "#ff0000", | ||||||
| }, | ||||||
| FILLOPACITY: { | ||||||
| type: Scratch.ArgumentType.NUMBER, | ||||||
| defaultValue: "100", | ||||||
| }, | ||||||
| STROKEWIDTH: { | ||||||
| type: Scratch.ArgumentType.NUMBER, | ||||||
| defaultValue: "8", | ||||||
| }, | ||||||
| STROKECOLOR: { | ||||||
| type: Scratch.ArgumentType.COLOR, | ||||||
| defaultValue: "#000000", | ||||||
| }, | ||||||
| STROKEOPACITY: { | ||||||
| type: Scratch.ArgumentType.NUMBER, | ||||||
| defaultValue: "100", | ||||||
| }, | ||||||
| DASH: { | ||||||
| type: Scratch.ArgumentType.NUMBER, | ||||||
| defaultValue: "0", | ||||||
| }, | ||||||
| GAP: { | ||||||
| type: Scratch.ArgumentType.NUMBER, | ||||||
| defaultValue: "0", | ||||||
| }, | ||||||
| LINECAP: { | ||||||
| type: Scratch.ArgumentType.STRING, | ||||||
| menu: "LINECAPmenu", | ||||||
| }, | ||||||
| }, | ||||||
| }, | ||||||
|
|
||||||
| { | ||||||
| opcode: "ellipse", | ||||||
| blockType: Scratch.BlockType.REPORTER, | ||||||
| text: Scratch.translate( | ||||||
| "ELLIPSE // cx, cy: [CX][CY] width: [WIDTH] height: [HEIGHT] fill color: [FILLCOLOR] fill opacity: [FILLOPACITY]% stroke width: [STROKEWIDTH] stroke color: [STROKECOLOR] stroke opacity: [STROKEOPACITY]% dash, gap: [DASH][GAP] stroke linecap: [LINECAP]" | ||||||
| ), | ||||||
| arguments: { | ||||||
| CX: { | ||||||
| type: Scratch.ArgumentType.NUMBER, | ||||||
| defaultValue: "50", | ||||||
| }, | ||||||
| CY: { | ||||||
| type: Scratch.ArgumentType.NUMBER, | ||||||
| defaultValue: "50", | ||||||
| }, | ||||||
| WIDTH: { | ||||||
| type: Scratch.ArgumentType.NUMBER, | ||||||
| defaultValue: "92", | ||||||
| }, | ||||||
| HEIGHT: { | ||||||
| type: Scratch.ArgumentType.NUMBER, | ||||||
| defaultValue: "92", | ||||||
| }, | ||||||
| FILLCOLOR: { | ||||||
| type: Scratch.ArgumentType.COLOR, | ||||||
| defaultValue: "#ff0000", | ||||||
| }, | ||||||
| FILLOPACITY: { | ||||||
| type: Scratch.ArgumentType.NUMBER, | ||||||
| defaultValue: "100", | ||||||
| }, | ||||||
| STROKEWIDTH: { | ||||||
| type: Scratch.ArgumentType.NUMBER, | ||||||
| defaultValue: "8", | ||||||
| }, | ||||||
| STROKECOLOR: { | ||||||
| type: Scratch.ArgumentType.COLOR, | ||||||
| defaultValue: "#000000", | ||||||
| }, | ||||||
| STROKEOPACITY: { | ||||||
| type: Scratch.ArgumentType.NUMBER, | ||||||
| defaultValue: "100", | ||||||
| }, | ||||||
| DASH: { | ||||||
| type: Scratch.ArgumentType.NUMBER, | ||||||
| defaultValue: "0", | ||||||
| }, | ||||||
| GAP: { | ||||||
| type: Scratch.ArgumentType.NUMBER, | ||||||
| defaultValue: "0", | ||||||
| }, | ||||||
| LINECAP: { | ||||||
| type: Scratch.ArgumentType.STRING, | ||||||
| menu: "LINECAPmenu", | ||||||
| }, | ||||||
| }, | ||||||
| }, | ||||||
| ], | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||
| menus: { | ||||||
| LINECAPmenu: { | ||||||
| acceptReporters: true, | ||||||
| items: [ | ||||||
| { | ||||||
| text: Scratch.translate("round"), | ||||||
| value: "round", | ||||||
| }, | ||||||
| { | ||||||
| text: Scratch.translate("butt"), | ||||||
| value: "butt", | ||||||
| }, | ||||||
| { | ||||||
| text: Scratch.translate("square"), | ||||||
| value: "square", | ||||||
| }, | ||||||
| ], | ||||||
| }, | ||||||
Brackets-Coder marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| }, | ||||||
| }; | ||||||
| } | ||||||
|
|
||||||
| svg(args) { | ||||||
Brackets-Coder marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| // prettier-ignore | ||||||
| return ( | ||||||
| '<svg width="' + (args["WIDTH"] + ('" height="' + (args["HEIGHT"] + ('" viewBox="' + ("0 0 " + (args["WIDTH"] + (" " + (args["HEIGHT"] + ('" fill="' + ("none" + ('" xmlns="' + ("http://www.w3.org/2000/svg" + ('">' + args["ELEMENTS"]))))))))))))) + "</svg>" | ||||||
| ); | ||||||
| } | ||||||
|
|
||||||
| line(args) { | ||||||
| // prettier-ignore | ||||||
| return ( | ||||||
| '<line x1="' + (args["XA"] + ('" y1="' + (args["YA"] + ('" x2="' + (args["XB"] + ('" y2="' + (args["YB"] + ('" stroke-width="' + (args["WIDTH"] + ('" stroke="' + (args["COLOR"] + ('" stroke-dasharray="' + (args["DASH"] + (" " + (args["GAP"] + ('" stroke-linecap="' + (args["LINECAP"] + ('" stroke-opacity="' + (args["OPACITY"] / 100 + '"'))))))))))))))))))) + "/>" | ||||||
| ); | ||||||
|
Comment on lines
+254
to
+263
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prettier still decided to format these even though you said ignore... ?? |
||||||
| } | ||||||
|
|
||||||
| rect(args) { | ||||||
| // prettier-ignore | ||||||
| return ( | ||||||
| '<rect x="' + (args["X"] + ('" y="' + (args["Y"] + ('" width="' + (args["WIDTH"] + ('" height="' + (args["HEIGHT"] + ('" rx="' + (args["RADIUS"] + ('" fill="' + (args["FILLCOLOR"] + ('" fill-opacity="' + (args["FILLOPACITY"] / 100 + ('" stroke-width="' + (args["STROKEWIDTH"] + ('" stroke="' + (args["STROKECOLOR"] + ('" stroke-opacity="' + (args["STROKEOPACITY"] / 100 + ('" stroke-dasharray="' + (args["DASH"] + (" " + args["GAP"]) + ('" stroke-linecap="' + (args["LINECAP"] + '"'))))))))))))))))))))))) + "/>" | ||||||
| ); | ||||||
| } | ||||||
|
|
||||||
| ellipse(args) { | ||||||
| // prettier-ignore | ||||||
| return ( | ||||||
| '<ellipse cx="' + (args["CX"] + ('" cy="' + (args["CY"] + ('" rx="' + (args["WIDTH"] / 2 + ('" ry="' + (args["HEIGHT"] / 2 + ('" fill="' + (args["FILLCOLOR"] + ('" fill-opacity="' + (args["FILLOPACITY"] / 100 + ('" stroke-width="' + (args["STROKEWIDTH"] + ('" stroke="' + (args["STROKECOLOR"] + ('" stroke-opacity="' + (args["STROKEOPACITY"] / 100 + ('" stroke-dasharray="' + (args["DASH"] + (" " + args["GAP"]) + ('" stroke-linecap="' + (args["LINECAP"] + '"'))))))))))))))))))))) + "/>" | ||||||
| ); | ||||||
| } | ||||||
| } | ||||||
|
Comment on lines
+252
to
+279
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that is some nasty code out there, it almost looks like Pascal code😭 🙏 |
||||||
|
|
||||||
| Scratch.extensions.register(new svg()); | ||||||
| })(Scratch); | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bro wth are the docs in russian 😭🙏