Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How to rotate a matrix?
- game_pr0grammer
-
500+ posts
How to rotate a matrix?
I am making a pen tetris and the shapes work by using a matrix. This is the matrix for a T-shaped piece.
#1: ~ ~ ~
#2: 1 1 1
#3: ~ 1 ~
I searched up how to make matrices transpose and I programmed it into my game but it doesn't seem to work. Here is my project:
https://beta.scratch.mit.edu/#251889022
I used the scratch 3.0 website because I don't want to publish an unfinished project..
The custom block that rotates the player is called “rotate player ()”
EDIT:
The way that it's supposed to work is by transposing the matrix.
#1: ~ ~ ~
#2: 1 1 1
#3: ~ 1 ~
I searched up how to make matrices transpose and I programmed it into my game but it doesn't seem to work. Here is my project:
https://beta.scratch.mit.edu/#251889022
I used the scratch 3.0 website because I don't want to publish an unfinished project..
The custom block that rotates the player is called “rotate player ()”
EDIT:
The way that it's supposed to work is by transposing the matrix.
Last edited by game_pr0grammer (Dec. 11, 2018 01:08:36)
- deck26
-
1000+ posts
How to rotate a matrix?
Not sure you should be referring to i2 in the ‘set x y of player to id script. Shouldn’t it be i4?
- game_pr0grammer
-
500+ posts
How to rotate a matrix?
no
Last edited by game_pr0grammer (Nov. 18, 2018 16:00:41)
- game_pr0grammer
-
500+ posts
How to rotate a matrix?
i fixed the rotation (it was actually a bug with the set of player block) but now when it rotates two items get removed… why?
- deck26
-
1000+ posts
How to rotate a matrix?
Yes, you replaced i2 with i4 like I suggested by the look of things! i fixed the rotation (it was actually a bug with the set of player block) but now when it rotates two items get removed… why?
- game_pr0grammer
-
500+ posts
How to rotate a matrix?
but now when it rotates two items get removed… why?Yes, you replaced i2 with i4 like I suggested by the look of things! i fixed the rotation (it was actually a bug with the set of player block)
A very astute observation.
- deck26
-
1000+ posts
How to rotate a matrix?
So do you still have a problem? What items are removed?
- game_pr0grammer
-
500+ posts
How to rotate a matrix?
So do you still have a problem?
well obviously.
after further observation, i realized the tetranimo does not actually rotate; it only removes some items. and also, why won't you actually check out the project? What items are removed?
- deck26
-
1000+ posts
How to rotate a matrix?
How do you think I identified the first problem if I didn't look at the project?So do you still have a problem?
well obviously.after further observation, i realized the tetranimo does not actually rotate; it only removes some items. and also, why won't you actually check out the project? What items are removed?
I'm happy to help if you provide enough info for me to do so but you've provided very little so far. You haven't answered my last question which would tell me what's actually happening.
- game_pr0grammer
-
500+ posts
How to rotate a matrix?
When I press “up,” the last item from the two top rows get removed.
When I press “down,” the tetranimo flips up/down, and after that, the last item from the two bottom rows get removed.
When I press “down,” the tetranimo flips up/down, and after that, the last item from the two bottom rows get removed.
- deck26
-
1000+ posts
How to rotate a matrix?
Your custom block ‘set x y of player to id’ should repeat the length of the list item rather than the length minus 1.
I don't know what the first part of your rotate script is supposed to be doing - it identifies letters in the player entries but just puts them back in the same place. It is less confusing if you start i and i2 at 1 instead of 0 - then you don't have to add one every time you use them!
If you swap temp1 and temp2 in the calls to ‘set x y of player to id’ the first part of the script then works but it reflects the array across the diagonal. So I'm still baffled about the first part of that custom block.
If we take that first bit out the code for dir > 0 reflects the array in a vertical line down the middle and dir < 0 reflects it in a horizontal line. So you're mainipulating the array but not in the right way. Use a test array like 123, 456, 789 so you can see this - if you test with something that has symnmetry you might not see what your scripts are doing.
Can you fix it from there?
I don't know what the first part of your rotate script is supposed to be doing - it identifies letters in the player entries but just puts them back in the same place. It is less confusing if you start i and i2 at 1 instead of 0 - then you don't have to add one every time you use them!
If you swap temp1 and temp2 in the calls to ‘set x y of player to id’ the first part of the script then works but it reflects the array across the diagonal. So I'm still baffled about the first part of that custom block.
If we take that first bit out the code for dir > 0 reflects the array in a vertical line down the middle and dir < 0 reflects it in a horizontal line. So you're mainipulating the array but not in the right way. Use a test array like 123, 456, 789 so you can see this - if you test with something that has symnmetry you might not see what your scripts are doing.
Can you fix it from there?
- RokCoder
-
1000+ posts
How to rotate a matrix?
I was playing around with this and @deck26 gave a nice answer while I was doing so. Might as well paste what I came up with anyway 

- game_pr0grammer
-
500+ posts
How to rotate a matrix?
I was playing around with this and @deck26 gave a nice answer while I was doing so. Might as well paste what I came up with anyway
snip
wow that's really complicated since i don't know what each part does
just tell me how to transpose matrices then, please
- game_pr0grammer
-
500+ posts
How to rotate a matrix?
oh nevermind it was just a problem with the set of player block because i was overthinking something
Last edited by game_pr0grammer (Dec. 11, 2018 01:32:39)
- RokCoder
-
1000+ posts
How to rotate a matrix?
just tell me how to transpose matrices then, please
I thought you wanted to rotate the matrix, not transpose it? The above script will rotate your n x m player matrix either clockwise or anticlockwise. Isn't that what you needed for your project?

- game_pr0grammer
-
500+ posts
How to rotate a matrix?
I thought you wanted to rotate the matrix, not transpose it? The above script will rotate your n x m player matrix either clockwise or anticlockwise. Isn't that what you needed for your project?
~ ~ ~ ~ 1 ~
1 1 1 transposed is 1 1 ~
~ 1 ~ ~ 1 ~
the original code was supposed to transpose it and then flip it across an axis based on whether it's rotating counterclockwise or not
- deck26
-
1000+ posts
How to rotate a matrix?
As per my earlier post if you sort out the first part of the rotate script it gives you the transposed matrix - reflection along the main diagonal. So if you want that you nearly had it but you were putting the values you extracted back in the places you got them from.
If you want to talk about rotation/reflection/transposition it is much better if you use a non-symmetrical matrix.
1 2 3
4 5 6
7 8 9
is a much better example as we can then tell the difference between the different operations.
If you want to talk about rotation/reflection/transposition it is much better if you use a non-symmetrical matrix.
could equally well be a rotation 90 degrees anti-clockwise. ~ ~ ~ ~ 1 ~
1 1 1 transposed is 1 1 ~
~ 1 ~ ~ 1 ~
1 2 3
4 5 6
7 8 9
is a much better example as we can then tell the difference between the different operations.
- Discussion Forums
- » Help with Scripts
-
» How to rotate a matrix?