Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/ep_layer_letterpress.py
diff options
context:
space:
mode:
authorThomas Jourdan <b.vehikel@googlemail.com>2009-12-06 12:40:41 (GMT)
committer Thomas Jourdan <b.vehikel@googlemail.com>2009-12-06 12:40:41 (GMT)
commit7ce7155dead3893e572006588fc342fb3af7ec60 (patch)
tree2bb234d6d159aa797767bf1ceccea53117dc773a /ep_layer_letterpress.py
parentbcde11455168a07de8a3b17f2a4d77ce8931e75d (diff)
Layers are now arranged as a tree data structure.
Diffstat (limited to 'ep_layer_letterpress.py')
-rw-r--r--ep_layer_letterpress.py70
1 files changed, 31 insertions, 39 deletions
diff --git a/ep_layer_letterpress.py b/ep_layer_letterpress.py
index b607020..526fa18 100644
--- a/ep_layer_letterpress.py
+++ b/ep_layer_letterpress.py
@@ -18,9 +18,11 @@
import random
import pango
import pangocairo
+import ka_debug
import model_layer
-import ka_random
+import model_random
import ka_factory
+import model_locus
import model_constraintpool
import exon_color
import exon_position
@@ -78,12 +80,18 @@ class LetterPress(model_layer.Layer):
self.size = cpool.get(self, FONTSIZE_CONSTRAINT)[0]
self.weight = cpool.get(self, FONTWEIGHT_CONSTRAINT)[0]
self.center = exon_position.Position(self.path, 0.0, 0.0)
-# self.direction_steps = [exon_direction.Direction(self.path, 0.0, 0.0)]
sampler_factory = ka_factory.get_factory('sampler')
sampler_key = sampler_factory.keys()[0]
self.sampler = sampler_factory.create(sampler_key, self.path)
self.buzzwords = exon_buzzword.Buzzword(self.path, [''])
+ def dot(self):
+ result = ""
+ anchor = ka_debug.dot_id(self) + ' -> '
+ for ref in [self.textcolor, self.center, self.sampler, self.buzzwords]:
+ result += ka_debug.dot_ref(anchor, ref)
+ return result
+
def __eq__(self, other):
"""Equality based on the objects components."""
equal = isinstance(other, LetterPress) \
@@ -96,10 +104,6 @@ class LetterPress(model_layer.Layer):
and self.center == other.center \
and self.sampler == other.sampler \
and self.buzzwords == other.buzzwords
-# and len(self.direction_steps) == len(other.direction_steps) \
-# if equal:
-# for index, direction in enumerate(self.direction_steps):
-# equal = equal and direction == other.direction_steps[index]
return equal
def randomize(self):
@@ -112,9 +116,9 @@ class LetterPress(model_layer.Layer):
style_constraint = cpool.get(self, FONTSTYLE_CONSTRAINT)
self.style = random.choice(style_constraint)
size_constraint = cpool.get(self, FONTSIZE_CONSTRAINT)
- self.size = ka_random.randint_constrained(size_constraint)
+ self.size = model_random.randint_constrained(size_constraint)
weight_constraint = cpool.get(self, FONTWEIGHT_CONSTRAINT)
- self.weight = ka_random.randint_constrained(weight_constraint)
+ self.weight = model_random.randint_constrained(weight_constraint)
self.center.randomize()
sampler_factory = ka_factory.get_factory('sampler')
@@ -124,44 +128,35 @@ class LetterPress(model_layer.Layer):
self.sampler.randomize()
self.buzzwords.randomize()
-# self.direction_steps = []
-# for i in range(random.randint(1, 6)):
-# direction = exon_direction.Direction(self.path, 0.0, 0.0)
-# direction.randomize()
-# self.direction_steps.append(direction)
def mutate(self):
"""Make small random changes to the layers components."""
super(LetterPress, self).mutate()
cpool = model_constraintpool.ConstraintPool.get_pool()
self.textcolor.mutate()
- if ka_random.is_mutating():
+ if model_random.is_mutating():
family_constraint = cpool.get(self, FONTFAMILY_CONSTRAINT)
self.family = random.choice(family_constraint)
- if ka_random.is_mutating():
+ if model_random.is_mutating():
style_constraint = cpool.get(self, FONTSTYLE_CONSTRAINT)
self.style = random.choice(style_constraint)
- if ka_random.is_mutating():
+ if model_random.is_mutating():
size_constraint = cpool.get(self, FONTSIZE_CONSTRAINT)
- self.size = ka_random.jitter_discret_constrained(
+ self.size = model_random.jitter_discret_constrained(
self.size, size_constraint)
- if ka_random.is_mutating():
+ if model_random.is_mutating():
weight_constraint = cpool.get(self, FONTWEIGHT_CONSTRAINT)
- self.weight = ka_random.jitter_discret_constrained(
+ self.weight = model_random.jitter_discret_constrained(
self.weight, weight_constraint)
self.center.mutate()
self.sampler.mutate()
self.buzzwords.mutate()
-# for direction in self.direction_steps:
-# direction.mutate()
- def shuffle(self):
- """Shuffle similar componets."""
- super(LetterPress, self).shuffle()
- self.buzzwords.shuffle()
- if ka_random.is_shuffling():
- self.sampler.shuffle()
-# self.direction_steps.shuffle()
+ def swap_places(self):
+ """Shuffle similar components."""
+ self.center.swap_places()
+ self.sampler.swap_places()
+ self.buzzwords.swap_places()
def crossingover(self, other):
"""
@@ -170,19 +165,19 @@ class LetterPress(model_layer.Layer):
# check for distinct references, needs to copy content, not references
post: __return__ is not self
post: __return__ is not other
+ post: model_locus.unique_check(__return__, self, other) == ''
"""
new_one = LetterPress(self.get_trunk())
crossing = self.crossingover_base(new_one, other, 7)
new_one.textcolor = self.textcolor.crossingover(other.textcolor)
- new_one.center = self.center if crossing[0] else other.center
- new_one.sampler = self.sampler if crossing[1] else other.sampler
- new_one.buzzwords = self.buzzwords if crossing[2] else other.buzzwords
+ new_one.center = self.center.crossingover(other.center)
+ new_one.sampler = model_random.crossingover_elem(self.sampler,
+ other.sampler)
+ new_one.buzzwords = self.buzzwords.crossingover(other.buzzwords)
new_one.family = self.family if crossing[3] else other.family
new_one.style = self.style if crossing[4] else other.style
new_one.size = self.size if crossing[5] else other.size
new_one.weight = self.weight if crossing[6] else other.weight
-# new_one.direction_steps = ka_random.crossingover(self.direction_steps, \
-# other.direction_steps)
return new_one
def render(self, ctx, width, height):
@@ -192,7 +187,6 @@ class LetterPress(model_layer.Layer):
pre: height > 0
pre: width == height
"""
-# self.operator = cairo.OPERATOR_OVER
self.begin_render(ctx, width, height)
ctx.scale(1.0/width, 1.0/height)
@@ -223,20 +217,19 @@ class LetterPress(model_layer.Layer):
pango_ctx.show_layout(layout)
def explain(self, formater):
-# super(LetterPress, self).explain(formater)
+ super(LetterPress, self).explain(formater)
formater.text_list('buzzwords: ', self.buzzwords.wordlist)
formater.color_item(self.textcolor, 'text color:')
- formater.text_item(self.family
+ formater.text_item('Font: ' + self.family
+ ', ' + LetterPress.font_style[self.style]
+ ', ' + str(self.size)
+ ', ' + str(self.weight))
formater.position_item(self.center, 'center:')
text, surface, descr = self.sampler.explain()
if surface is not None:
- formater.surface_item(surface, 'sampling points:' + text, descr)
+ formater.surface_item(surface, 'sampling points: ' + text, descr)
else:
formater.text_item(text)
-# formater.direction_array(self.direction_steps, 'direction:')
def copy(self):
"""The LetterPress diagram layers copy constructor.
@@ -253,5 +246,4 @@ class LetterPress(model_layer.Layer):
new_one.center = self.center.copy()
new_one.sampler = self.sampler.copy()
new_one.buzzwords = self.buzzwords.copy()
-# new_one.direction_steps = ka_random.copy_list(self.direction_steps)
return new_one