Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » How do I rotate a sprite drawn with pen?
- TheCreatorOfUnTV
-
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:
How do I do something like this:
with the sprite?
- AHypnoman
-
1000+ posts
How do I rotate a sprite drawn with pen?
trig, assuming I've understood (which i frequently don't :P)
Last edited by AHypnoman (Aug. 4, 2024 02:29:24)
- TheCreatorOfUnTV
-
1000+ posts
How do I rotate a sprite drawn with pen?
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). trig, assuming I've understood (which i frequently don't :P)
Last edited by TheCreatorOfUnTV (Aug. 4, 2024 02:35:42)
- AHypnoman
-
1000+ posts
How do I rotate a sprite drawn with pen?
Could you share your code? ~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).
- TheCreatorOfUnTV
-
1000+ posts
How do I rotate a sprite drawn with pen?
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)Could you share your code? ~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).
Anyway, I don't think
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:
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
-
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
-
1000+ posts
How do I rotate a sprite drawn with pen?
It worked, thank you!Close, but not correct. trig, assuming I've understood (which i frequently don't :P)
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.
- AHypnoman
-
1000+ posts
How do I rotate a sprite drawn with pen?
Oh I was assuming they wanted what amounted to a ‘move’ block.Close, but not correct. trig, assuming I've understood (which i frequently don't :P)
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.
As anticipated, I'm wrong :P
I'll report this as resolved
Last edited by AHypnoman (Aug. 4, 2024 19:15:33)
- Discussion Forums
- » Advanced Topics
-
» How do I rotate a sprite drawn with pen?