Discuss Scratch

TheCreatorOfUnTV
Scratcher
1000+ posts

How do I rotate a sprite drawn with pen?

I want to rotate my sprite, but here's the thing: I can't use the rotate block because I'm drawing it with pen so that it can use arbitrary data for the sprite.
How do I do something like this:
turn15degrees
with the sprite?
AHypnoman
Scratcher
1000+ posts

How do I rotate a sprite drawn with pen?

trig, assuming I've understood (which i frequently don't :P)

gotox:xposition+sinofdirection*distancetomovey:xposition+cosofdirection*distancetomove

Last edited by AHypnoman (Aug. 4, 2024 02:29:24)

TheCreatorOfUnTV
Scratcher
1000+ posts

How do I rotate a sprite drawn with pen?

AHypnoman wrote:

trig, assuming I've understood (which i frequently don't :P)

gotox:xposition+sinofdirection*distancetomovey:xposition+cosofdirection*distancetomove
Great, but that didn't work, it just made the sprite move in a circle around a location (which is not what I'm looking for, I'm looking for the same thing as rotation, but for pen).

Last edited by TheCreatorOfUnTV (Aug. 4, 2024 02:35:42)

AHypnoman
Scratcher
1000+ posts

How do I rotate a sprite drawn with pen?

TheCreatorOfUnTV wrote:

~snip~
Great, but that didn't work, it just made the sprite move in a circle around a location (which is not what I'm looking for, I'm looking for the same thing as rotation, but for pen).
Could you share your code?
TheCreatorOfUnTV
Scratcher
1000+ posts

How do I rotate a sprite drawn with pen?

AHypnoman wrote:

TheCreatorOfUnTV wrote:

~snip~
Great, but that didn't work, it just made the sprite move in a circle around a location (which is not what I'm looking for, I'm looking for the same thing as rotation, but for pen).
Could you share your code?
This project has similar code to the one in my project. (I'm not sharing the project because it is an unfinished update to one of my projects)
Anyway, I don't think

AHypnoman wrote:

gotox:xposition+sinofdirection*distancetomovey:xposition+cosofdirection*distancetomove
has an issue itself (besides the 2 extra x positions which I corrected) but I think it's code for the wrong thing. I'm not looking to move the sprite in a circle around a sprite, I'm looking to rotate the sprite like with this block:
turn15degrees
but I'm using pen, so I have to do something else, and I need to rotate each pixel to do it.

Last edited by TheCreatorOfUnTV (Aug. 4, 2024 16:08:24)

BigNate469
Scratcher
1000+ posts

How do I rotate a sprite drawn with pen?

You could use the script @AHypqnoman provided and apply it to each point's coordinates, if the project you provided is similar enough to what you want.
TheCreatorOfUnTV
Scratcher
1000+ posts

How do I rotate a sprite drawn with pen?

completeness wrote:

AHypnoman wrote:

trig, assuming I've understood (which i frequently don't :P)

gotox:xposition+sinofdirection*distancetomovey:xposition+cosofdirection*distancetomove
Close, but not correct.

Recall the trig identities: sin(x+y) = sin x cos y + cos x sin y, and cos(x+y) = cos x cos y - sin x sin y. You can easily find a proof for these online.
Thus to rotate, the x position you must go to is:
x * cos(direction) - y * sin(direction),
And the y position is:
x * sin(direction) + y * cos(direction)
Too lazy to type it out in Scratchblocks.
It worked, thank you!
AHypnoman
Scratcher
1000+ posts

How do I rotate a sprite drawn with pen?

completeness wrote:

AHypnoman wrote:

trig, assuming I've understood (which i frequently don't :P)

gotox:xposition+sinofdirection*distancetomovey:xposition+cosofdirection*distancetomove
Close, but not correct.

Recall the trig identities: sin(x+y) = sin x cos y + cos x sin y, and cos(x+y) = cos x cos y - sin x sin y. You can easily find a proof for these online.
Thus to rotate, the x position you must go to is:
x * cos(direction) - y * sin(direction),
And the y position is:
x * sin(direction) + y * cos(direction)
Too lazy to type it out in Scratchblocks.
Oh I was assuming they wanted what amounted to a ‘move’ block.

As anticipated, I'm wrong :P

I'll report this as resolved

Last edited by AHypnoman (Aug. 4, 2024 19:15:33)

Powered by DjangoBB