diff options
author | David <dbphillipsnz@gmail.com> | 2014-05-13 21:17:30 +1200 |
---|---|---|
committer | David <dbphillipsnz@gmail.com> | 2014-05-13 21:17:30 +1200 |
commit | 574df05b9bd100de623b0a0126d935f513ca0f24 (patch) | |
tree | b452b99b15cea4cd29ddf9fa2a41eb73f40ec1bd | |
download | fractal-gen-574df05b9bd100de623b0a0126d935f513ca0f24.tar.xz |
Added all files
-rw-r--r-- | Makefile | 25 | ||||
-rw-r--r-- | config.c | 1 | ||||
-rw-r--r-- | config.h | 3 | ||||
-rwxr-xr-x | gen-pow-imagery | 253 | ||||
-rwxr-xr-x | generate-samples | 50 | ||||
-rw-r--r-- | mbrot-gen.c | 39 | ||||
-rw-r--r-- | raw-to-png.cpp | 111 |
7 files changed, 482 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6e18fac --- /dev/null +++ b/Makefile @@ -0,0 +1,25 @@ +all: config mbrot-gen raw-to-png raw-to-png-bw + +mbrot-gen: + - gcc -o mbrot-gen mbrot-gen.c ./config.so -lm -Wall + +raw-to-png: + - g++ -o raw-to-png raw-to-png.cpp -lm -lGL -lX11 -lpthread -Wall + +raw-to-png-bw: + - g++ -o raw-to-png-bw raw-to-png.cpp -DBW -lm -lGL -lX11 -lpthread -Wall + + +clean: clean-config clean-exec +clean-exec: + - rm mbrot-gen raw-to-png -f + +clean-config: + - rm config.so -f + +config: + - gcc -shared -o config.so config.c + + +samples: + - ./generate-samples diff --git a/config.c b/config.c new file mode 100644 index 0000000..f2c8a32 --- /dev/null +++ b/config.c @@ -0,0 +1 @@ +unsigned int SIZE=1120;unsigned int ITERATIONS=50;float POWER=2.00; diff --git a/config.h b/config.h new file mode 100644 index 0000000..12b650d --- /dev/null +++ b/config.h @@ -0,0 +1,3 @@ +unsigned int SIZE; +unsigned int ITERATIONS; +float POWER; diff --git a/gen-pow-imagery b/gen-pow-imagery new file mode 100755 index 0000000..1d785e3 --- /dev/null +++ b/gen-pow-imagery @@ -0,0 +1,253 @@ +#!/bin/sh + +OUT_DIR="pow_imagery" + +mkdir -p $OUT_DIR + + + +make_sample () { + N="$1-$2-$3pow" + + if [ -e $OUT_DIR/$N.png ]; then + echo $OUT_DIR/$N : Already exists, skipping. + else + # Configure the generator + echo unsigned int SIZE=$1\;unsigned int ITERATIONS=$2\;float POWER=$3\; > config.c + make config + + # Generate raw data + ./mbrot-gen > $OUT_DIR/$N.raw + + # Make normal colour image + ./raw-to-png $OUT_DIR/$N.raw $1 $1 + mv 0,0.png $OUT_DIR/$N.png + + # Make (hypnotic) bw image to show boundaries clearly + ./raw-to-png-bw $OUT_DIR/$N.raw $1 $1 + mv 0,0.png $OUT_DIR/$N-bw.png + + rm $OUT_DIR/$N.raw + fi +} + +make_sample 560 50 0.01 +make_sample 560 50 0.02 +make_sample 560 50 0.03 +make_sample 560 50 0.04 +make_sample 560 50 0.05 +make_sample 560 50 0.06 +make_sample 560 50 0.07 +make_sample 560 50 0.08 +make_sample 560 50 0.09 +make_sample 560 50 0.10 + +make_sample 560 50 0.11 +make_sample 560 50 0.12 +make_sample 560 50 0.13 +make_sample 560 50 0.14 +make_sample 560 50 0.15 +make_sample 560 50 0.16 +make_sample 560 50 0.17 +make_sample 560 50 0.18 +make_sample 560 50 0.19 + +make_sample 560 50 0.20 +make_sample 560 50 0.21 +make_sample 560 50 0.22 +make_sample 560 50 0.23 +make_sample 560 50 0.24 +make_sample 560 50 0.25 +make_sample 560 50 0.26 +make_sample 560 50 0.27 +make_sample 560 50 0.28 +make_sample 560 50 0.29 + +make_sample 560 50 0.30 +make_sample 560 50 0.31 +make_sample 560 50 0.32 +make_sample 560 50 0.33 +make_sample 560 50 0.34 +make_sample 560 50 0.35 +make_sample 560 50 0.36 +make_sample 560 50 0.37 +make_sample 560 50 0.38 +make_sample 560 50 0.39 + +make_sample 560 50 0.40 +make_sample 560 50 0.41 +make_sample 560 50 0.42 +make_sample 560 50 0.43 +make_sample 560 50 0.44 +make_sample 560 50 0.45 +make_sample 560 50 0.46 +make_sample 560 50 0.47 +make_sample 560 50 0.48 +make_sample 560 50 0.49 + +make_sample 560 50 0.50 +make_sample 560 50 0.51 +make_sample 560 50 0.52 +make_sample 560 50 0.53 +make_sample 560 50 0.54 +make_sample 560 50 0.55 +make_sample 560 50 0.56 +make_sample 560 50 0.57 +make_sample 560 50 0.58 +make_sample 560 50 0.59 + +make_sample 560 50 0.60 +make_sample 560 50 0.61 +make_sample 560 50 0.62 +make_sample 560 50 0.63 +make_sample 560 50 0.64 +make_sample 560 50 0.65 +make_sample 560 50 0.66 +make_sample 560 50 0.67 +make_sample 560 50 0.68 +make_sample 560 50 0.69 + +make_sample 560 50 0.70 +make_sample 560 50 0.71 +make_sample 560 50 0.72 +make_sample 560 50 0.73 +make_sample 560 50 0.74 +make_sample 560 50 0.75 +make_sample 560 50 0.76 +make_sample 560 50 0.77 +make_sample 560 50 0.78 +make_sample 560 50 0.79 + +make_sample 560 50 0.80 +make_sample 560 50 0.81 +make_sample 560 50 0.82 +make_sample 560 50 0.83 +make_sample 560 50 0.84 +make_sample 560 50 0.85 +make_sample 560 50 0.86 +make_sample 560 50 0.87 +make_sample 560 50 0.88 +make_sample 560 50 0.89 + +make_sample 560 50 0.90 +make_sample 560 50 0.91 +make_sample 560 50 0.92 +make_sample 560 50 0.93 +make_sample 560 50 0.94 +make_sample 560 50 0.95 +make_sample 560 50 0.96 +make_sample 560 50 0.97 +make_sample 560 50 0.98 +make_sample 560 50 0.99 + +make_sample 560 50 1.00 +make_sample 560 50 1.01 +make_sample 560 50 1.02 +make_sample 560 50 1.03 +make_sample 560 50 1.04 +make_sample 560 50 1.05 +make_sample 560 50 1.06 +make_sample 560 50 1.07 +make_sample 560 50 1.08 +make_sample 560 50 1.09 + +make_sample 560 50 1.10 +make_sample 560 50 1.11 +make_sample 560 50 1.12 +make_sample 560 50 1.13 +make_sample 560 50 1.14 +make_sample 560 50 1.15 +make_sample 560 50 1.16 +make_sample 560 50 1.17 +make_sample 560 50 1.18 +make_sample 560 50 1.19 + +make_sample 560 50 1.20 +make_sample 560 50 1.21 +make_sample 560 50 1.22 +make_sample 560 50 1.23 +make_sample 560 50 1.24 +make_sample 560 50 1.25 +make_sample 560 50 1.26 +make_sample 560 50 1.27 +make_sample 560 50 1.28 +make_sample 560 50 1.29 + +make_sample 560 50 1.30 +make_sample 560 50 1.31 +make_sample 560 50 1.32 +make_sample 560 50 1.33 +make_sample 560 50 1.34 +make_sample 560 50 1.35 +make_sample 560 50 1.36 +make_sample 560 50 1.37 +make_sample 560 50 1.38 +make_sample 560 50 1.39 + +make_sample 560 50 1.40 +make_sample 560 50 1.41 +make_sample 560 50 1.42 +make_sample 560 50 1.43 +make_sample 560 50 1.44 +make_sample 560 50 1.45 +make_sample 560 50 1.46 +make_sample 560 50 1.47 +make_sample 560 50 1.48 +make_sample 560 50 1.49 + +make_sample 560 50 1.50 +make_sample 560 50 1.51 +make_sample 560 50 1.52 +make_sample 560 50 1.53 +make_sample 560 50 1.54 +make_sample 560 50 1.55 +make_sample 560 50 1.56 +make_sample 560 50 1.57 +make_sample 560 50 1.58 +make_sample 560 50 1.59 + +make_sample 560 50 1.60 +make_sample 560 50 1.61 +make_sample 560 50 1.62 +make_sample 560 50 1.63 +make_sample 560 50 1.64 +make_sample 560 50 1.65 +make_sample 560 50 1.66 +make_sample 560 50 1.67 +make_sample 560 50 1.68 +make_sample 560 50 1.69 + +make_sample 560 50 1.70 +make_sample 560 50 1.71 +make_sample 560 50 1.72 +make_sample 560 50 1.73 +make_sample 560 50 1.74 +make_sample 560 50 1.75 +make_sample 560 50 1.76 +make_sample 560 50 1.77 +make_sample 560 50 1.78 +make_sample 560 50 1.79 + +make_sample 560 50 1.80 +make_sample 560 50 1.81 +make_sample 560 50 1.82 +make_sample 560 50 1.83 +make_sample 560 50 1.84 +make_sample 560 50 1.85 +make_sample 560 50 1.86 +make_sample 560 50 1.87 +make_sample 560 50 1.88 +make_sample 560 50 1.89 + +make_sample 560 50 1.90 +make_sample 560 50 1.91 +make_sample 560 50 1.92 +make_sample 560 50 1.93 +make_sample 560 50 1.94 +make_sample 560 50 1.95 +make_sample 560 50 1.96 +make_sample 560 50 1.97 +make_sample 560 50 1.98 +make_sample 560 50 1.99 + +make_sample 560 50 2.00 diff --git a/generate-samples b/generate-samples new file mode 100755 index 0000000..54ccc71 --- /dev/null +++ b/generate-samples @@ -0,0 +1,50 @@ +#!/bin/sh + +OUT_DIR="samples" + +mkdir -p $OUT_DIR + + + +make_sample () { + # Configure the generator + echo unsigned int SIZE=$1\;unsigned int ITERATIONS=$2\;float POWER=$3\; > config.c + make config + + # Generate raw data + ./mbrot-gen > $OUT_DIR/$1-$2-$3pow.raw + + # Make normal colour image + ./raw-to-png $OUT_DIR/$1-$2-$3pow.raw $1 $1 + mv 0,0.png $OUT_DIR/$1-$2.png + + # Make (hypnotic) bw image to show boundaries clearly + ./raw-to-png-bw $OUT_DIR/$1-$2-$3pow.raw $1 $1 + mv 0,0.png $OUT_DIR/$1-$2-$3-pow-bw.png + + rm $OUT_DIR/$1-$2-$3pow.raw +} + +make_sample 35 10 2 +make_sample 70 10 2 +make_sample 140 10 2 +make_sample 280 10 2 +make_sample 560 10 2 +make_sample 1120 10 2 +make_sample 2240 10 2 + +make_sample 35 50 2 +make_sample 70 50 2 +make_sample 140 50 2 +make_sample 280 50 2 +make_sample 560 50 2 +make_sample 1120 50 2 +make_sample 2240 50 2 + +make_sample 35 100 2 +make_sample 70 100 2 +make_sample 140 100 2 +make_sample 280 100 2 +make_sample 560 100 2 +make_sample 1120 100 2 +make_sample 2240 100 2 diff --git a/mbrot-gen.c b/mbrot-gen.c new file mode 100644 index 0000000..cb79f54 --- /dev/null +++ b/mbrot-gen.c @@ -0,0 +1,39 @@ +#include <stdio.h> +#include <complex.h> +#include <math.h> +#include "config.h" + +int main(int argc, char **argv) +{ + unsigned int x, y, i; + float a,b; + float complex z,c; + + fprintf(stderr, "Creating %dx%d image (raw format)\n",SIZE,SIZE); + + y = 0; + for (b = -1.75f; y < SIZE; b+=(3.5f/SIZE)) + { + x = 0; + for (a = -2.5f; x < SIZE; a+=(3.5f/SIZE)) + { + z = 0; + c = a+I*b; + for (i = 0; i < ITERATIONS; i++) + { + if (cabsf(z) >= 2) + break; + + z = cpow(z,POWER)+c; + } + + printf("%c",( (255*i)/ITERATIONS ) ); + x++; + } + y++; + if ( (y%10) == 0 ) + fprintf(stderr,"\r%.3f%%",y/(float)SIZE*100); + } + fprintf(stderr,"\n"); + return 0; +} diff --git a/raw-to-png.cpp b/raw-to-png.cpp new file mode 100644 index 0000000..0a6746e --- /dev/null +++ b/raw-to-png.cpp @@ -0,0 +1,111 @@ +#include <iostream> +#include <stdio.h> +#include <CImg.h> + +//#define TILE_WIDTH 200 +//#define TILE_HEIGHT 200 + +//#define IMAGE_WIDTH 12200 +//#define IMAGE_HEIGHT 12200 + +using namespace cimg_library; + +int main(int argc, char **argv) +{ + unsigned int TILE_SIZE, IMAGE_SIZE, x, y, tile_x, tile_y; + char out_name[] = "________.png"; + + if (argc != 4) + { + printf("%s in_file image_square tile_square\n",argv[0]); + return 1; + } + + IMAGE_SIZE = atoi(argv[2]); + TILE_SIZE = atoi(argv[3]); + + + unsigned char *buf = (unsigned char*)malloc(TILE_SIZE); + + FILE *fp = fopen(argv[1],"r"); + if (!fp) + { + printf("ERROR: Cannot open file\n"); + return 1; + } + + CImg<unsigned char> buffer(TILE_SIZE, TILE_SIZE,1,3,1); + for (tile_y = 0; tile_y < IMAGE_SIZE/TILE_SIZE; tile_y++) + { + for (tile_x = 0; tile_x < IMAGE_SIZE/TILE_SIZE; tile_x++) + { + // Seek to data for start of this tile + #define DATA_Y (tile_y * (TILE_SIZE * TILE_SIZE) * (IMAGE_SIZE / TILE_SIZE)) + #define DATA_X (tile_x * TILE_SIZE) + + fseek(fp, DATA_Y+DATA_X, SEEK_SET); + + printf("Creating tile (%d,%d)...\n", tile_x, tile_y); + + for (y = 0; y < TILE_SIZE; y++) + { + fread(buf, TILE_SIZE, 1, fp); + for (x = 0; x < TILE_SIZE; x++) + { +#ifdef BW + if (buf[x] % 2) + { + buffer(x,y,0) = buffer(x,y,1) = buffer(x,y,2) = 255; + } else { + buffer(x,y,0) = buffer(x,y,1) = buffer(x,y,2) = 0; + } +#else + buffer(x,y,0) = 0; + buffer(x,y,1) = buf[x]; + buffer(x,y,2) = 0; +#endif + } + // Seek and wrap around to next Y pos for tile + fseek(fp, IMAGE_SIZE-TILE_SIZE, SEEK_CUR); + } + sprintf(out_name,"%d,%d.png",tile_x,tile_y); + buffer.save(out_name); + } + } + fclose(fp); + free(buf); +} + + + + + + + + + + + + + + + + + + + + + +//#ifdef BLACK +// if (buf[x] == 255) +// { +// buffer(x,y,0) = 0; +// buffer(x,y,1) = 0; +// buffer(x,y,2) = 0; +// } else { +//#endif + +//#ifdef BLACK +// } +//#endif +// printf("%d,%d\n",x,y); |