diff options
Diffstat (limited to 'ep_layer_referencepattern.py')
-rw-r--r-- | ep_layer_referencepattern.py | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/ep_layer_referencepattern.py b/ep_layer_referencepattern.py new file mode 100644 index 0000000..0487d2c --- /dev/null +++ b/ep_layer_referencepattern.py @@ -0,0 +1,123 @@ +# coding: UTF8 +# Copyright 2009 Thomas Jourdan +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +import cairo +import model_layer + +image_list = [] + +class ReferencePattern(model_layer.Layer): + """ReferencePattern + """ + + def __init__(self, trunk): + """Constructor for bitmap image layer.""" + super(ReferencePattern, self).__init__(trunk) + + def __eq__(self, other): + """Equality based on the cells color components.""" + equal = isinstance(other, ReferencePattern) \ + and super(ReferencePattern, self).__eq__(other) + return equal + + def randomize(self): + """Randomize the layers components.""" + super(ReferencePattern, self).randomize() + + def mutate(self): + """Make small random changes to the layers components.""" + super(ReferencePattern, self).mutate() + + def shuffle(self): + """Shuffle similar componets.""" + super(ReferencePattern, self).shuffle() + + def crossingover(self, other): + """ + pre: isinstance(other, ReferencePattern) + pre: isinstance(self, ReferencePattern) + # check for distinct references, needs to copy content, not references + post: __return__ is not self + post: __return__ is not other + """ + new_one = ReferencePattern(self.get_trunk()) + return new_one + + def draw(self, ctx, width, height): + """ + pre: ctx is not None + pre: width > 0 + pre: height > 0 + pre: width == height + """ + self.begin_draw(ctx, width, height) + + ctx.set_source_rgba(1.0, 1.0, 1.0, 0.5) + ctx.rectangle(-0.5, -0.5, 1.0, 1.0) + ctx.fill() + + linear = cairo.LinearGradient(-0.5, -0.5, 1.0, 1.0) + linear.add_color_stop_rgba(0.00, 1.0, 0.0, 0.0, 1.0) + linear.add_color_stop_rgba(1.00, 1.0, 1.0, 0.0, 0.0) + + ctx.rectangle(-0.5, -0.5, 1.0, 1.0) + ctx.set_source(linear) + ctx.fill() + + ctx.set_line_width(0.05) + ctx.set_source_rgba(0.0, 0.0, 0.0, 0.5) + ctx.rectangle(-0.5, -0.5, 1.0, 1.0) + ctx.stroke() + + ctx.set_source_rgba(1.0, 1.0, 1.0, 0.25) + ctx.select_font_face("Sans", + cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_BOLD) + ctx.set_font_size(0.2) + text = 'L' + ctx.move_to(0.0, 0.0) + ctx.show_text(text) + ctx.set_font_size(0.03) + for ix in range(11): + for iy in range(11): + ctx.move_to(ix/10.0-0.5, iy/10.0-0.5) + ctx.show_text(str(ix)+'&'+str(iy)) + + + ctx.set_line_width(0.01) + ctx.set_source_rgba(0.75, 0.75, 0.75, 0.75) + diagonal = 0.05 + ctx.move_to(-diagonal, -diagonal) + ctx.line_to( diagonal, diagonal) + ctx.move_to( diagonal, -diagonal) + ctx.line_to(-diagonal, diagonal) + ctx.stroke() + + def explain(self, formater): + """ + pre: formater is not None + """ +# super(ReferencePattern, self).explain(formater) + pass + + def copy(self): + """The Voronoi diagram layers copy constructor. + # check for distinct references, needs to copy content, not references + post: __return__ is not self + """ + new_one = ReferencePattern(self.get_trunk()) + self.copy_base(new_one) + return new_one |