Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How to modify vectors (SVG) using scratchblocks?
- MyDigitalGarden
-
Scratcher
51 posts
How to modify vectors (SVG) using scratchblocks?
Hello. I was wondering if it's possible, perhaps through an extension.
Last edited by MyDigitalGarden (March 13, 2026 18:38:36)
- N8_D_GR8_1
-
Scratcher
1000+ posts
How to modify vectors (SVG) using scratchblocks?
Hello. I was wondering if it's possible, perhaps through an extension.Do you mean vector graphics (SVGs)? or just normal vectors? If I want to store/modify vectors, I generally just store the x y and z components in separate lists.
EDIT: example code:
when green flag clicked
repeat (4)//adds four vectors to lists
add (pick random (-1.0) to (1.0)) to [ vec. x v]
add (pick random (-1.0) to (1.0)) to [ vec. y v]
add (pick random (-1.0) to (1.0)) to [ vec. y v]
end
To modify the vectors (let's say I want to scale them by 2…
for each [i v] in (length of [vec. x v]){
replace item (i) of [vec. x v] with ((item (i) of [vec. x v])*(2))
replace item (i) of [vec. y v] with ((item (i) of [vec. y v])*(2))
replace item (i) of [vec. z v] with ((item (i) of [vec. z v])*(2))
}@loopArrow::controlIf storing those vectors in the same lists is not practical, you can store them in a new set of lists.
Last edited by N8_D_GR8_1 (March 13, 2026 18:33:57)
- MyDigitalGarden
-
Scratcher
51 posts
How to modify vectors (SVG) using scratchblocks?
Oh. Sorry. I was talking about SVG, but thank you for your comment.Hello. I was wondering if it's possible, perhaps through an extension.Do you mean vector graphics (SVGs)? or just normal vectors? If I want to store/modify vectors, I generally just store the x y and z components in separate lists.
EDIT: example code:when green flag clicked
repeat (4)//adds four vectors to lists
add (pick random (-1.0) to (1.0)) to [ vec. x v]
add (pick random (-1.0) to (1.0)) to [ vec. y v]
add (pick random (-1.0) to (1.0)) to [ vec. y v]
end
To modify the vectors (let's say I want to scale them by 2…for each [i v] in (length of [vec. x v]){
replace item (i) of [vec. x v] with ((item (i) of [vec. x v])*(2))
replace item (i) of [vec. y v] with ((item (i) of [vec. y v])*(2))
replace item (i) of [vec. z v] with ((item (i) of [vec. z v])*(2))
}@loopArrow::control
If storing those vectors in the same lists is not practical, you can store them in a new set of lists.
- MyDigitalGarden
-
Scratcher
51 posts
How to modify vectors (SVG) using scratchblocks?
I will report this forum for inactivity. If I find anything, I will gladly create a new one to notify you.
- Discussion Forums
- » Help with Scripts
-
» How to modify vectors (SVG) using scratchblocks?