Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/ep_layer_referencepattern.py
blob: 0487d2c7068f6f4f8c7943fb0cefc5a987556161 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
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