Beispiel #1
0
def initsort(n=40, order='random', width=0):
    global count, perm, keys, colors
    global display, canvas, displayactive
    global rheight, rwidth, swidth
    global lastorder
    count = n
    perm = genperm(count, order=order)
    keys = range(0, count)
    lastorder = order
    colors = hsv.spectrum(n)
    if (width > 0):
        swidth = width
    if displayactive:
        display.destroy()
        display.active = False
    if (count * rwidth > swidth):
        rwidth = int(swidth / count)
    display = Tk()
    displayactive = True
    display.title('Sorting %d elements' % count)
    canvas = Canvas(display,
                    width=rwidth * count,
                    height=rheight,
                    background="#ffffff")
    canvas.grid(row=0, column=0)
    showsort(perm)
Beispiel #2
0
    def setmgranularity(self, m = 1):
        n = self.ecount
        curm = self.mgranularity
#        print 'Changing mgranularity from %d to %d' % (curm, m)
        if m == 2 * curm:
            # Double degree of mirroring (mirror2)
            n = n / 2
            if self.lastorder == 'fwdrev':
                self.lastorder = 'forward'
            elif self.lastorder == 'revfwd':
                self.lastorder = 'reverse'
            else:
                print 'Invalid order for mirroring'
                return # Invalid order for mirroring
        elif m * 2 == curm:
            # Halve degree of mirroring (unmirror2)
            n = n * 2
            if self.lastorder == 'forward':
                self.lastorder = 'fwdrev'
            elif self.lastorder == 'reverse':
                self.lastorder = 'revfwd'
            else:
                print 'Invalid order for unmirroring'
                return # Invalid order for unmirroring
        self.ecount = n
        self.mgranularity = m
        self.perm = genperm(n,
                            order=fixorder(self.lastorder, self.rowmode))
        self.keys = range(0, n)
        self.colors = hsv.spectrum(n, self.spectrum_s, self.spectrum_v,
                                   granularity=self.colorgranularity(self.rowmode))
        self.showsort()
Beispiel #3
0
 def __init__(self, n=48, order='forward', saturation = 0, value = 0,
              rhost = '', subdivisions = 1, bordercolor = '', nodisplay = False):
     self.ecount = n
     self.rowmode = 'single'
     self.cgranularity = 1
     self.mgranularity = 1
     self.subdivisions = subdivisions
     if subdivisions > 1 and not bordercolor:
         bordercolor = '#000000'
     self.bordercolor = bordercolor
     self.rcount = n * 2 * self.subrectanglecount(True) * self.mgranularity
     self.perm = genperm(n, order=order)
     self.keys = range(0, n)
     self.lastorder = order
     cols = self.rcount/2
     self.panel = panel.Panel(rows = 2, cols = cols,
                              rwidth = int(1440/cols), nodisplay = nodisplay)
     if rhost:
         port = 8000
         (host, s, p) = rhost.partition(':')
         if p:
             port = int(p)
         pn = panel.PanelClient(host, port)
         self.panel.addsubpanel(pn)
     if saturation > 0:
         self.spectrum_s = saturation
     if value > 0:
         self.spectrum_v = value
     self.colors = hsv.spectrum(n, self.spectrum_s, self.spectrum_v,
                                granularity=self.colorgranularity(self.rowmode))
     self.showsort()
Beispiel #4
0
    def __init__(self, n=40, order='forward', width=0, height = 0,
                 saturation = 0, value = 0):
        self.count = n
        self.perm = genperm(n, order=order)
        self.keys = range(0, n)
        self.lastorder = order

        if saturation > 0:
            self.spectrum_s = saturation
        if value > 0:
            self.spectrum_v = value
        self.colors = hsv.spectrum(n, self.spectrum_s, self.spectrum_v)

        if width > 0:
            self.swidth = width
        if height > 0:
            self.rheight = height
        if self.displayactive:
            self.display.destroy()
        if (self.count * self.rwidth > self.swidth):
            self.rwidth = int(self.swidth/self.count)
        self.display = Tk()
        self.display.title('Sorting %d elements' % self.count)
        self.frame = Frame(self.display)
        self.frame.pack(fill=BOTH, expand=YES)
        self.canvas = Canvas(self.frame,
                             width=self.rwidth*self.count,
                             height=self.rheight,
                             background="#ffffff")
        self.canvas.pack(fill=BOTH, expand=YES)
        self.canvas.grid(row=0, column=0)
        self.displayactive = True
        self.showsort(firsttime=True)
        self.display.bind("<ButtonRelease-1>", self.showsort)
Beispiel #5
0
    def __init__(self, n=48, order='forward', saturation = 0, value = 0,
                 subdivisions = 1, bordercolor = '', nodisplay = False,
                 rigBool = False, rig = []):
        # just pass to panel
        self.rigBool = rigBool
        self.rig = rig
        print rigBool

        self.ecount = n
        self.rowmode = 'single'
        self.cgranularity = 1
        self.mgranularity = 1
        self.subdivisions = subdivisions
        if subdivisions > 1 and not bordercolor:
            bordercolor = '#000000'
        self.bordercolor = bordercolor
        self.rcount = n * 2 * self.subrectanglecount(True) * self.mgranularity
        self.perm = genperm(n, order=order)
        self.keys = range(0, n)
        self.lastorder = order
        cols = self.rcount/2
        self.panel = panel.Panel(rows = 2, cols = cols,
                                 rwidth = int(1440/cols), nodisplay = nodisplay,
                                 rigBool = self.rigBool, rig = self.rig)
        if saturation > 0:
            self.spectrum_s = saturation
        if value > 0:
            self.spectrum_v = value
        self.colors = hsv.spectrum(n, self.spectrum_s, self.spectrum_v,
                                   granularity=self.colorgranularity(self.rowmode))
        self.showsort()
Beispiel #6
0
 def set_spectrum(self, s = -1, v = -1):
     if s >= 0:
         self.spectrum_s = s
     if v >= 0:
         self.spectrum_v = v
     self.colors = hsv.spectrum(self.ecount, self.spectrum_s, self.spectrum_v,
                                granularity=self.colorgranularity(self.rowmode))
     self.showsort()
Beispiel #7
0
 def set_spectrum(self, s = -1, v = -1):
     if s >= 0:
         self.spectrum_s = s
     if v >= 0:
         self.spectrum_v = v
     self.colors = hsv.spectrum(self.count, self.spectrum_s, self.spectrum_v)
     if self.displayactive:
         self.showsort()
Beispiel #8
0
 def set_spectrum(self, s=-1, v=-1):
     if s >= 0:
         self.spectrum_s = s
     if v >= 0:
         self.spectrum_v = v
     self.colors = hsv.spectrum(self.count, self.spectrum_s,
                                self.spectrum_v)
     if self.displayactive:
         self.showsort()
Beispiel #9
0
 def setcgranularity(self, c=1):
     self.cgranularity = c
     n = int(self.rcount /
             (self.rgranularity(self.rowmode) * self.subrectanglecount(True) * self.mgranularity))
     self.ecount = n
     if self.lastorder == 'none':
         self.lastorder = 'forward'
     self.perm = genperm(n,
                         order=fixorder(self.lastorder, self.rowmode))
     self.keys = range(0, n)
     self.colors = hsv.spectrum(n, self.spectrum_s, self.spectrum_v,
                                granularity=self.colorgranularity(self.rowmode))
     self.showsort()
Beispiel #10
0
    def __init__(self,
                 n=48,
                 order='forward',
                 saturation=0,
                 value=0,
                 subdivisions=1,
                 bordercolor='',
                 nodisplay=False,
                 rigBool=False,
                 rig=[]):
        # just pass to panel
        self.rigBool = rigBool
        self.rig = rig
        print rigBool

        self.ecount = n
        self.rowmode = 'single'
        self.cgranularity = 1
        self.mgranularity = 1
        self.subdivisions = subdivisions
        if subdivisions > 1 and not bordercolor:
            bordercolor = '#000000'
        self.bordercolor = bordercolor
        self.rcount = n * 2 * self.subrectanglecount(True) * self.mgranularity
        self.perm = genperm(n, order=order)
        self.keys = range(0, n)
        self.lastorder = order
        cols = self.rcount / 2
        self.panel = panel.Panel(rows=2,
                                 cols=cols,
                                 rwidth=int(1440 / cols),
                                 nodisplay=nodisplay,
                                 rigBool=self.rigBool,
                                 rig=self.rig)
        if saturation > 0:
            self.spectrum_s = saturation
        if value > 0:
            self.spectrum_v = value
        self.colors = hsv.spectrum(n,
                                   self.spectrum_s,
                                   self.spectrum_v,
                                   granularity=self.colorgranularity(
                                       self.rowmode))
        self.showsort()
Beispiel #11
0
    def __init__(self,
                 n=40,
                 order='forward',
                 width=0,
                 height=0,
                 saturation=0,
                 value=0):
        self.count = n
        self.perm = genperm(n, order=order)
        self.keys = range(0, n)
        self.lastorder = order

        if saturation > 0:
            self.spectrum_s = saturation
        if value > 0:
            self.spectrum_v = value
        self.colors = hsv.spectrum(n, self.spectrum_s, self.spectrum_v)

        if width > 0:
            self.swidth = width
        if height > 0:
            self.rheight = height
        if self.displayactive:
            self.display.destroy()
        if (self.count * self.rwidth > self.swidth):
            self.rwidth = int(self.swidth / self.count)
        self.display = Tk()
        self.display.title('Sorting %d elements' % self.count)
        self.frame = Frame(self.display)
        self.frame.pack(fill=BOTH, expand=YES)
        self.canvas = Canvas(self.frame,
                             width=self.rwidth * self.count,
                             height=self.rheight,
                             background="#ffffff")
        self.canvas.pack(fill=BOTH, expand=YES)
        self.canvas.grid(row=0, column=0)
        self.displayactive = True
        self.showsort(firsttime=True)
        self.display.bind("<ButtonRelease-1>", self.showsort)
Beispiel #12
0
def initsort(n=40, order='random', width=0):
    global count, perm, keys, colors
    global display, canvas, displayactive
    global rheight, rwidth, swidth
    global lastorder
    count = n
    perm = genperm(count, order=order)
    keys = range(0,count)
    lastorder = order
    colors = hsv.spectrum(n)
    if (width > 0):
        swidth = width
    if displayactive:
        display.destroy()
        display.active = False
    if (count * rwidth > swidth):
        rwidth = int(swidth/count)
    display = Tk()
    displayactive = True
    display.title('Sorting %d elements' % count)
    canvas = Canvas(display,
                    width=rwidth*count, height=rheight, background="#ffffff")
    canvas.grid(row=0, column=0)
    showsort(perm)
Beispiel #13
0
 def newcount(self, n=40):
     self.count = n
     if self.lastorder == 'none':
         self.lastorder = 'forward'
     self.perm = genperm(n, order=self.lastorder)
     self.keys = range(0, n)
     self.colors = hsv.spectrum(n, self.spectrum_s, self.spectrum_v)
     self.rwidth = int(self.swidth / self.count)
     if not self.displayactive:
         self.display = Tk()
         self.displayactive = True
         self.display.title('Sorting %d elements' % self.count)
         self.frame = Frame(self.display)
         self.frame.pack(fill=BOTH, expand=YES)
         self.canvas = Canvas(self.frame,
                              width=self.rwidth * self.count,
                              height=self.rheight,
                              background="#ffffff")
         self.canvas.pack(fill=BOTH, expand=YES)
         self.canvas.grid(row=0, column=0)
         self.display.bind("<ButtonRelease-1>", self.showsort)
     else:
         self.display.title('Sorting %d elements' % self.count)
     self.showsort(firsttime=True)
Beispiel #14
0
 def newcount(self, n=40):
     self.count = n
     if self.lastorder == 'none':
         self.lastorder = 'forward'
     self.perm = genperm(n, order=self.lastorder)
     self.keys = range(0, n)
     self.colors = hsv.spectrum(n, self.spectrum_s, self.spectrum_v)
     self.rwidth = int(self.swidth/self.count)
     if not self.displayactive:
         self.display = Tk()
         self.displayactive = True
         self.display.title('Sorting %d elements' % self.count)
         self.frame = Frame(self.display)
         self.frame.pack(fill=BOTH, expand=YES)
         self.canvas = Canvas(self.frame,
                              width=self.rwidth*self.count,
                              height=self.rheight,
                              background="#ffffff")
         self.canvas.pack(fill=BOTH, expand=YES)
         self.canvas.grid(row=0, column=0)
         self.display.bind("<ButtonRelease-1>", self.showsort)
     else:
         self.display.title('Sorting %d elements' % self.count)
     self.showsort(firsttime=True)