Skip to content

Conversation

WAYLIVES
Copy link

@WAYLIVES WAYLIVES commented Mar 3, 2025

Extension: "SVG"

With this extension, you can create simple vector images:

изображение

Image:

SVG

@github-actions github-actions bot added the pr: new extension Pull requests that add a new extension label Mar 3, 2025
@WAYLIVES
Copy link
Author

WAYLIVES commented Mar 3, 2025

!format

@Brackets-Coder
Copy link
Contributor

@WAYLIVES
I have a question. Are SVG elements rendered as part of the actual scratch stage <canvas> or are they elements overlaying the stage?

@WAYLIVES
Copy link
Author

WAYLIVES commented Mar 4, 2025

@WAYLIVES I have a question. Are SVG elements rendered as part of the actual scratch stage <canvas> or are they elements overlaying the stage?

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.

@WAYLIVES
Copy link
Author

WAYLIVES commented Mar 4, 2025

@WAYLIVES I have a question. Are SVG elements rendered as part of the actual scratch stage <canvas> or are they elements overlaying the stage?

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...

изображение
изображение

@WAYLIVES
Copy link
Author

WAYLIVES commented Mar 4, 2025

@Brackets-Coder Thank you so much for your help, for your time spent on me. I am very grateful to you!

@Brackets-Coder
Copy link
Contributor

@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

Copy link

@hammouda101010 hammouda101010 left a 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

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 😭🙏

"use strict";

if (!Scratch.extensions.unsandboxed) {
throw new Error("This example must run unsandboxed");

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

Comment on lines +16 to +19
class svg {
getInfo() {
return {
id: "svg",

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

Comment on lines 24 to 218
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",
},
},
},
],

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 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)
  2. why are there so many arguments bro 💀
  3. the opcodes are too generic and aren't releted to the context of the extension at all.

Comment on lines +241 to +268
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"] + '"'))))))))))))))))))))) + "/>"
);
}
}

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😭 🙏

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.

@WAYLIVES
Copy link
Author

WAYLIVES commented Mar 5, 2025

@hammouda101010 Thank you, very mutch!

@snowboyz0825
Copy link

well this would've been helpful 2 weeks ago lol, I learned how SVGs work and manually edited them to make an isometric cube
Perfect Isometric Cube

@WAYLIVES
Copy link
Author

WAYLIVES commented Mar 6, 2025

well this would've been helpful 2 weeks ago lol, I learned how SVGs work and manually edited them to make an isometric cube Perfect Isometric Cube

This extension can help those who don't know SVG.

@WAYLIVES
Copy link
Author

WAYLIVES commented Mar 7, 2025

!format

Copy link
Contributor

@Brackets-Coder Brackets-Coder left a 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:

  1. 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.

  2. 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

## Блоки
Copy link
Contributor

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.

## Пример-проект
Copy link
Contributor

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
Copy link
Contributor

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");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
throw new Error("svg");
throw new Error("SVG extension must run unsandboxed.");

class svg {
getInfo() {
return {
id: "svg",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
id: "svg",
id: "WRsvg",


{
blockType: Scratch.BlockType.LABEL,
text: Scratch.translate("The basis of SVG:"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Comment on lines +254 to +263
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 + '"'))))))))))))))))))) + "/>"
);
Copy link
Contributor

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... ??

Copy link
Contributor

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.

@Brackets-Coder
Copy link
Contributor

Seems to work pretty well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr: new extension Pull requests that add a new extension

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants