-
Notifications
You must be signed in to change notification settings - Fork 294
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
Conversation
🖼 NEW EXTENSION IMAGES
!format |
@WAYLIVES |
The fact is that with the help of my extension, you can create a simple SVG code, but this code will not be displayed anywhere, it will be like a variable. |
But with the help of additional extensions, such as "Skins", "Looks+", you can display them on the stage by inserting, so to speak, a variable with an svg code into a specific cell... |
@Brackets-Coder Thank you so much for your help, for your time spent on me. I am very grateful to you! |
You're very welcome |
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.
i may be tough with this review, but your PR has alot of flaws and boilerplate code
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 😭🙏
extensions/WAYLIVES/SVG/1.0.1.js
Outdated
"use strict"; | ||
|
||
if (!Scratch.extensions.unsandboxed) { | ||
throw new Error("This example must run unsandboxed"); |
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.
i think you should put the name of the extension instead
class svg { | ||
getInfo() { | ||
return { | ||
id: "svg", |
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.
the extension ID and class name should match the ID in the given metadata
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 comment
The reason will be displayed to describe this comment to others. Learn more.
- the blocks text are really, really bad and aren't following best practices (especialy if you use //, because that's how you would make comments on javascript)
- why are there so many arguments bro 💀
- the opcodes are too generic and aren't releted to the context of the extension at all.
svg(args) { | ||
// 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 + '"'))))))))))))))))))) + "/>" | ||
); | ||
} | ||
|
||
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"] + '"'))))))))))))))))))))) + "/>" | ||
); | ||
} | ||
} |
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.
that is some nasty code out there, it almost looks like Pascal code😭 🙏
images/WAYLIVES/Window Settings.svg
Outdated
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.
but this should not exist because it's in another PR of yours.
@hammouda101010 Thank you, very mutch! |
!format |
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.
Just a few tiny changes before this can be merged.
Overall it's a good extension, but a few things to consider:
-
It's great for editing SVGs at runtime, but when making complex SVGs, blocks can get very long very quickly. This isn't a problem, but it'd be nice if readability could be improved.
-
Have you thought about adding more SVG shapes, or potentially custom paths? They don't even have to be now, it could be a later update or not at all, just depends on the scope of this extension.
- rectangle | ||
- circle | ||
|
||
## Блоки |
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.
There's still a Russian heading here...
|
||
(linecap) - here you can set the shape of the line ends. | ||
|
||
## Пример-проект |
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.
And here.
// ID: WRsvg | ||
// Description: Create SVG elements. | ||
// By: WAYLIVES <https://scratch.mit.edu/users/WAYLIVES/> | ||
// License: MIT |
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.
Did you choose MIT out of personal preference?
"use strict"; | ||
|
||
if (!Scratch.extensions.unsandboxed) { | ||
throw new Error("svg"); |
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.
throw new Error("svg"); | |
throw new Error("SVG extension must run unsandboxed."); |
class svg { | ||
getInfo() { | ||
return { | ||
id: "svg", |
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.
id: "svg", | |
id: "WRsvg", |
|
||
{ | ||
blockType: Scratch.BlockType.LABEL, | ||
text: Scratch.translate("The basis of SVG:"), |
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.
text: Scratch.translate("The basis of SVG:"), | |
text: Scratch.translate("The basics of SVG"), |
I can't tell if this is supposed to be basics or basis
also, you should remove the colon from every single one of your label blocks
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 + '"'))))))))))))))))))) + "/>" | ||
); |
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.
Prettier still decided to format these even though you said ignore... ??
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.
The thumbnail still looks fantastic, nice job.
Seems to work pretty well |
Extension: "SVG"
With this extension, you can create simple vector images:
Image: