Discuss Scratch

Lu_Li_49
Scratcher
100+ posts

power squared

hello, I would like to know if there is a block
(number)  ² ::operators
in scratch?

Last edited by Lu_Li_49 (Nov. 26, 2024 17:37:13)

200490512jy
Scratcher
11 posts

power squared

Ummmmmmmmmmmmmmmm no but you can make it with
()
Lu_Li_49
Scratcher
100+ posts

power squared

how can I do it?
asdf1546
Scratcher
33 posts

power squared

To get x^2, just use

(((x)) * ((x)))


If you want to take any power, like x^y, try:

([e^ v] of (((y)) * ([ln v] of ((x))::operators))::operators)
Lu_Li_49
Scratcher
100+ posts

power squared

I just wanted to know if there was a block
((number) squared ::operator)
because in this code
([sqrt v] of (((([x v] of [Sprite1 v]) - ([x v] of [Sprite2 v])) * (([x v] of [Sprite1 v]) - ([x v] of [Sprite2 v]))) + ((([y v] of [Sprite1 v]) - ([y v] of [Sprite2 v])) * (([y v] of [Sprite1 v]) - ([y v] of [Sprite2 v]))))::operators)
it's a bit long…



Last edited by Lu_Li_49 (Nov. 26, 2024 18:08:36)

ametrine_
Scratcher
1000+ posts

power squared

Lu_Li_49 wrote:

I just wanted to know if there was a block
((number) squared ::operator)
because in this code
([sqrt v] of (((([x v] of [Sprite1 v]) - ([x v] of [Sprite2 v])) * (([x v] of [Sprite1 v]) - ([x v] of [Sprite2 v]))) + ((([y v] of [Sprite1 v]) - ([y v] of [Sprite2 v])) * (([y v] of [Sprite1 v]) - ([y v] of [Sprite2 v]))))::operators)
it's a bit long…
you might be able to use the (number) * (number) method to get the squared value and put it in a variable, that way you won't have to use the block so many times
medians
Scratcher
1000+ posts

power squared

ametrine_ wrote:

Lu_Li_49 wrote:

I just wanted to know if there was a block
((number) squared ::operator)
because in this code
([sqrt v] of (((([x v] of [Sprite1 v]) - ([x v] of [Sprite2 v])) * (([x v] of [Sprite1 v]) - ([x v] of [Sprite2 v]))) + ((([y v] of [Sprite1 v]) - ([y v] of [Sprite2 v])) * (([y v] of [Sprite1 v]) - ([y v] of [Sprite2 v]))))::operators)
it's a bit long…
you might be able to use the (number) * (number) method to get the squared value and put it in a variable, that way you won't have to use the block so many times
Or sth like this to prevent repeating too
define dist between (sprite 1) and (sprite 2)
set [delta x v] to (([x position v] of (sprite 1)) - ([x position v] of (sprite 2))
set [delta y v] to (([y position v] of (sprite 1)) - ([y position v] of (sprite 2))
set [result v] to ([sqrt v] of (((delta x) * (delta x)) + ((delta y) * (delta y)))
I have no idea why there isn't a report block yet, though you could also have:
define square of (number)
set [result v] to ((number) * (number))
Also, there's already a distance to () blocks if you aren't aware, and the x and y should be “x position” and “y position”

Last edited by medians (Nov. 26, 2024 20:29:33)

Lu_Li_49
Scratcher
100+ posts

power squared

ok, thank you.
THEIMPORTANT
Scratcher
100+ posts

power squared

i can do in 3 blocks

go to [point 1]
set [distance] to (distance to [point2])

why didnt you just that?
SpyCoderX
Scratcher
1000+ posts

power squared

THEIMPORTANT wrote:

i can do in 3 blocks

go to [point 1]
set [distance] to (distance to [point2])

why didnt you just that?
Doesn’t work for distance to a point. (An x y position)

Powered by DjangoBB