mirror of
https://gitlab.com/klmp200/LO27.git
synced 2024-11-05 06:48:03 +00:00
Merge branch 'sli' into 'master'
Swag matrice en SDL See merge request !17
This commit is contained in:
commit
ca359fae1b
@ -1,5 +1,5 @@
|
||||
CC=gcc
|
||||
CFLAGS=-Wall -Werror -pedantic -fpic -g -std=c89
|
||||
CFLAGS=-Wall -Werror -pedantic -fpic -g -std=c89 -Wextra
|
||||
|
||||
|
||||
LIBSDIR=-L/usr/lib -L../Libs
|
||||
|
@ -2,7 +2,7 @@
|
||||
* @Author: klmp200
|
||||
* @Date: 2016-12-27 19:59:21
|
||||
* @Last Modified by: klmp200
|
||||
* @Last Modified time: 2016-12-28 18:48:54
|
||||
* @Last Modified time: 2016-12-28 21:36:39
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
@ -10,10 +10,29 @@
|
||||
#include <SDL2/SDL.h>
|
||||
#include <pixel.h>
|
||||
#include <matrix.h>
|
||||
#include <cellElement.h>
|
||||
|
||||
void SDL_test(){
|
||||
PIXEL test;
|
||||
Matrix gg = CreateMatrix();
|
||||
SetCellValue(gg, 1, 1, true);
|
||||
test.color = 1;
|
||||
void SetPixel(SDL_Renderer *renderer, int x, int y, bool value){
|
||||
|
||||
if (value){
|
||||
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
|
||||
} else {
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
||||
}
|
||||
SDL_RenderDrawPoint(renderer, x, y);
|
||||
}
|
||||
|
||||
void DisplayMatrixSDL(SCREEN *screen, Matrix m){
|
||||
int i;
|
||||
int j;
|
||||
|
||||
SDL_SetRenderDrawColor(screen->renderer, 0, 0, 0, 0);
|
||||
SDL_RenderClear(screen->renderer);
|
||||
|
||||
for (i=0;i<m.rowCount;i++){
|
||||
for (j=0;j<m.colCount;j++){
|
||||
SetPixel(screen->renderer, i, j, GetCellValue(m, j, i));
|
||||
}
|
||||
}
|
||||
SDL_RenderPresent(screen->renderer);
|
||||
}
|
||||
|
@ -2,12 +2,33 @@
|
||||
#define PIXEL_H_INCLUDED
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <cellElement.h>
|
||||
#include <matrix.h>
|
||||
|
||||
typedef struct {
|
||||
SDL_Rect position;
|
||||
Uint8 color;
|
||||
} PIXEL;
|
||||
SDL_Window * window;
|
||||
SDL_Renderer * renderer;
|
||||
int WIDTH;
|
||||
int HEIGHT;
|
||||
SDL_Event event;
|
||||
} SCREEN;
|
||||
|
||||
void SDL_test();
|
||||
/**
|
||||
* Set a pixel on a given screen
|
||||
* @param screen the screen to display the pixel
|
||||
* @param x x position
|
||||
* @param y y position
|
||||
* @param value display white if true and black if false
|
||||
* @return
|
||||
*/
|
||||
void SetPixel(SDL_Renderer *renderer, int x, int y, bool value);
|
||||
|
||||
/**
|
||||
* Display an entire matrix on a given screen
|
||||
* @param screen the screen where the matrix should be displayed
|
||||
* @param m a Matrix
|
||||
* @return
|
||||
*/
|
||||
void DisplayMatrixSDL(SCREEN *screen, Matrix m);
|
||||
|
||||
#endif
|
||||
|
@ -14,8 +14,6 @@ cellElement * CreateCellElem(){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
printf("---Created cellElement---\n");
|
||||
|
||||
elem->nextCol = NULL;
|
||||
elem->nextRow = NULL;
|
||||
|
||||
@ -62,8 +60,6 @@ int AddNextCol(cellElement* tree){
|
||||
|
||||
cellElement * elem = NULL;
|
||||
|
||||
printf("---insertNextCol---\n");
|
||||
|
||||
elem = CreateCellElem();
|
||||
|
||||
if (elem == NULL){
|
||||
@ -78,8 +74,6 @@ int AddNextRow(cellElement* tree){
|
||||
|
||||
cellElement * elem = NULL;
|
||||
|
||||
printf("---insertNextRow---\n");
|
||||
|
||||
elem = CreateCellElem();
|
||||
|
||||
if (elem == NULL){
|
||||
@ -90,7 +84,6 @@ int AddNextRow(cellElement* tree){
|
||||
}
|
||||
|
||||
void removeNextCol(cellElement* tree){
|
||||
printf("---removeNextCol---\n");
|
||||
|
||||
if (tree->nextCol != NULL){
|
||||
free(tree->nextCol);
|
||||
@ -100,7 +93,6 @@ void removeNextCol(cellElement* tree){
|
||||
}
|
||||
|
||||
void removeNextRow(cellElement* tree){
|
||||
printf("---removeNextRow---\n");
|
||||
|
||||
if (tree->nextRow != NULL){
|
||||
free(tree->nextRow);
|
||||
@ -127,8 +119,6 @@ void recursivePrint(cellElement * tree){
|
||||
|
||||
void FreeCellElement(cellElement* element) {
|
||||
|
||||
printf("---FreeCellElement---\n");
|
||||
|
||||
if (element != NULL){
|
||||
free(element);
|
||||
}else{
|
||||
|
@ -299,8 +299,6 @@ Matrix freeMatrix(Matrix matrix){
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
|
||||
printf("\n---FREE MATRIX---\n");
|
||||
|
||||
for (i=0;i<matrix.rowCount;i++){
|
||||
for (j=0;j<matrix.colCount;j++){
|
||||
|
||||
@ -311,7 +309,6 @@ Matrix freeMatrix(Matrix matrix){
|
||||
|
||||
}
|
||||
|
||||
printf("---END OF MATRIX---\n\n");
|
||||
FreeList(matrix.cols);
|
||||
FreeList(matrix.rows);
|
||||
return matrix;
|
||||
@ -536,11 +533,11 @@ bool rightRule(Matrix m, int ColPos, int RowPos){
|
||||
}
|
||||
|
||||
bool topRule(Matrix m, int ColPos, int RowPos){
|
||||
return ErrorToFalse(GetCellValue(m, ColPos, RowPos -1));
|
||||
return ErrorToFalse(GetCellValue(m, ColPos, RowPos + 1));
|
||||
}
|
||||
|
||||
bool bottomRule(Matrix m, int ColPos, int RowPos){
|
||||
return ErrorToFalse(GetCellValue(m, ColPos, RowPos + 1));
|
||||
return ErrorToFalse(GetCellValue(m, ColPos, RowPos - 1));
|
||||
}
|
||||
|
||||
bool top_leftRule(Matrix m, int ColPos, int RowPos){
|
||||
|
2
Makefile
2
Makefile
@ -3,7 +3,7 @@
|
||||
# export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:./Libs
|
||||
|
||||
CC=gcc
|
||||
CFLAGS=-Wall -Werror -pedantic -fpic -g -std=c89
|
||||
CFLAGS=-Wall -Werror -pedantic -fpic -g -std=c89 -Wextra
|
||||
|
||||
EXTLIBS=`sdl2-config --cflags --libs`
|
||||
|
||||
|
79
matrixmain.c
79
matrixmain.c
@ -6,57 +6,58 @@
|
||||
* Description :
|
||||
**********************************************************************************/
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <matrix.h>
|
||||
#include <pixel.h>
|
||||
|
||||
int main(int argc, char **argv){
|
||||
int Rule = 256;
|
||||
int N = 1;
|
||||
int rules[] = {1, 2};
|
||||
Matrix matrix = CreateMatrix();
|
||||
int main(){
|
||||
Matrix m1 = CreateMatrix();
|
||||
int rules[] = {2, 32, 8, 128};
|
||||
Matrix m2;
|
||||
Matrix m3;
|
||||
Matrix m4;
|
||||
BooleanMatrix bmatrix = CreateBooleanMatrix(5, 5);
|
||||
BooleanMatrix bmatrix = CreateBooleanMatrix(300, 300);
|
||||
int keypress = 0;
|
||||
|
||||
SCREEN screen;
|
||||
screen.WIDTH = 300;
|
||||
screen.HEIGHT = 300;
|
||||
|
||||
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0){
|
||||
return 1;
|
||||
}
|
||||
|
||||
SDL_CreateWindowAndRenderer(screen.WIDTH, screen.HEIGHT,
|
||||
SDL_WINDOW_RESIZABLE | SDL_WINDOW_MAXIMIZED | SDL_WINDOW_SHOWN,
|
||||
&(screen.window), &(screen.renderer));
|
||||
if (screen.window == NULL || screen.renderer == NULL){
|
||||
SDL_Quit();
|
||||
return 1;
|
||||
}
|
||||
|
||||
bmatrix = RandomizeBooleanMatrix(bmatrix);
|
||||
m3 = newMatrix(bmatrix);
|
||||
m1 = newMatrix(bmatrix);
|
||||
FreeBooleanMatrix(bmatrix);
|
||||
BasicPrintMatrix(m3);
|
||||
m4 = matrixFromRules(m3, 2, rules);
|
||||
BasicPrintMatrix(m4);
|
||||
freeMatrix(m4);
|
||||
freeMatrix(m3);
|
||||
|
||||
applyRules(matrix,Rule,N);
|
||||
matrix = SetMatrixDim(matrix,3,3);
|
||||
|
||||
BasicPrintMatrix(matrix);
|
||||
|
||||
SetCellValue(matrix,0,0,true);
|
||||
SetCellValue(matrix,0,1,true);
|
||||
SetCellValue(matrix,0,2,true);
|
||||
BasicPrintMatrix(matrix);
|
||||
|
||||
SetCellValue(matrix,0,0,false);
|
||||
SetCellValue(matrix,0,1,false);
|
||||
BasicPrintMatrix(matrix);
|
||||
|
||||
m2 = colSequenceOnMatrix(matrix, OR);
|
||||
BasicPrintMatrix(m2);
|
||||
freeMatrix(m2);
|
||||
m2 = rowSequenceOnMatrix(matrix, AND);
|
||||
BasicPrintMatrix(m2);
|
||||
|
||||
/*sumMatrix(matrix,m2);*/
|
||||
while (!keypress){
|
||||
DisplayMatrixSDL(&screen, m1);
|
||||
while(SDL_PollEvent(&screen.event)){
|
||||
switch (screen.event.type){
|
||||
case SDL_QUIT:
|
||||
keypress = 1;
|
||||
break;
|
||||
case SDL_KEYDOWN:
|
||||
keypress = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m2 = matrixFromRules(m1, 4, rules);
|
||||
freeMatrix(m1);
|
||||
freeMatrix(m2);
|
||||
|
||||
freeMatrix(matrix);
|
||||
return 0;
|
||||
|
||||
}
|
||||
/* todo
|
||||
*modifier DeleteListContent avec sli
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user