summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2015-02-17 20:41:20 +0100
committerLars-Dominik Braun <lars@6xq.net>2015-05-02 21:36:45 +0200
commita1066a9c6b1ce4c15626ed1de635453b542ee4c8 (patch)
tree317dd9f894789e897c8bf525a331da90848aa24f
parentaa6c3e00a7f1ad8f2560ca18e17e278cddd9f0ca (diff)
downloadpucket-a1066a9c6b1ce4c15626ed1de635453b542ee4c8.tar.gz
pucket-a1066a9c6b1ce4c15626ed1de635453b542ee4c8.tar.bz2
pucket-a1066a9c6b1ce4c15626ed1de635453b542ee4c8.zip
random: Adjust bounding box
-rw-r--r--main.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/main.c b/main.c
index 0079b82..0917b19 100644
--- a/main.c
+++ b/main.c
@@ -187,6 +187,39 @@ typedef struct {
const char *palette;
} random_arguments;
+#define GOLDEN_RATIO (1.618033988749894848204586834)
+#define GOLDEN_RATIO_M1 (GOLDEN_RATIO-1.0)
+#define GOLDEN_RATIO_DIV (GOLDEN_RATIO_M1/GOLDEN_RATIO)
+static double golden_bit (randctx * const rc) {
+ return rand_bool (rc) ? GOLDEN_RATIO_DIV : GOLDEN_RATIO_M1;
+}
+
+static void adjust_bounding_box (flam3_genome * const genome, randctx * const rc) {
+ double bmin[2], bmax[2];
+ flam3_estimate_bounding_box(genome, 0.01, 100000, bmin, bmax, rc);
+ if (rand_d01(rc) < 0.3) {
+ genome->center[0] = (bmin[0] + bmax[0]) / 2.0;
+ genome->center[1] = (bmin[1] + bmax[1]) / 2.0;
+ } else {
+ double mix0, mix1;
+ if (rand_bool(rc)) {
+ mix0 = golden_bit(rc) + rand_d11(rc)/5;
+ mix1 = golden_bit(rc);
+ } else if (rand_bool(rc)) {
+ mix0 = golden_bit(rc);
+ mix1 = golden_bit(rc) + rand_d11(rc)/5;
+ } else {
+ mix0 = golden_bit(rc) + rand_d11(rc)/5;
+ mix1 = golden_bit(rc) + rand_d11(rc)/5;
+ }
+ genome->center[0] = mix0 * bmin[0] + (1-mix0)*bmax[0];
+ genome->center[1] = mix1 * bmin[1] + (1-mix1)*bmax[1];
+ }
+ genome->rot_center[0] = genome->center[0];
+ genome->rot_center[1] = genome->center[1];
+ genome->pixels_per_unit = genome->width / (bmax[0] - bmin[0]);
+}
+
static void do_random (const random_arguments * const arguments) {
randctx rc;
rand_seed(&rc);
@@ -194,6 +227,7 @@ static void do_random (const random_arguments * const arguments) {
flam3_genome genome = { .edits = NULL };
int ivars = flam3_variation_random;
flam3_random (&genome, &ivars, 1, arguments->symmetry, 0, &rc);
+ adjust_bounding_box (&genome, &rc);
flam3_print (stdout, &genome, NULL, flam3_dont_print_edits);
fflush(stdout);