1
0
mirror of https://gitlab.com/klmp200/LO27.git synced 2024-11-22 22:13:19 +00:00
LO27/matrixmain.c

88 lines
2.3 KiB
C
Raw Normal View History

2016-12-29 15:09:39 +00:00
/*
* This is a cellular automaton library
*
* Copyright (C) 2016-2017 Antoine BARTUCCIO, Jean POREE DE RIDDER
*
* Licensed under the MIT License,(the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* hhttps://opensource.org/licenses/MIT
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
2016-12-10 01:28:10 +00:00
2016-12-28 20:39:42 +00:00
#include <SDL2/SDL.h>
2016-12-10 01:28:10 +00:00
#include <stdio.h>
#include <stdlib.h>
2016-12-13 14:12:55 +00:00
#include <matrix.h>
#include <gui.h>
2016-12-10 20:11:46 +00:00
2016-12-28 20:39:42 +00:00
int main(){
int rule;
int times;
bool useSDL;
bool cont = true;
int col;
int row;
2016-12-29 00:40:50 +00:00
Matrix m1;
2016-12-26 19:44:39 +00:00
Matrix m2;
BooleanMatrix bmatrix;
2017-01-01 23:37:47 +00:00
useSDL = inputYesOrNo("Do you want to use SDL library for matrix display ( interesting for big matrix only ) ?");
2017-01-02 00:16:49 +00:00
printf("Do you prefer : 1. A matrix with random values 2. An example matrix\n");
if (safeNumberInput(1, 2) == 2){
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);
2016-12-26 19:44:39 +00:00
2017-01-02 00:16:49 +00:00
m1 = createMatrix();
m1 = setMatrixDim(m1,col,row);
createSquare(m1);
2016-12-27 21:26:06 +00:00
2017-01-02 00:16:49 +00:00
}else{
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);
m1 = newMatrix(bmatrix);
freeBooleanMatrix(bmatrix);
}
2017-01-01 15:43:40 +00:00
displayMatrixGUI(m1, useSDL);
2016-12-28 20:39:42 +00:00
while (cont){
printf("What rule do you want to apply to this matrix ?\n");
2017-01-01 15:43:40 +00:00
rule = safeNumberInput(1, 481);
printf("How many times do you want the rule to be applied ?\n");
2017-01-01 15:43:40 +00:00
times = safeNumberInput(1, 100000);
m2 = applyRules(m1,rule,times);
freeMatrix(m1);
2016-12-29 00:40:50 +00:00
2017-01-01 15:43:40 +00:00
displayMatrixGUI(m2, useSDL);
2017-01-01 15:43:40 +00:00
cont = inputYesOrNo("Do you want to apply other rules on this matrix ?");
m1 = m2;
}
2016-12-29 00:40:50 +00:00
2016-12-26 19:44:39 +00:00
freeMatrix(m2);
2016-12-10 01:28:10 +00:00
return 0;
2016-12-10 20:11:46 +00:00
2016-12-10 01:28:10 +00:00
}