mirror of
https://gitlab.com/klmp200/LO27.git
synced 2024-11-25 18:24:14 +00:00
finished applyrules
This commit is contained in:
parent
3df77c90ae
commit
bfbee069ac
@ -4,24 +4,46 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
Matrix applyRules (Matrix matrix,int Rules, int N){
|
Matrix applyRules (Matrix matrix,int Rules, int N){
|
||||||
int power = 2;
|
int RulesMatrix[9];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
if (Rules <= 0){
|
int power = 2;
|
||||||
|
int sum = 0;
|
||||||
|
int j = 0;
|
||||||
|
Matrix tempMatrix;
|
||||||
|
|
||||||
|
if (Rules <= 0 || N < 1){
|
||||||
return matrix;
|
return matrix;
|
||||||
} else {
|
}
|
||||||
while (Rules%power == 0 ){
|
|
||||||
power*=2;
|
tempMatrix = CreateMatrix();
|
||||||
}
|
|
||||||
for (i=0;i<N;i++){
|
while(power<=512){
|
||||||
printf("Apply rule %d \n",Rules%power);
|
|
||||||
/*Replace it by the implementation of the rules*/
|
RulesMatrix[i] = Rules%power - sum;
|
||||||
|
sum = Rules%power;
|
||||||
|
|
||||||
|
if (RulesMatrix[i]!=0){
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
applyRules(matrix,Rules - Rules%power,N);
|
power*=2;
|
||||||
}
|
}
|
||||||
return matrix;
|
|
||||||
|
/* test code : print decomposition */
|
||||||
|
/*for (j=0;j<i;j++){
|
||||||
|
printf("%d +",RulesMatrix[j]);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
for (j = 0;j<N;j++){
|
||||||
|
freeMatrix(tempMatrix);
|
||||||
|
tempMatrix = matrixFromRules(matrix,i, RulesMatrix);
|
||||||
|
}
|
||||||
|
|
||||||
|
return tempMatrix;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Matrix CreateMatrix(){
|
Matrix CreateMatrix(){
|
||||||
Matrix matrix;
|
Matrix matrix;
|
||||||
matrix.colCount = 0;
|
matrix.colCount = 0;
|
||||||
|
15
matrixmain.c
15
matrixmain.c
@ -13,21 +13,28 @@
|
|||||||
#include <pixel.h>
|
#include <pixel.h>
|
||||||
|
|
||||||
int main(){
|
int main(){
|
||||||
Matrix m1 = CreateMatrix();
|
|
||||||
int rules[] = {2, 32, 8, 128};
|
int Rule34 = 3;
|
||||||
|
Matrix m1;
|
||||||
|
|
||||||
Matrix m2;
|
Matrix m2;
|
||||||
BooleanMatrix bmatrix = CreateBooleanMatrix(300, 300);
|
BooleanMatrix bmatrix = CreateBooleanMatrix(5, 5);
|
||||||
|
|
||||||
bmatrix = RandomizeBooleanMatrix(bmatrix);
|
bmatrix = RandomizeBooleanMatrix(bmatrix);
|
||||||
m1 = newMatrix(bmatrix);
|
m1 = newMatrix(bmatrix);
|
||||||
|
|
||||||
FreeBooleanMatrix(bmatrix);
|
FreeBooleanMatrix(bmatrix);
|
||||||
|
|
||||||
NewWindowFromMatrix(m1);
|
NewWindowFromMatrix(m1);
|
||||||
|
|
||||||
m2 = matrixFromRules(m1, 4, rules);
|
m2 = applyRules(m1,Rule34,3);
|
||||||
|
|
||||||
|
NewWindowFromMatrix(m2);
|
||||||
|
|
||||||
freeMatrix(m1);
|
freeMatrix(m1);
|
||||||
freeMatrix(m2);
|
freeMatrix(m2);
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user