Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNostalghia <b.vehikel@googlemail.com>2010-07-07 18:26:41 (GMT)
committer Nostalghia <b.vehikel@googlemail.com>2010-07-07 18:26:41 (GMT)
commitccd7b379b7a6fc89630cd3d63ced3d9c886cb4ea (patch)
treefae19bbb494e41c63647ebcc1c5d7a38b4977c8c
parent1b6936f0df2d24ca8032959b47656458750ea8a2 (diff)
Added a stamp painter for simple stars.
-rw-r--r--MANIFEST1
-rw-r--r--ep_stamp_star.py163
-rw-r--r--model_constraintpool.py1
-rw-r--r--po/Kandid.pot16
4 files changed, 180 insertions, 1 deletions
diff --git a/MANIFEST b/MANIFEST
index e79df59..e6c8653 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -150,6 +150,7 @@ ep_sampler_squaregrid.py
ep_stamp_disk.py
ep_stamp_filledcyclic.py
ep_stamp_glyph.py
+ep_stamp_star.py
ep_stamp_svg.py
exon_buzzword.py
exon_color.py
diff --git a/ep_stamp_star.py b/ep_stamp_star.py
new file mode 100644
index 0000000..962cf55
--- /dev/null
+++ b/ep_stamp_star.py
@@ -0,0 +1,163 @@
+# coding: UTF-8
+# Copyright 2009, 2010 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
+
+from gettext import gettext as _
+
+import math
+
+import model_random
+import model_locus
+import model_allele
+import model_constraintpool
+
+ORDER_CONSTRAINT = 'orderconstaint'
+RADIUS_CONSTRAINT = 'radiusconstraint'
+LINE_WIDTH_CONSTRAINT = 'scaleconstraint'
+START_ANGLE_CONSTRAINT = 'dimoutconstraint'
+
+class StarStamp(model_allele.Allele):
+ """StarStamp:.
+ inv: self.radius >= 0.0
+ """
+
+ cdef = [{'bind' : ORDER_CONSTRAINT,
+ 'name' : 'Number of nested disks',
+ 'domain': model_constraintpool.INT_RANGE,
+ 'min' : 3, 'max': 17},
+ {'bind' : RADIUS_CONSTRAINT,
+ 'name' : 'Radius of the filled cyclic polygon or circle',
+ 'domain': model_constraintpool.FLOAT_RANGE,
+ 'min' : 0.01, 'max': 0.33},
+ {'bind' : START_ANGLE_CONSTRAINT,
+ 'name' : 'Rotation of the stamp',
+ 'domain': model_constraintpool.FLOAT_RANGE,
+ 'min' : -math.pi, 'max': math.pi},
+ {'bind' : LINE_WIDTH_CONSTRAINT,
+ 'name' : 'Line width',
+ 'domain': model_constraintpool.FLOAT_RANGE,
+ 'min' : 0.001, 'max': 0.025},
+ ]
+
+ def __init__(self, trunk, dummy):
+ """Constructor for a flip merger."""
+ super(StarStamp, self).__init__(trunk)
+ self.order = 1
+ self.radius = 0.1
+ self.start_angle = 0.0
+ self.line_width = 0.025
+
+ def __eq__(self, other):
+ """Equality based on radius."""
+ equal = isinstance(other, StarStamp) \
+ and self.order == other.order \
+ and self.radius == other.radius \
+ and self.start_angle == other.start_angle \
+ and self.line_width == other.line_width
+ return equal
+
+ def randomize(self):
+ """Randomize the layers components."""
+ cpool = model_constraintpool.ConstraintPool.get_pool()
+ order_constraint = cpool.get(self, ORDER_CONSTRAINT)
+ self.order = model_random.randint_constrained(order_constraint)
+ radius_constraint = cpool.get(self, RADIUS_CONSTRAINT)
+ self.radius = model_random.uniform_constrained(radius_constraint)
+ start_angle_constraint = cpool.get(self, START_ANGLE_CONSTRAINT)
+ self.start_angle = model_random.uniform_constrained(start_angle_constraint)
+ line_width_constraint = cpool.get(self, LINE_WIDTH_CONSTRAINT)
+ self.line_width = model_random.uniform_constrained(line_width_constraint)
+
+ def mutate(self):
+ """Make small random changes to the layers components."""
+ cpool = model_constraintpool.ConstraintPool.get_pool()
+ order_constraint = cpool.get(self, ORDER_CONSTRAINT)
+ self.order = model_random.jitter_discret_constrained(self.order, order_constraint)
+ radius_constraint = cpool.get(self, RADIUS_CONSTRAINT)
+ self.radius = model_random.jitter_constrained(self.radius, radius_constraint)
+ start_angle_constraint = cpool.get(self, START_ANGLE_CONSTRAINT)
+ self.start_angle = model_random.jitter_constrained(self.start_angle, start_angle_constraint)
+ line_width_constraint = cpool.get(self, LINE_WIDTH_CONSTRAINT)
+ self.line_width = model_random.jitter_constrained(self.line_width, line_width_constraint)
+
+ def swap_places(self):
+ """Nothing to do."""
+
+ def crossingover(self, other):
+ """
+ pre: isinstance(other, StarStamp)
+ pre: isinstance(self, StarStamp)
+ # 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 = StarStamp(self.get_trunk(), -1)
+ cross_sequence = model_random.crossing_sequence(4)
+ new_one.order = self.order if cross_sequence[0] else other.order
+ new_one.radius = self.radius if cross_sequence[1] else other.radius
+ new_one.start_angle = self.start_angle if cross_sequence[2] else other.start_angle
+ new_one.line_width = self.line_width if cross_sequence[3] else other.line_width
+ return new_one
+
+ def set_stamp_extent(self, width, height):
+ """Set extent of stamp. This stamps will ignore these parameters."""
+ pass
+
+ def render(self, ctx, point, state):
+ """
+ pre: ctx is not None
+ pre: len(point) == 2
+ """
+ ctx.set_line_width(self.line_width)
+ factor = 2.0 * math.pi / float(self.order)
+# rale = random.Random()
+# rale.seed(self.order+100*self.line_width+100*self.start_angle)
+ for step in xrange(self.order + 1):
+ angle = factor * step + self.start_angle
+# jitter = rale.uniform(0.9, 1.1)
+# delta_x = jitter*self.radius * math.cos(angle)
+# delta_y = jitter*self.radius * math.sin(angle)
+ delta_x = self.radius * math.cos(angle)
+ delta_y = self.radius * math.sin(angle)
+ ctx.move_to(point[0], point[1])
+ ctx.line_to(point[0]+delta_x, point[1]+delta_y)
+ ctx.stroke()
+
+ def explain(self):
+ """
+ post: len(__return__) == 3
+ """
+ str_start_angle = _('start angle: %4.3f') % self.start_angle
+ str_line_width = _('line width: %4.3f') % self.line_width
+ return _('Star stamp: number of rays: ') + str(self.order) \
+ + ', ' + str_line_width \
+ + ', ' + str_start_angle , \
+ None, \
+ None
+
+ def copy(self):
+ """A copy constructor.
+ post: isinstance(__return__, StarStamp)
+ # check for distinct references, needs to copy content, not references
+ post: __return__ is not self
+ """
+ new_one = StarStamp(self.get_trunk(), -1)
+ new_one.order = self.order
+ new_one.radius = self.radius
+ new_one.line_width = self.line_width
+ new_one.start_angle = self.start_angle
+ return new_one
diff --git a/model_constraintpool.py b/model_constraintpool.py
index e7e4e6d..e671af0 100644
--- a/model_constraintpool.py
+++ b/model_constraintpool.py
@@ -151,6 +151,7 @@ class ConstraintPool(object):
# self.set('*', 'modifiertypeconstraint', ['border', ])
# self.set('*', 'modifiertypeconstraint', ['rectangulartile', ])
+# self.set('*', 'stamptypeconstraint', ['star',])
# self.set('*', 'stamptypeconstraint', ['disk',])
# self.set('*', 'stamptypeconstraint', ['filledcyclic',])
# self.set('*', 'stamptypeconstraint', ['svg',])
diff --git a/po/Kandid.pot b/po/Kandid.pot
index 9794292..633c596 100644
--- a/po/Kandid.pot
+++ b/po/Kandid.pot
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2010-07-04 12:56+0200\n"
+"POT-Creation-Date: 2010-07-07 20:23+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -194,6 +194,20 @@ msgstr ""
msgid "Analogous color scheme"
msgstr ""
+#: /home/strom/minimal/activities/Kandid.activity/ep_stamp_star.py:144
+#, python-format
+msgid "start angle: %4.3f"
+msgstr ""
+
+#: /home/strom/minimal/activities/Kandid.activity/ep_stamp_star.py:145
+#, python-format
+msgid "line width: %4.3f"
+msgstr ""
+
+#: /home/strom/minimal/activities/Kandid.activity/ep_stamp_star.py:146
+msgid "Star stamp: number of rays: "
+msgstr ""
+
#: /home/strom/minimal/activities/Kandid.activity/ep_colorgamut_monchrome.py:69
msgid "Monochromatic color scheme"
msgstr ""