mirror of
https://gitlab.com/klmp200/LO27.git
synced 2024-11-25 20:44:15 +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;
|
|
||||||
}
|
|
||||||
for (i=0;i<N;i++){
|
|
||||||
printf("Apply rule %d \n",Rules%power);
|
|
||||||
/*Replace it by the implementation of the rules*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
applyRules(matrix,Rules - Rules%power,N);
|
tempMatrix = CreateMatrix();
|
||||||
|
|
||||||
|
while(power<=512){
|
||||||
|
|
||||||
|
RulesMatrix[i] = Rules%power - sum;
|
||||||
|
sum = Rules%power;
|
||||||
|
|
||||||
|
if (RulesMatrix[i]!=0){
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
return matrix;
|
|
||||||
|
power*=2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 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