66 lines
1.8 KiB
C++
66 lines
1.8 KiB
C++
#include <iostream>
|
|
#include <unistd.h>
|
|
|
|
#define ESC "\x1b"
|
|
#define RIGHE 9
|
|
#define COLONNE 9
|
|
|
|
using namespace std;
|
|
|
|
void riempiMatrice(int matrice[][COLONNE], int righe, int colonne);
|
|
void stampaMatrice(int matrice[][COLONNE], int righe, int colonne);
|
|
void clockWise(int matrice[][COLONNE], int righe);
|
|
|
|
int main(void) {
|
|
int matrice[RIGHE][COLONNE];
|
|
int righe = RIGHE;
|
|
int colonne = COLONNE;
|
|
|
|
riempiMatrice(matrice, righe, colonne);
|
|
stampaMatrice(matrice, righe, colonne);
|
|
|
|
for (int r = 0; r < 12; r++) {
|
|
clockWise(matrice, righe);
|
|
cout << ESC << "[H";
|
|
stampaMatrice(matrice, righe, colonne);
|
|
sleep(1);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
void riempiMatrice(int matrice[][COLONNE], int righe, int colonne) {
|
|
for (int r = 0; r < righe; r++) {
|
|
for (int c = 0; c < colonne; c++) {
|
|
if (r <= righe / 2 && c == colonne / 2) {
|
|
matrice[r][c] = 1;
|
|
} else {
|
|
matrice[r][c] = 0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void stampaMatrice(int matrice[][COLONNE], int righe, int colonne) {
|
|
for (int r = 0; r < righe; r++) {
|
|
cout << endl;
|
|
for (int c = 0; c < colonne; c++) {
|
|
cout << matrice[r][c] << " ";
|
|
}
|
|
}
|
|
}
|
|
|
|
void clockWise(int matrice[][COLONNE], int righe) {
|
|
for (int c = 0; c < righe/2; c++) {
|
|
int temp = matrice[c][righe / 2];
|
|
matrice[c][righe / 2] = matrice[c][c];
|
|
matrice[c][c] = matrice[righe / 2][c];
|
|
matrice[righe / 2][c] = matrice[righe - 1 - c][c];
|
|
matrice[righe - 1 - c][c] = matrice[righe - 1 - c][righe / 2];
|
|
matrice[righe - 1 - c][righe / 2] = matrice[righe - 1 - c][righe - 1 - c];
|
|
matrice[righe - 1 - c][righe - 1 - c] = matrice[righe / 2][righe - 1 - c];
|
|
matrice[righe/2][righe - 1 - c] = matrice[c][righe - 1 - c];
|
|
matrice[c][righe - 1 - c] = matrice[c][righe / 2];
|
|
matrice[c][righe - 1 - c] = temp;
|
|
}
|
|
} |