Files
GRA-Project/Implementierung/tricorn.c
T

39 lines
1.2 KiB
C

#include "tricorn.h"
static const float convergenceLimit = 2.0f;
unsigned converge(float complex position,unsigned n);
void tricorn(float complex start, size_t width, ssize_t height, float res, unsigned n, _Bool color, unsigned char* img){
height = height < 0 ? height*-1 : height;
for(size_t i = 0; i < width; i++){
for(ssize_t j = 0; j < height; j++){
unsigned value = converge(start + (i*res + I*j*res),n);
size_t position = (i*width +j) *3;
if(!color){
img[position] = value;
img[position + 1] = value;
img[position + 2] = value;
}
else{ // TEMPORARY / Bad looking color gradient before testing
img[position] = (value % 85)*3;
img[position + 1] = 85 +(value % 85) * 2;
img[position + 2] = 170 +(value % 85);
}
}
}
}
unsigned converge(float complex position,unsigned n){
complex float result = 0;
for(unsigned i = 0; i < n; i++){
result = cpowf(conjf(result),2) + position;
if(sqrtf(crealf(result)+cimagf(result)) > convergenceLimit)
return 255-4*(i % 64);
}
return 0;
}