mirror of
https://gitlab.com/klmp200/LO27.git
synced 2024-11-26 18:04:14 +00:00
Merge branch 'sli' into 'master'
Ajout d'une gui et correction de l'apply rules See merge request !20
This commit is contained in:
commit
758e64f6cd
@ -7,7 +7,7 @@ INCLUDEDIR=-I/usr/include -I. -I../LibMatrix
|
|||||||
|
|
||||||
#Library variables
|
#Library variables
|
||||||
LIBTARGET=libGui.so
|
LIBTARGET=libGui.so
|
||||||
LIBSOURCE=pixel
|
LIBSOURCE=gui
|
||||||
LIBSOURCECFILE=$(LIBSOURCE:=.c)
|
LIBSOURCECFILE=$(LIBSOURCE:=.c)
|
||||||
LIBSOURCEOFILE=$(LIBSOURCE:=.o)
|
LIBSOURCEOFILE=$(LIBSOURCE:=.o)
|
||||||
|
|
||||||
|
@ -2,15 +2,17 @@
|
|||||||
* @Author: klmp200
|
* @Author: klmp200
|
||||||
* @Date: 2016-12-27 19:59:21
|
* @Date: 2016-12-27 19:59:21
|
||||||
* @Last Modified by: klmp200
|
* @Last Modified by: klmp200
|
||||||
* @Last Modified time: 2016-12-29 00:03:19
|
* @Last Modified time: 2016-12-29 02:51:25
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include <pixel.h>
|
#include <gui.h>
|
||||||
#include <matrix.h>
|
#include <matrix.h>
|
||||||
#include <CellElement.h>
|
#include <CellElement.h>
|
||||||
|
#include <termios.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
void SetPixel(SDL_Renderer *renderer, int x, int y, bool value){
|
void SetPixel(SDL_Renderer *renderer, int x, int y, bool value){
|
||||||
|
|
||||||
@ -88,3 +90,51 @@ int NewWindowFromMatrix(Matrix m){
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool YesOrNo(char message[]){
|
||||||
|
char response;
|
||||||
|
|
||||||
|
printf("%s (Y/n)\n", message);
|
||||||
|
response = getchar();
|
||||||
|
ClearBuffer();
|
||||||
|
|
||||||
|
if (response == 'n'){
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClearBuffer(){
|
||||||
|
char c;
|
||||||
|
while ((c = getchar()) != '\n' && c != EOF) { }
|
||||||
|
}
|
||||||
|
|
||||||
|
void DisplayMatrixGUI(Matrix m, bool useSDL){
|
||||||
|
if (useSDL){
|
||||||
|
printf("Press ENTER or the red cross to exit the window and continue.\n");
|
||||||
|
NewWindowFromMatrix(m);
|
||||||
|
} else {
|
||||||
|
BasicPrintMatrix(m);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int SafeNumberInput(int min, int max){
|
||||||
|
char str[30];
|
||||||
|
int input;
|
||||||
|
|
||||||
|
fgets(str, 29, stdin);
|
||||||
|
ClearBuffer();
|
||||||
|
|
||||||
|
input = atoi(str);
|
||||||
|
|
||||||
|
while (input < min || input > max){
|
||||||
|
printf("The number should be between %d and %d\n", min, max);
|
||||||
|
fgets(str, 29, stdin);
|
||||||
|
ClearBuffer();
|
||||||
|
input = atoi(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
return input;
|
||||||
|
}
|
@ -45,4 +45,33 @@ void WaitUntilEnter(SCREEN * screen);
|
|||||||
*/
|
*/
|
||||||
int NewWindowFromMatrix(Matrix m);
|
int NewWindowFromMatrix(Matrix m);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display a message and ask for yes or no to the user
|
||||||
|
* @param message the message to display
|
||||||
|
* @return bool the answer
|
||||||
|
*/
|
||||||
|
bool YesOrNo(char message[]);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display matrix choosing the right function
|
||||||
|
* @param m a Matrix
|
||||||
|
* @param useSDL a bool
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
void DisplayMatrixGUI(Matrix m, bool useSDL);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a number from the user safely
|
||||||
|
* @param min the minimal authorized number
|
||||||
|
* @param max the maximal authorized number
|
||||||
|
* @return int the input number
|
||||||
|
*/
|
||||||
|
int SafeNumberInput(int min, int max);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears the buffer of stdin
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
void ClearBuffer();
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -9,14 +9,13 @@ Matrix applyRules (Matrix matrix,int Rules, int N){
|
|||||||
int power = 2;
|
int power = 2;
|
||||||
int sum = 0;
|
int sum = 0;
|
||||||
int j = 0;
|
int j = 0;
|
||||||
Matrix tempMatrix;
|
Matrix tempMatrix1;
|
||||||
|
Matrix tempMatrix2;
|
||||||
|
|
||||||
if (Rules <= 0 || N < 1){
|
if (Rules <= 0 || N < 1){
|
||||||
return matrix;
|
return matrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
tempMatrix = CreateMatrix();
|
|
||||||
|
|
||||||
while(power<=512){
|
while(power<=512){
|
||||||
|
|
||||||
RulesMatrix[i] = Rules%power - sum;
|
RulesMatrix[i] = Rules%power - sum;
|
||||||
@ -29,17 +28,20 @@ Matrix applyRules (Matrix matrix,int Rules, int N){
|
|||||||
power*=2;
|
power*=2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* test code : print decomposition */
|
tempMatrix1 = matrixFromRules(matrix, i, RulesMatrix);
|
||||||
/*for (j=0;j<i;j++){
|
|
||||||
printf("%d +",RulesMatrix[j]);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
for (j = 0;j<N;j++){
|
for (j=1;j<N;j++){
|
||||||
freeMatrix(tempMatrix);
|
printf("Tourne\n");
|
||||||
tempMatrix = matrixFromRules(matrix,i, RulesMatrix);
|
tempMatrix2 = matrixFromRules(tempMatrix1,i, RulesMatrix);
|
||||||
|
freeMatrix(tempMatrix1);
|
||||||
|
|
||||||
|
tempMatrix1.colCount = tempMatrix2.colCount;
|
||||||
|
tempMatrix1.rowCount = tempMatrix2.rowCount;
|
||||||
|
tempMatrix1.cols = tempMatrix2.cols;
|
||||||
|
tempMatrix1.rows = tempMatrix2.rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
return tempMatrix;
|
return tempMatrix1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
37
matrixmain.c
37
matrixmain.c
@ -10,28 +10,49 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <matrix.h>
|
#include <matrix.h>
|
||||||
#include <pixel.h>
|
#include <gui.h>
|
||||||
|
|
||||||
int main(){
|
int main(){
|
||||||
|
|
||||||
int Rule34 = 3;
|
int rule;
|
||||||
|
int times;
|
||||||
|
bool useSDL;
|
||||||
|
bool cont = true;
|
||||||
|
int col;
|
||||||
|
int row;
|
||||||
Matrix m1;
|
Matrix m1;
|
||||||
|
|
||||||
Matrix m2;
|
Matrix m2;
|
||||||
BooleanMatrix bmatrix = CreateBooleanMatrix(5, 5);
|
BooleanMatrix bmatrix;
|
||||||
|
|
||||||
|
useSDL = YesOrNo("Do you want to use SDL library for matrix display ?");
|
||||||
|
printf("A random matrix will be generated\n");
|
||||||
|
printf("Enter the number of columns of this matrix\n");
|
||||||
|
col = SafeNumberInput(1, 30000);
|
||||||
|
printf("Enter the number of rows of this matrix\n");
|
||||||
|
row = SafeNumberInput(1, 30000);
|
||||||
|
bmatrix = CreateBooleanMatrix(col, row);
|
||||||
|
|
||||||
bmatrix = RandomizeBooleanMatrix(bmatrix);
|
bmatrix = RandomizeBooleanMatrix(bmatrix);
|
||||||
m1 = newMatrix(bmatrix);
|
m1 = newMatrix(bmatrix);
|
||||||
|
|
||||||
FreeBooleanMatrix(bmatrix);
|
FreeBooleanMatrix(bmatrix);
|
||||||
|
|
||||||
NewWindowFromMatrix(m1);
|
DisplayMatrixGUI(m1, useSDL);
|
||||||
|
|
||||||
m2 = applyRules(m1,Rule34,3);
|
while (cont){
|
||||||
|
printf("What rule do you want to apply to this matrix ?\n");
|
||||||
|
rule = SafeNumberInput(1, 481);
|
||||||
|
printf("How many times do you want the rule to be applied ?\n");
|
||||||
|
times = SafeNumberInput(1, 100000);
|
||||||
|
m2 = applyRules(m1,rule,times);
|
||||||
|
freeMatrix(m1);
|
||||||
|
|
||||||
NewWindowFromMatrix(m2);
|
DisplayMatrixGUI(m2, useSDL);
|
||||||
|
|
||||||
|
cont = YesOrNo("Do you want to apply other rules on this matrix ?");
|
||||||
|
m1 = m2;
|
||||||
|
}
|
||||||
|
|
||||||
freeMatrix(m1);
|
|
||||||
freeMatrix(m2);
|
freeMatrix(m2);
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user