diff options
author | Thomas Jourdan <b.vehikel@googlemail.com> | 2010-01-31 16:44:47 (GMT) |
---|---|---|
committer | Thomas Jourdan <b.vehikel@googlemail.com> | 2010-01-31 16:44:47 (GMT) |
commit | c81c18ddf83a97147e1025129a65fe538c34acb7 (patch) | |
tree | 9ac7c2510bfe7dbcc4bf1bc73890cb3f4903c932 /ep_layer_filledspline.py | |
parent | 5997b56f004cea4d7ee344f47e6ba2f41e10f119 (diff) |
improving color scheme
Diffstat (limited to 'ep_layer_filledspline.py')
-rw-r--r-- | ep_layer_filledspline.py | 61 |
1 files changed, 45 insertions, 16 deletions
diff --git a/ep_layer_filledspline.py b/ep_layer_filledspline.py index 314bbb6..656213a 100644 --- a/ep_layer_filledspline.py +++ b/ep_layer_filledspline.py @@ -21,11 +21,11 @@ import ka_factory import model_locus import model_layer import model_constraintpool -import exon_color import exon_position from gettext import gettext as _ SAMPLERTYPE_CONSTRAINT = 'samplertypeconstraint' +COLORGAMUTTYPE_CONSTRAINT = 'colorgamuttypeconstraint' class FilledSpline(model_layer.Layer): """FilledSpline @@ -45,16 +45,23 @@ class FilledSpline(model_layer.Layer): 'min' : 0.1, 'max': 20.0}, {'bind' : SAMPLERTYPE_CONSTRAINT, 'name' : 'Permitted sampler types', - 'domain': model_constraintpool.STRING_1_OF_N, + 'domain': model_constraintpool.STRING_M_OF_N, 'enum' : ka_factory.get_factory('sampler').keys()}, + {'bind' : COLORGAMUTTYPE_CONSTRAINT, + 'name' : 'Permitted color gamut', + 'domain': model_constraintpool.STRING_M_OF_N, + 'enum' : ka_factory.get_factory('colorgamut').keys()}, ] def __init__(self, trunk): """FilledSpline diagram layer constructor""" super(FilledSpline, self).__init__(trunk) cpool = model_constraintpool.ConstraintPool.get_pool() - self.linecolor = exon_color.Color(self.path, 0, 0, 0, 1) - self.fillcolor = exon_color.Color(self.path, 0, 0, 0, 1) + colorgamut_factory = ka_factory.get_factory('colorgamut') + colorgamut_key = colorgamut_factory.keys()[0] + self.colorgamut = colorgamut_factory.create(colorgamut_key, self.path) + self.linecolor = self.colorgamut.get_randomized_color(self.path) + self.fillcolor = self.colorgamut.get_randomized_color(self.path) self.line_width = cpool.get(self, 'line_width')[0] self.roundness = cpool.get(self, 'roundness')[0] self.center = exon_position.Position(self.path, 0.0, 0.0) @@ -65,7 +72,7 @@ class FilledSpline(model_layer.Layer): def dot(self): result = "" anchor = ka_debug.dot_id(self) + ' -> ' - for ref in [self.linecolor, self.fillcolor, self.center, self.sampler]: + for ref in [self.colorgamut, self.linecolor, self.fillcolor, self.center, self.sampler]: result += ka_debug.dot_ref(anchor, ref) return result @@ -78,7 +85,8 @@ class FilledSpline(model_layer.Layer): and self.line_width == other.line_width \ and self.roundness == other.roundness \ and self.center == other.center \ - and self.sampler == other.sampler + and self.sampler == other.sampler \ + and self.colorgamut == other.colorgamut return equal def randomize(self): @@ -87,8 +95,12 @@ class FilledSpline(model_layer.Layer): cpool = model_constraintpool.ConstraintPool.get_pool() line_width_constraint = cpool.get(self, 'line_width') roundness_constraint = cpool.get(self, 'roundness') - self.linecolor.randomize() - self.fillcolor.randomize() + colorgamut_factory = ka_factory.get_factory('colorgamut') + colorgamuttype_constraint = cpool.get(self, COLORGAMUTTYPE_CONSTRAINT) + self.colorgamut = colorgamut_factory.create_random(colorgamuttype_constraint, + self.path) + self.linecolor = self.colorgamut.get_randomized_color(self.path) + self.fillcolor = self.colorgamut.get_randomized_color(self.path) self.line_width = model_random.uniform_constrained(line_width_constraint) self.roundness = model_random.uniform_constrained(roundness_constraint) self.center.randomize() @@ -104,8 +116,9 @@ class FilledSpline(model_layer.Layer): cpool = model_constraintpool.ConstraintPool.get_pool() line_width_constraint = cpool.get(self, 'line_width') roundness_constraint = cpool.get(self, 'roundness') - self.linecolor.mutate() - self.fillcolor.mutate() + self.colorgamut.mutate() + self.colorgamut.mutate_color(self.linecolor) + self.colorgamut.mutate_color(self.fillcolor) self.line_width = model_random.jitter_constrained(self.line_width, line_width_constraint) self.roundness = model_random.jitter_constrained(self.roundness, roundness_constraint) self.center.mutate() @@ -126,14 +139,20 @@ class FilledSpline(model_layer.Layer): post: model_locus.unique_check(__return__, self, other) == '' """ new_one = FilledSpline(self.get_trunk()) - crossing = self.crossingover_base(new_one, other, 2) - new_one.linecolor = self.linecolor.crossingover(other.linecolor) - new_one.fillcolor = self.fillcolor.crossingover(other.fillcolor) - new_one.line_width = self.line_width if crossing[0] else other.line_width - new_one.roundness = self.roundness if crossing[1] else other.roundness + crossing = self.crossingover_base(new_one, other, 3) + if crossing[0]: + new_one.colorgamut = other.colorgamut.copy() + new_one.linecolor = other.linecolor.copy() + new_one.fillcolor = other.fillcolor.copy() + else: + new_one.colorgamut = self.colorgamut.copy() + new_one.linecolor = self.linecolor.copy() + new_one.fillcolor = self.fillcolor.copy() + new_one.line_width = other.line_width if crossing[1] else self.line_width + new_one.roundness = other.roundness if crossing[2] else self.roundness new_one.center = self.center.crossingover(other.center) new_one.sampler = model_random.crossingover_elem(self.sampler, - other.sampler) + other.sampler) return new_one def render(self, task, ctx, width, height): @@ -184,6 +203,7 @@ class FilledSpline(model_layer.Layer): def explain(self, formater): super(FilledSpline, self).explain(formater) + self.colorgamut.explain(formater) formater.color_item(self.linecolor, 'line color:') formater.text_item('line width: ' + str(self.line_width)) formater.text_item('roundness: ' + str(self.roundness)) @@ -208,4 +228,13 @@ class FilledSpline(model_layer.Layer): new_one.roundness = self.roundness new_one.center = self.center.copy() new_one.sampler = self.sampler.copy() + # upgrade from a release older than 'v4' + if self.__dict__.has_key('colorgamut'): + new_one.colorgamut = self.colorgamut.copy() + else: + cpool = model_constraintpool.ConstraintPool.get_pool() + colorgamut_factory = ka_factory.get_factory('colorgamut') + colorgamuttype_constraint = cpool.get(self, COLORGAMUTTYPE_CONSTRAINT) + new_one.colorgamut = colorgamut_factory.create_random(colorgamuttype_constraint, + new_one.path) return new_one |