Added: Unoptimized tricorn algorithm draft
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
CFLAGS= -Wall -Wextra -O3
|
CFLAGS= -Wall -Wextra -O3
|
||||||
|
LDLIBS = -lm
|
||||||
CC = gcc
|
CC = gcc
|
||||||
|
|
||||||
.PHONY: all clean
|
.PHONY: all clean
|
||||||
@@ -6,6 +7,6 @@ CC = gcc
|
|||||||
all: tricorn
|
all: tricorn
|
||||||
|
|
||||||
tricorn: main.c tricorn.c
|
tricorn: main.c tricorn.c
|
||||||
$(CC) $(CFLAGS) -o $@ $^
|
$(CC) $(CFLAGS) -o $@ $^ $(LDLIBS)
|
||||||
clean:
|
clean:
|
||||||
rm -f tricorn
|
rm -f tricorn
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
void save_bmp(const char *filename, unsigned char *img, size_t width, ssize_t height);
|
void save_bmp(const char *filename, unsigned char *img, size_t width, ssize_t height);
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,39 @@
|
|||||||
#include "tricorn.h"
|
#include "tricorn.h"
|
||||||
void tricorn(float complex start, size_t width, size_t height, float res, unsigned n, _Bool color, unsigned char* img){
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
#include <complex.h>
|
#include <complex.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
void tricorn(float complex start, size_t width, size_t height, float res, unsigned n, _Bool color, unsigned char* img);
|
#include <math.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
void tricorn(float complex start, size_t width, ssize_t height, float res, unsigned n, _Bool color, unsigned char* img);
|
||||||
Reference in New Issue
Block a user