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 = [

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],
		[7,8,9] ]
	n=[ [0,0,0],
		[0,0,0] ]

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():

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