mirror of
https://gitlab.com/klmp200/LO27.git
synced 2024-11-22 17:13:20 +00:00
Swag matrice en SDL
This commit is contained in:
parent
5ce36a2607
commit
bededa78c2
@ -1,5 +1,5 @@
|
|||||||
CC=gcc
|
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
|
LIBSDIR=-L/usr/lib -L../Libs
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
* @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-28 18:48:54
|
* @Last Modified time: 2016-12-28 21:36:39
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -10,10 +10,29 @@
|
|||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include <pixel.h>
|
#include <pixel.h>
|
||||||
#include <matrix.h>
|
#include <matrix.h>
|
||||||
|
#include <cellElement.h>
|
||||||
|
|
||||||
void SDL_test(){
|
void SetPixel(SDL_Renderer *renderer, int x, int y, bool value){
|
||||||
PIXEL test;
|
|
||||||
Matrix gg = CreateMatrix();
|
if (value){
|
||||||
SetCellValue(gg, 1, 1, true);
|
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
|
||||||
test.color = 1;
|
} 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
|
#define PIXEL_H_INCLUDED
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
|
#include <cellElement.h>
|
||||||
|
#include <matrix.h>
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
SDL_Rect position;
|
SDL_Window * window;
|
||||||
Uint8 color;
|
SDL_Renderer * renderer;
|
||||||
} PIXEL;
|
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
|
#endif
|
||||||
|
@ -14,8 +14,6 @@ cellElement * CreateCellElem(){
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("---Created cellElement---\n");
|
|
||||||
|
|
||||||
elem->nextCol = NULL;
|
elem->nextCol = NULL;
|
||||||
elem->nextRow = NULL;
|
elem->nextRow = NULL;
|
||||||
|
|
||||||
@ -62,8 +60,6 @@ int AddNextCol(cellElement* tree){
|
|||||||
|
|
||||||
cellElement * elem = NULL;
|
cellElement * elem = NULL;
|
||||||
|
|
||||||
printf("---insertNextCol---\n");
|
|
||||||
|
|
||||||
elem = CreateCellElem();
|
elem = CreateCellElem();
|
||||||
|
|
||||||
if (elem == NULL){
|
if (elem == NULL){
|
||||||
@ -78,8 +74,6 @@ int AddNextRow(cellElement* tree){
|
|||||||
|
|
||||||
cellElement * elem = NULL;
|
cellElement * elem = NULL;
|
||||||
|
|
||||||
printf("---insertNextRow---\n");
|
|
||||||
|
|
||||||
elem = CreateCellElem();
|
elem = CreateCellElem();
|
||||||
|
|
||||||
if (elem == NULL){
|
if (elem == NULL){
|
||||||
@ -90,7 +84,6 @@ int AddNextRow(cellElement* tree){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void removeNextCol(cellElement* tree){
|
void removeNextCol(cellElement* tree){
|
||||||
printf("---removeNextCol---\n");
|
|
||||||
|
|
||||||
if (tree->nextCol != NULL){
|
if (tree->nextCol != NULL){
|
||||||
free(tree->nextCol);
|
free(tree->nextCol);
|
||||||
@ -100,7 +93,6 @@ void removeNextCol(cellElement* tree){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void removeNextRow(cellElement* tree){
|
void removeNextRow(cellElement* tree){
|
||||||
printf("---removeNextRow---\n");
|
|
||||||
|
|
||||||
if (tree->nextRow != NULL){
|
if (tree->nextRow != NULL){
|
||||||
free(tree->nextRow);
|
free(tree->nextRow);
|
||||||
@ -127,8 +119,6 @@ void recursivePrint(cellElement * tree){
|
|||||||
|
|
||||||
void FreeCellElement(cellElement* element) {
|
void FreeCellElement(cellElement* element) {
|
||||||
|
|
||||||
printf("---FreeCellElement---\n");
|
|
||||||
|
|
||||||
if (element != NULL){
|
if (element != NULL){
|
||||||
free(element);
|
free(element);
|
||||||
}else{
|
}else{
|
||||||
|
@ -299,8 +299,6 @@ Matrix freeMatrix(Matrix matrix){
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
int j = 0;
|
int j = 0;
|
||||||
|
|
||||||
printf("\n---FREE MATRIX---\n");
|
|
||||||
|
|
||||||
for (i=0;i<matrix.rowCount;i++){
|
for (i=0;i<matrix.rowCount;i++){
|
||||||
for (j=0;j<matrix.colCount;j++){
|
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.cols);
|
||||||
FreeList(matrix.rows);
|
FreeList(matrix.rows);
|
||||||
return matrix;
|
return matrix;
|
||||||
@ -536,11 +533,11 @@ bool rightRule(Matrix m, int ColPos, int RowPos){
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool topRule(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){
|
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){
|
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
|
# export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:./Libs
|
||||||
|
|
||||||
CC=gcc
|
CC=gcc
|
||||||
CFLAGS=-Wall -Werror -pedantic -fpic -g -std=c89
|
CFLAGS=-Wall -Werror -pedantic -fpic -g -std=c89 -Wextra
|
||||||
|
|
||||||
EXTLIBS=`sdl2-config --cflags --libs`
|
EXTLIBS=`sdl2-config --cflags --libs`
|
||||||
|
|
||||||
|
79
matrixmain.c
79
matrixmain.c
@ -6,57 +6,58 @@
|
|||||||
* Description :
|
* Description :
|
||||||
**********************************************************************************/
|
**********************************************************************************/
|
||||||
|
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <matrix.h>
|
#include <matrix.h>
|
||||||
|
#include <pixel.h>
|
||||||
|
|
||||||
int main(int argc, char **argv){
|
int main(){
|
||||||
int Rule = 256;
|
Matrix m1 = CreateMatrix();
|
||||||
int N = 1;
|
int rules[] = {2, 32, 8, 128};
|
||||||
int rules[] = {1, 2};
|
|
||||||
Matrix matrix = CreateMatrix();
|
|
||||||
Matrix m2;
|
Matrix m2;
|
||||||
Matrix m3;
|
BooleanMatrix bmatrix = CreateBooleanMatrix(300, 300);
|
||||||
Matrix m4;
|
int keypress = 0;
|
||||||
BooleanMatrix bmatrix = CreateBooleanMatrix(5, 5);
|
|
||||||
|
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);
|
bmatrix = RandomizeBooleanMatrix(bmatrix);
|
||||||
m3 = newMatrix(bmatrix);
|
m1 = newMatrix(bmatrix);
|
||||||
FreeBooleanMatrix(bmatrix);
|
FreeBooleanMatrix(bmatrix);
|
||||||
BasicPrintMatrix(m3);
|
|
||||||
m4 = matrixFromRules(m3, 2, rules);
|
|
||||||
BasicPrintMatrix(m4);
|
|
||||||
freeMatrix(m4);
|
|
||||||
freeMatrix(m3);
|
|
||||||
|
|
||||||
applyRules(matrix,Rule,N);
|
while (!keypress){
|
||||||
matrix = SetMatrixDim(matrix,3,3);
|
DisplayMatrixSDL(&screen, m1);
|
||||||
|
while(SDL_PollEvent(&screen.event)){
|
||||||
BasicPrintMatrix(matrix);
|
switch (screen.event.type){
|
||||||
|
case SDL_QUIT:
|
||||||
SetCellValue(matrix,0,0,true);
|
keypress = 1;
|
||||||
SetCellValue(matrix,0,1,true);
|
break;
|
||||||
SetCellValue(matrix,0,2,true);
|
case SDL_KEYDOWN:
|
||||||
BasicPrintMatrix(matrix);
|
keypress = 1;
|
||||||
|
break;
|
||||||
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);*/
|
|
||||||
|
|
||||||
|
m2 = matrixFromRules(m1, 4, rules);
|
||||||
|
freeMatrix(m1);
|
||||||
freeMatrix(m2);
|
freeMatrix(m2);
|
||||||
|
|
||||||
freeMatrix(matrix);
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
/* todo
|
|
||||||
*modifier DeleteListContent avec sli
|
|
||||||
*/
|
|
||||||
|
Loading…
Reference in New Issue
Block a user