mirror of
				https://gitlab.com/klmp200/LO27.git
				synced 2025-10-30 13:23:52 +00:00 
			
		
		
		
	finished applyrules
This commit is contained in:
		| @@ -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; | ||||
|  | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user