Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/ka_utils.py
diff options
context:
space:
mode:
authorstrom <strom@vehikel.(none)>2010-05-02 19:04:36 (GMT)
committer strom <strom@vehikel.(none)>2010-05-02 19:04:36 (GMT)
commitf84b965aa7b4a28786b3520671a5d0fd1881cd6d (patch)
tree79be950bc29ee8c2eb9ffb1bd0fac6723c486d89 /ka_utils.py
parent6416d002a0c99678bc38f1997a9bbc94acd7ead3 (diff)
Added a sampler for iterated function systems.
Diffstat (limited to 'ka_utils.py')
-rw-r--r--ka_utils.py26
1 files changed, 24 insertions, 2 deletions
diff --git a/ka_utils.py b/ka_utils.py
index 22f0a4a..df51e8d 100644
--- a/ka_utils.py
+++ b/ka_utils.py
@@ -14,6 +14,9 @@
# 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
+
+ICON_WIDTH = ICON_HEIGHT = 48
def explain_points(head, points):
"""
@@ -24,5 +27,24 @@ def explain_points(head, points):
for point in points:
description += '%4.3f, %4.3f; ' % (point[0], point[1])
description += ']'
- return head + ' ' + description if head is not None and len(head) \
- else description
+ text = head + ' ' + description if head is not None and len(head) \
+ else description
+
+ surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, ICON_WIDTH, ICON_HEIGHT)
+ ctx = cairo.Context(surface)
+ ctx.scale(ICON_WIDTH, ICON_HEIGHT)
+ # paint background
+ ctx.set_operator(cairo.OPERATOR_OVER)
+ ctx.set_source_rgb(1.0, 1.0, 1.0)
+ ctx.paint()
+ radius = 0.1
+ ctx.set_line_width(0.02)
+ for point in points:
+ # paint a cross for each position
+ ctx.set_source_rgb(0.0, 0.0, 0.0)
+ ctx.move_to(0.5+point[0]-radius, 0.5+point[1]-radius)
+ ctx.line_to(0.5+point[0]+radius, 0.5+point[1]+radius)
+ ctx.move_to(0.5+point[0]+radius, 0.5+point[1]-radius)
+ ctx.line_to(0.5+point[0]-radius, 0.5+point[1]+radius)
+ ctx.stroke()
+ return text, surface, head