mirror of
https://gitlab.com/klmp200/LO27.git
synced 2024-12-22 17:11:09 +00:00
Merge branch 'NaejBranch' into 'master'
finished applyrules See merge request !19
This commit is contained in:
commit
b6db74e7ee
@ -4,24 +4,46 @@
|
||||
#include <time.h>
|
||||
|
||||
Matrix applyRules (Matrix matrix,int Rules, int N){
|
||||
int power = 2;
|
||||
int RulesMatrix[9];
|
||||
int i = 0;
|
||||
if (Rules <= 0){
|
||||
int power = 2;
|
||||
int sum = 0;
|
||||
int j = 0;
|
||||
Matrix tempMatrix;
|
||||
|
||||
if (Rules <= 0 || N < 1){
|
||||
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*/
|
||||
}
|
||||
|
||||
tempMatrix = CreateMatrix();
|
||||
|
||||
while(power<=512){
|
||||
|
||||
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 matrix;
|
||||
matrix.colCount = 0;
|
||||
|
15
matrixmain.c
15
matrixmain.c
@ -13,21 +13,28 @@
|
||||
#include <pixel.h>
|
||||
|
||||
int main(){
|
||||
Matrix m1 = CreateMatrix();
|
||||
int rules[] = {2, 32, 8, 128};
|
||||
|
||||
int Rule34 = 3;
|
||||
Matrix m1;
|
||||
|
||||
Matrix m2;
|
||||
BooleanMatrix bmatrix = CreateBooleanMatrix(300, 300);
|
||||
BooleanMatrix bmatrix = CreateBooleanMatrix(5, 5);
|
||||
|
||||
bmatrix = RandomizeBooleanMatrix(bmatrix);
|
||||
m1 = newMatrix(bmatrix);
|
||||
|
||||
FreeBooleanMatrix(bmatrix);
|
||||
|
||||
NewWindowFromMatrix(m1);
|
||||
|
||||
m2 = matrixFromRules(m1, 4, rules);
|
||||
m2 = applyRules(m1,Rule34,3);
|
||||
|
||||
NewWindowFromMatrix(m2);
|
||||
|
||||
freeMatrix(m1);
|
||||
freeMatrix(m2);
|
||||
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user