mirror of
https://gitlab.com/klmp200/LO27.git
synced 2024-11-05 06:48:03 +00:00
left/right/top/down rules
This commit is contained in:
parent
4e4beeab07
commit
581e2e60e8
@ -153,3 +153,18 @@ bool AND(bool a, bool b){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool XOR(bool a, bool b){
|
||||
if (!(a && b) && (a||b)){
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool ErrorToFalse(bool x){
|
||||
if (x == ERROR){
|
||||
return false;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
@ -161,4 +161,19 @@ bool OR(bool a, bool b);
|
||||
*/
|
||||
bool AND(bool a, bool b);
|
||||
|
||||
/**
|
||||
* Apply XOR operator to a bool a and a bool b
|
||||
* @param a a bool
|
||||
* @param b a bool
|
||||
* @return result a and b
|
||||
*/
|
||||
bool XOR(bool a, bool b);
|
||||
|
||||
/**
|
||||
* Return false if the bool is ERROR
|
||||
* @param x a bool
|
||||
* @return result a bool
|
||||
*/
|
||||
bool ErrorToFalse(bool x);
|
||||
|
||||
#endif
|
||||
|
@ -474,6 +474,104 @@ void FreeBooleanMatrix(BooleanMatrix matrix){
|
||||
free(matrix.data);
|
||||
}
|
||||
|
||||
|
||||
Matrix basicRule(Matrix m, int incrh, int incrv){
|
||||
int i;
|
||||
int j;
|
||||
bool a;
|
||||
bool b;
|
||||
Matrix result = CreateMatrix();
|
||||
|
||||
result.colCount = m.colCount;
|
||||
result.rowCount = m.rowCount;
|
||||
|
||||
for (i=0; i < m.rowCount; i++){
|
||||
for (j = 0; j < m.colCount; j++){
|
||||
a = GetCellValue(m, j, i);
|
||||
b = ErrorToFalse(GetCellValue(m, j + incrh, i + incrv));
|
||||
if (XOR(a, b)){
|
||||
SetCellValue(result, j, i, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Matrix leftRule(Matrix m){
|
||||
Matrix result = CreateMatrix();
|
||||
int i;
|
||||
int j;
|
||||
|
||||
result.colCount = m.colCount;
|
||||
result.rowCount = m.rowCount;
|
||||
|
||||
for (i=1;i<m.colCount;i++){
|
||||
for (j=0;j<m.rowCount;j++){
|
||||
if (GetCellValue(m, i, j)){
|
||||
SetCellValue(result, i - 1, j, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Matrix rightRule(Matrix m){
|
||||
Matrix result = CreateMatrix();
|
||||
int i;
|
||||
int j;
|
||||
|
||||
result.colCount = m.colCount;
|
||||
result.rowCount = m.rowCount;
|
||||
|
||||
for (i=0;i<m.colCount - 1;i++){
|
||||
for (j=0;j<m.rowCount;j++){
|
||||
if (GetCellValue(m, i, j)){
|
||||
SetCellValue(result, i + 1, j, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Matrix topRule(Matrix m){
|
||||
Matrix result = CreateMatrix();
|
||||
int i;
|
||||
int j;
|
||||
|
||||
result.colCount = m.colCount;
|
||||
result.rowCount = m.rowCount;
|
||||
|
||||
for (i=1;i<m.rowCount;i++){
|
||||
for (j=0;j<m.colCount;j++){
|
||||
if (GetCellValue(m, j, i)){
|
||||
SetCellValue(result, j, i - 1, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Matrix downRule(Matrix m){
|
||||
Matrix result = CreateMatrix();
|
||||
int i;
|
||||
int j;
|
||||
|
||||
result.colCount = m.colCount;
|
||||
result.rowCount = m.rowCount;
|
||||
|
||||
for (i=0;i<m.rowCount - 1;i++){
|
||||
for (j=0;j<m.colCount;j++){
|
||||
if (GetCellValue(m, j, i)){
|
||||
SetCellValue(result, j, i + 1, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* todos :
|
||||
*mulMatrix
|
||||
*
|
||||
|
@ -230,6 +230,43 @@ Matrix andRowSequenceOnMatrix(Matrix m);
|
||||
* @return matrix the copmuted matrix
|
||||
*/
|
||||
Matrix orRowSequenceOnMatrix(Matrix m);
|
||||
|
||||
/**
|
||||
* Apply XOR on a whole matrix
|
||||
* @param m a matrix
|
||||
* @param incrh the horizontal increment
|
||||
* @param incrv the vertical increment
|
||||
* @return matrix a new modified matrix
|
||||
*/
|
||||
Matrix basicRule(Matrix m, int incrh, int incrv);
|
||||
|
||||
/**
|
||||
* Apply right rule on a matrix
|
||||
* @param m a matrix
|
||||
* @return matrix a new matrix
|
||||
*/
|
||||
Matrix rightRule(Matrix m);
|
||||
|
||||
/**
|
||||
* Apply left rule on a matrix
|
||||
* @param m a matrix
|
||||
* @return matrix a new matrix
|
||||
*/
|
||||
Matrix leftRule(Matrix m);
|
||||
/**
|
||||
* Apply top rule on a matrix
|
||||
* @param m a matrix
|
||||
* @return matrix a new matrix
|
||||
*/
|
||||
Matrix topRule(Matrix m);
|
||||
|
||||
/**
|
||||
* Apply down rule on a matrix
|
||||
* @param m a matrix
|
||||
* @return matrix a new matrix
|
||||
*/
|
||||
Matrix downRule(Matrix m);
|
||||
|
||||
Matrix sumMatrix(Matrix matrix1,Matrix matrix2);
|
||||
|
||||
|
||||
|
5
main.c
5
main.c
@ -9,7 +9,6 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <matrix.h>
|
||||
#include <pixel.c>
|
||||
|
||||
int main(int argc, char **argv){
|
||||
int Rule = 256;
|
||||
@ -17,12 +16,16 @@ int main(int argc, char **argv){
|
||||
Matrix matrix = CreateMatrix();
|
||||
Matrix m2;
|
||||
Matrix m3;
|
||||
Matrix m4;
|
||||
BooleanMatrix bmatrix = CreateBooleanMatrix(5, 5);
|
||||
|
||||
bmatrix = RandomizeBooleanMatrix(bmatrix);
|
||||
m3 = newMatrix(bmatrix);
|
||||
FreeBooleanMatrix(bmatrix);
|
||||
BasicPrintMatrix(m3);
|
||||
m4 = downRule(m3);
|
||||
BasicPrintMatrix(m4);
|
||||
freeMatrix(m4);
|
||||
freeMatrix(m3);
|
||||
|
||||
applyRules(matrix,Rule,N);
|
||||
|
Loading…
Reference in New Issue
Block a user