aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore4
-rw-r--r--Makefile22
-rw-r--r--README.md3
-rw-r--r--algorithms.h8
-rw-r--r--algorithms/burning-ship-lattice.c31
-rw-r--r--algorithms/burning-ship.c (renamed from bship.c)11
-rw-r--r--algorithms/mandelbrot.c31
-rw-r--r--algorithms/tricorn.c31
-rw-r--r--fractal-gen.c23
-rw-r--r--fractal-gen.h4
-rw-r--r--mbrot.c28
11 files changed, 148 insertions, 48 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..076de85
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+*.o
+*-gen
+*.pgm
+*.png
diff --git a/Makefile b/Makefile
index 2155733..0162825 100644
--- a/Makefile
+++ b/Makefile
@@ -1,20 +1,28 @@
all: fractal-gen symlinks
symlinks: fractal-gen
- ln -sf $< mbrot-gen
- ln -sf $< bship-gen
+ ln -sf $< mandelbrot-gen
+ ln -sf $< burning-ship-gen
+ ln -sf $< burning-ship-lattice-gen
+ ln -sf $< tricorn-gen
+
+fractal-gen: fractal-gen.o \
+ algorithms/mandelbrot.o \
+ algorithms/burning-ship.o \
+ algorithms/burning-ship-lattice.o \
+ algorithms/tricorn.o
-fractal-gen: fractal-gen.o mbrot.o bship.o
$(CC) -o $@ $^ -lm -lpthread
%.o: %.c
$(CC) -c -o $@ $< -Wall -Wextra -Werror
-
.PHONY: all clean symlinks
clean:
rm fractal-gen \
- mbrot-gen \
- bship-gen \
- *.o \
+ mandelbrot-gen \
+ burning-ship-gen \
+ burning-ship-lattice-gen \
+ tricorn-gen \
+ **/*.o \
-f
diff --git a/README.md b/README.md
index c0b8cc5..29337bc 100644
--- a/README.md
+++ b/README.md
@@ -6,8 +6,9 @@ This is a tiny program which will output a binary [PGM](https://wikipedia.org/wi
Syntax
------
- ./mbrot-gen <size> <max_iterations> <power> [threads] > output.pgm
+ ./mandelbrot-gen <size> <max_iterations> <power> [threads] > output.pgm
+Also check out the other algorithms like `tricorn-gen` and `burning-ship-gen`.
You might then want to consider using a tool such as ImageMagick to then convert the (large) output file into something more sane like a PNG.
For the clich&eacute; set you'll want to keep the exponent at 2.
For more info on the exponent, read through [Wikipedia's fine article](http://wikipedia.org/wiki/Mandelbrot_set).
diff --git a/algorithms.h b/algorithms.h
new file mode 100644
index 0000000..d8d2935
--- /dev/null
+++ b/algorithms.h
@@ -0,0 +1,8 @@
+#ifndef GENERATORS_H
+#define GENERATORS_H
+
+void *generate_mandelbrot_section(void *section);
+void *generate_burning_ship_section(void *section);
+void *generate_tricorn_section(void *section);
+
+#endif
diff --git a/algorithms/burning-ship-lattice.c b/algorithms/burning-ship-lattice.c
new file mode 100644
index 0000000..cf80632
--- /dev/null
+++ b/algorithms/burning-ship-lattice.c
@@ -0,0 +1,31 @@
+#include "../fractal-gen.h"
+
+void *generate_burning_ship_lattice_section(void *section)
+{
+ data_section *d = (data_section*)section;
+ unsigned int x,y,i;
+ int idx = 0;
+ double a,b;
+ double complex z,c;
+ double size_units = 0.09f;
+ double top = -0.082f;
+ double left = -1.8f;
+
+ for (y = d->core, b = (d->core*(size_units/d->size)+top); y < d->size; b+=((d->cores*size_units)/d->size), y+=d->cores)
+ {
+ for (x = 0, a = left; x < d->size; a+=(size_units/d->size), x++)
+ {
+ z = 0;
+ c = a+I*b;
+ for (i = 0; i < d->iterat; i++)
+ {
+ if (cabsf(z) >= 2)
+ break;
+
+ z = cpow( cabsf(crealf(z)) + I*cabsf(cimagf(z)) , d->power) + c;
+ }
+ d->data[idx++] = (255*i)/d->iterat;
+ }
+ }
+ return NULL;
+}
diff --git a/bship.c b/algorithms/burning-ship.c
index 1d16ae2..bfbd0a7 100644
--- a/bship.c
+++ b/algorithms/burning-ship.c
@@ -1,16 +1,19 @@
-#include "fractal-gen.h"
+#include "../fractal-gen.h"
-void *generate_bship_section(void *section)
+void *generate_burning_ship_section(void *section)
{
data_section *d = (data_section*)section;
unsigned int x,y,i;
int idx = 0;
double a,b;
double complex z,c;
+ double size_units = 3.5f;
+ double top = -2.2f;
+ double left = -2.2f;
- for (y = d->core, b = (d->core*(3.5f/d->size)-1.75f); y < d->size; b+=((d->cores*3.5f)/d->size), y+=d->cores)
+ for (y = d->core, b = (d->core*(size_units/d->size)+top); y < d->size; b+=((d->cores*size_units)/d->size), y+=d->cores)
{
- for (x = 0, a = -2.5f; x < d->size; a+=(3.5f/d->size), x++)
+ for (x = 0, a = left; x < d->size; a+=(size_units/d->size), x++)
{
z = 0;
c = a+I*b;
diff --git a/algorithms/mandelbrot.c b/algorithms/mandelbrot.c
new file mode 100644
index 0000000..7f8a613
--- /dev/null
+++ b/algorithms/mandelbrot.c
@@ -0,0 +1,31 @@
+#include "../fractal-gen.h"
+
+void *generate_mandelbrot_section(void *section)
+{
+ data_section *d = (data_section*)section;
+ unsigned int x,y,i;
+ int idx = 0;
+ double a,b;
+ double complex z,c;
+ double size_units = 3.5f;
+ double top = -1.75f;
+ double left = -2.5f;
+
+ for (y = d->core, b = (d->core*(size_units/d->size)+top); y < d->size; b+=((d->cores*size_units)/d->size), y+=d->cores)
+ {
+ for (x = 0, a = left; x < d->size; a+=(size_units/d->size), x++)
+ {
+ z = 0;
+ c = a+I*b;
+ for (i = 0; i < d->iterat; i++)
+ {
+ if (cabsf(z) >= 2)
+ break;
+
+ z = cpow(z , d->power) + c;
+ }
+ d->data[idx++] = (255*i)/d->iterat;
+ }
+ }
+ return NULL;
+}
diff --git a/algorithms/tricorn.c b/algorithms/tricorn.c
new file mode 100644
index 0000000..eddc4d6
--- /dev/null
+++ b/algorithms/tricorn.c
@@ -0,0 +1,31 @@
+#include "../fractal-gen.h"
+
+void *generate_tricorn_section(void *section)
+{
+ data_section *d = (data_section*)section;
+ unsigned int x,y,i;
+ int idx = 0;
+ double a,b;
+ double complex z,c;
+ double size_units = 4.f;
+ double top = -2.f;
+ double left = -2.3f;
+
+ for (y = d->core, b = (d->core*(size_units/d->size)+top); y < d->size; b+=((d->cores*size_units)/d->size), y+=d->cores)
+ {
+ for (x = 0, a = left; x < d->size; a+=(size_units/d->size), x++)
+ {
+ z = 0;
+ c = a+I*b;
+ for (i = 0; i < d->iterat; i++)
+ {
+ if (cabsf(z) >= 2)
+ break;
+
+ z = cpow(conj(z) , d->power) + c;
+ }
+ d->data[idx++] = (255*i)/d->iterat;
+ }
+ }
+ return NULL;
+}
diff --git a/fractal-gen.c b/fractal-gen.c
index 6ce9867..10803d9 100644
--- a/fractal-gen.c
+++ b/fractal-gen.c
@@ -1,5 +1,11 @@
#include "fractal-gen.h"
+struct section_generator
+{
+ char *executable_name;
+ void *(*generator)(void *);
+};
+
int main(int argc, char **argv)
{
unsigned int size, iterat, cores, i, x, y;
@@ -8,14 +14,21 @@ int main(int argc, char **argv)
data_section* sections;
void *(*generator)(void *);
+ struct section_generator generators[] = {
+ { "mandelbrot-gen" , &generate_mandelbrot_section },
+ { "burning-ship-gen" , &generate_burning_ship_section },
+ { "tricorn-gen" , &generate_tricorn_section }
+ };
+
// Select correct generator for the fractal type
bname = basename(argv[0]);
- if (strcmp(bname, "mbrot-gen") == 0)
+ generator = NULL;
+ for (i = 0; i < sizeof(generators)/sizeof(struct section_generator); i++)
+ if (strcmp(bname, generators[i].executable_name) == 0)
+ generator = generators[i].generator;
+
+ if (generator == NULL)
{
- generator = &generate_mbrot_section;
- } else if (strcmp(bname, "bship-gen") == 0) {
- generator = &generate_bship_section;
- } else {
fprintf(stderr, "Don't call this directly, call a symlink to me\n");
return EXIT_FAILURE;
}
diff --git a/fractal-gen.h b/fractal-gen.h
index e710606..914c65e 100644
--- a/fractal-gen.h
+++ b/fractal-gen.h
@@ -22,8 +22,6 @@ typedef struct
pthread_t thread;
} data_section;
-void *generate_mbrot_section(void *d);
-void *generate_bship_section(void *d);
-
+#include "algorithms.h"
#endif
diff --git a/mbrot.c b/mbrot.c
deleted file mode 100644
index 6722b55..0000000
--- a/mbrot.c
+++ /dev/null
@@ -1,28 +0,0 @@
-#include "fractal-gen.h"
-
-void *generate_mbrot_section(void *section)
-{
- data_section *d = (data_section*)section;
- unsigned int x,y,i;
- int idx = 0;
- double a,b;
- double complex z,c;
-
- for (y = d->core, b = (d->core*(3.5f/d->size)-1.75f); y < d->size; b+=((d->cores*3.5f)/d->size), y+=d->cores)
- {
- for (x = 0, a = -2.5f; x < d->size; a+=(3.5f/d->size), x++)
- {
- z = 0;
- c = a+I*b;
- for (i = 0; i < d->iterat; i++)
- {
- if (cabsf(z) >= 2)
- break;
-
- z = cpow(z, d->power)+c;
- }
- d->data[idx++] = (255*i)/d->iterat;
- }
- }
- return NULL;
-}