File: DrawBot.py

package info (click to toggle)
wxpython4.0 4.2.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 232,540 kB
  • sloc: cpp: 958,937; python: 233,059; ansic: 150,441; makefile: 51,662; sh: 8,687; perl: 1,563; javascript: 584; php: 326; xml: 200
file content (72 lines) | stat: -rw-r--r-- 1,977 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/env python

"""
DrawBot.py

This a a demo of how one can use the FloatCanvas to do a drawing similar to one of the "DrawBot" demos:


http://just.letterror.com/ltrwiki/DrawBot

I think it's easier with FloatCavnas, and you get zoomign and scrolling to boot!


"""

import wx
from math import *

try: # see if there is a local FloatCanvas to use
    import sys
    sys.path.append("../")
    from floatcanvas import NavCanvas, FloatCanvas
    print("Using local FloatCanvas")
except ImportError: # Use the wxPython lib one
    from wx.lib.floatcanvas import NavCanvas, FloatCanvas
    print("Using installed FloatCanvas")


class DrawFrame(wx.Frame):

    """
    A frame used for the FloatCanvas Demo

    """

    def __init__(self,parent, id,title,position,size):
        wx.Frame.__init__(self,parent, id,title,position, size)

        # Add the Canvas
        self.Canvas = NavCanvas.NavCanvas(self,-1,(500,500),
                                          ProjectionFun = None,
                                          Debug = 0,
                                          BackgroundColor = "White",
                                          ).Canvas


        self.Show(True)
        self.MakePic()

        return None

    def MakePic(self):
        Canvas = self.Canvas
        phi = (sqrt(5) + 1)/2 - 1
        oradius = 10.0
        for i in xrange(720):
            radius = 1.5 * oradius * sin(i * pi/720)
            Color = (255*(i / 720.), 255*( i / 720.), 255 * 0.25)
            x = oradius + 0.25*i*cos(phi*i*2*pi)
            y = oradius + 0.25*i*sin(phi*i*2*pi)
            Canvas.AddCircle((x,y),
                             radius,
                             LineColor = "Black",
                             LineWidth = 2,
                             FillColor = Color,
                             )
        self.Canvas.ZoomToBB()

app = wx.App()
DrawFrame(None, -1, "FloatCanvas Demo App", wx.DefaultPosition, (700,700) )
app.MainLoop()