From b97b37bd8de949c8f85cb4fdfaefd89fbf7c74da Mon Sep 17 00:00:00 2001 From: Yashar Alan Zenker Date: Tue, 16 Jun 2026 14:48:03 +0200 Subject: [PATCH] Added: Unoptimized tricorn algorithm draft --- Implementierung/Makefile | 3 ++- Implementierung/main.c | 1 + Implementierung/tricorn.c | 37 ++++++++++++++++++++++++++++++++++++- Implementierung/tricorn.h | 4 +++- 4 files changed, 42 insertions(+), 3 deletions(-) diff --git a/Implementierung/Makefile b/Implementierung/Makefile index f2ff980..f8d0de5 100644 --- a/Implementierung/Makefile +++ b/Implementierung/Makefile @@ -1,4 +1,5 @@ CFLAGS= -Wall -Wextra -O3 +LDLIBS = -lm CC = gcc .PHONY: all clean @@ -6,6 +7,6 @@ CC = gcc all: tricorn tricorn: main.c tricorn.c - $(CC) $(CFLAGS) -o $@ $^ + $(CC) $(CFLAGS) -o $@ $^ $(LDLIBS) clean: rm -f tricorn \ No newline at end of file diff --git a/Implementierung/main.c b/Implementierung/main.c index a2888d4..98c0e34 100644 --- a/Implementierung/main.c +++ b/Implementierung/main.c @@ -1,6 +1,7 @@ #include #include #include +#include void save_bmp(const char *filename, unsigned char *img, size_t width, ssize_t height); diff --git a/Implementierung/tricorn.c b/Implementierung/tricorn.c index 1dcdf73..9ead146 100644 --- a/Implementierung/tricorn.c +++ b/Implementierung/tricorn.c @@ -1,4 +1,39 @@ #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; } \ No newline at end of file diff --git a/Implementierung/tricorn.h b/Implementierung/tricorn.h index cb8266c..d415628 100644 --- a/Implementierung/tricorn.h +++ b/Implementierung/tricorn.h @@ -1,3 +1,5 @@ #include #include -void tricorn(float complex start, size_t width, size_t height, float res, unsigned n, _Bool color, unsigned char* img); \ No newline at end of file +#include +#include +void tricorn(float complex start, size_t width, ssize_t height, float res, unsigned n, _Bool color, unsigned char* img); \ No newline at end of file