summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2015-05-28 17:35:46 +0200
committerLars-Dominik Braun <lars@6xq.net>2015-05-28 17:43:12 +0200
commitd2b38b16b1c416e160f5442cbcef64d1dd97f5f5 (patch)
treecb8bd9f2b41dbcde20ff7fa0364ba21d80830e02
parenteacf2017413f590e69e841480ae47a9ebdc769cd (diff)
downloadpucket-d2b38b16b1c416e160f5442cbcef64d1dd97f5f5.tar.gz
pucket-d2b38b16b1c416e160f5442cbcef64d1dd97f5f5.tar.bz2
pucket-d2b38b16b1c416e160f5442cbcef64d1dd97f5f5.zip
random: Remove symmetry bias
-rw-r--r--flam3.c23
-rw-r--r--flam3.h2
-rw-r--r--main.c7
-rw-r--r--parser.c2
4 files changed, 10 insertions, 24 deletions
diff --git a/flam3.c b/flam3.c
index ea8a51f..e0e014f 100644
--- a/flam3.c
+++ b/flam3.c
@@ -1320,34 +1320,15 @@ static int compare_xforms(const void *av, const void *bv) {
}
/* sym=2 or more means rotational
- sym=1 means identity, ie no symmetry
- sym=0 means pick a random symmetry (maybe none)
+ sym=1 and sym=0 means identity, ie no symmetry
sym=-1 means bilateral (reflection)
sym=-2 or less means rotational and reflective
*/
-void flam3_add_symmetry(flam3_genome *cp, int sym, randctx * const rc) {
+void flam3_add_symmetry(flam3_genome *cp, int sym) {
int i, j, k;
double a;
int result = 0;
- if (0 == sym) {
- static int sym_distrib[] = {
- -4, -3,
- -2, -2, -2,
- -1, -1, -1,
- 2, 2, 2,
- 3, 3,
- 4, 4,
- };
- if (rand_bool(rc)) {
- sym = rand_distrib(rc, sym_distrib);
- } else if (rand_mod(rc, 32)) {
- sym = rand_mod(rc, 13)-6;
- } else {
- sym = rand_mod(rc, 51)-25;
- }
- }
-
if (1 == sym || 0 == sym) return;
cp->symmetry = sym;
diff --git a/flam3.h b/flam3.h
index 488c963..e7596d7 100644
--- a/flam3.h
+++ b/flam3.h
@@ -457,7 +457,7 @@ void flam3_cross(flam3_genome *cp0, flam3_genome *cp1, flam3_genome *out, int cr
/* return NULL in case of error */
flam3_genome *flam3_parse_xml2(const int, int default_flag, int *ncps, randctx * const);
-void flam3_add_symmetry(flam3_genome *cp, int sym, randctx * const rc);
+void flam3_add_symmetry(flam3_genome *cp, int sym);
void flam3_improve_colors(flam3_genome *g, unsigned int ntries,
bool change_palette,
diff --git a/main.c b/main.c
index ec6205d..8bf0e6c 100644
--- a/main.c
+++ b/main.c
@@ -145,6 +145,7 @@ static void print_genome (flam3_genome * const genome) {
typedef struct {
const char *palette;
unsigned int width, height, max_xforms, max_var;
+ signed int max_symmetry, min_symmetry;
double post_likelihood, final_likelihood, symmetry_likelihood;
} random_arguments;
@@ -277,7 +278,9 @@ static void do_random (const random_arguments * const arguments) {
/* Randomly add symmetry (but not if we've already added a final xform) */
if (rand_d01(&rc) < arguments->symmetry_likelihood && !add_final) {
- flam3_add_symmetry(&genome, 0, &rc);
+ assert (arguments->max_symmetry >= arguments->min_symmetry);
+ unsigned int symrange = arguments->max_symmetry - arguments->min_symmetry + 1;
+ flam3_add_symmetry(&genome, rand_mod (&rc, symrange) + arguments->min_symmetry);
}
/* random resets genome, adjust before finding appropriate bbox */
@@ -635,6 +638,8 @@ int main (int argc, char **argv) {
.post_likelihood = 0.4,
.final_likelihood = 0.15,
.symmetry_likelihood = 0.25,
+ .min_symmetry = -6,
+ .max_symmetry = 6,
};
argp_parse (&argp, argc, argv, 0, NULL, &arguments);
diff --git a/parser.c b/parser.c
index 1c8e060..25e1701 100644
--- a/parser.c
+++ b/parser.c
@@ -603,7 +603,7 @@ static int parse_flame_element(xmlNode *flame_node, flam3_genome *loc_current_cp
}
bef = cp->num_xforms;
- flam3_add_symmetry(cp,kind, rc);
+ flam3_add_symmetry(cp, kind);
aft = cp->num_xforms;
num_std_xforms += (aft-bef);