how to rotation 2d array for tetris?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By bgegg
var array = [
[0,1,0,0],
[0,1,0,0],
[0,1,1,0],
[0,0,0,0]
]

for y in array.size():
    for x in array[y].size():

I want to rotate this for Tetris
Do i need sin or cos?

:bust_in_silhouette: Reply From: estebanmolca

For a square matrix you can do this:

extends Node2D
var m=[]
var n=[]
func _ready():
   	m=[ [1,2,3],
	    [4,5,6], 
		[7,8,9] ]
	
	n=[ [0,0,0],
	    [0,0,0], 
		[0,0,0] ]
			
	print_matrix(m)
	rotate_matriz()
	print_matrix(m)

func rotate_matriz():
	for i in m.size():
		for j in m[i].size():
			n[(m.size()-1)-j][i] = m[i][j]
	m= n
	
func print_matrix(m):
	for i in m.size():
		print(m[i])
	print("--------") 

n[(m.size()-1)-j][i] = m[i][j]
This rotates the matrix 90 degrees to the left. Needs to be implemented the clockwise
rotation and how many times it is rotated.

Thank you
It works well
But I need time to understand

bgegg | 2019-12-21 01:07