Skip to content

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

Open
wants to merge 64 commits into
base: master
Choose a base branch
from
Open

Extension: "SVG" #2005

wants to merge 64 commits into from

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

// Name: SVG
// ID: WRsvg
// Description: Create SVG elements.
// By: WAYLIVES <https://scratch.mit.edu/users/WAYLIVES/>
Copy link
Contributor

Choose a reason for hiding this comment

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

This is correct

Copy link
Author

Choose a reason for hiding this comment

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

)))

Comment on lines +219 to +236
menus: {
LINECAPmenu: {
acceptReporters: true,
items: [
{
text: Scratch.translate("round"),
value: "round",
},
{
text: Scratch.translate("butt"),
value: "butt",
},
{
text: Scratch.translate("square"),
value: "square",
},
],
},
Copy link
Contributor

Choose a reason for hiding this comment

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

I approve of the new menus, but what is butt supposed to be?

Copy link
Author

Choose a reason for hiding this comment

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

I'll check it out now xD

Copy link
Author

Choose a reason for hiding this comment

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

изображение

Copy link
Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

https://developer.mozilla.org/ru/docs/Web/SVG/Tutorial/Fills_and_Strokes

Ah, that makes sense now. You might want to clarify that in the documentation

Copy link
Author

Choose a reason for hiding this comment

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

Yes, I want to make documentation on this topic, because many people don't understand it.

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

this one is pretty nice

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

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