colorkeys.py

"""Keys mapped to different abstract glyphs.
   by stephan)
"""
from slut import *

class Atlantis(World):
    def onSetup(self):
        self.name = "Form Follows Computation Here"
        self.width = 800
        self.height = 600
        self.fullscreen = False
        self.camera.moveTo(0.0, 0.0, -35)
        self.camera.clip_far = 1000.0
        Sheet(self, 'sheet')

        def focus():
            self.camera.moveTo(0.0, 0.0, -35)
            self.camera.rotTo(0.0, 0.0, 0.0)
            if self.sprites['sheet'].dir > 0:
                self.camera.orbitTo(0.0, 0.0, 0.0)
            else:
                self.camera.orbitTo(0.0, 180.0, 0.0)
        def out():
            self.camera.moveTo(SineTween(-30.0, -40.0, -200.0, 1.0))
        def screenshot():
            self.screenshot()
        TextButton(self, 'focus', '[focus]', 16, 'courier', focus)
        self.tags['focus'].moveTo(self.width-130, self.height-30)
        TextButton(self, 'out', '[out]', 16, 'courier', out)
        self.tags['out'].moveTo(self.width-200, self.height-30)
        TextButton(self, 'sshot', '[screenshot]', 16, 'courier', screenshot)
        self.tags['sshot'].moveTo(100, self.height-30)


    def onKeyDown(self, event):
        self.sprites['sheet'].genGlyph(event.key)


class Sheet(Sprite):
    def __init__(self, parent, name):
        Sprite.__init__(self, parent, name)
        self.glyph_column = 0
        self.glyph_row = 0
        self.gwidth = 1.5
        self.gheight = 1.5
        self.dir = 1

    def genGlyph(self, key):
        Glyph(self, key)
        if self.glyph_column > 10:
            self.progress_vertically()
        else:
            self.progress_horizontally()

    def progress_vertically(self):
        if self.glyph_row > 200:
            self.glyph_column = 0
            self.glyph_row = 0
            self.sprites = {}
            self.moveTo(0.0, 0.0, 0.0)
            self.parent.camera.orbitTo(0.0, 0.0, 0.0)
            self.dir = -self.dir
        else:
            self.glyph_column = 0
            self.glyph_row += 1
            self.dir = -self.dir
            self.moveBy(SineTween(0.0, self.gheight, 0.0, 0.3))
            self.parent.camera.orbitBy(SineTween(0.0, -180.0, 0.0, 1.0))

    def progress_horizontally(self):
        self.glyph_column += 1
        self.moveBy(SineTween(-self.gwidth*0.8*self.dir, 0.0, 0.0, 0.3))


class Glyph(Sprite):
    def __init__(self, parent, key):
        Sprite.__init__(self, parent,
            'glyph_' + str(parent.glyph_column) + '_' + str(parent.glyph_row))
        self.key = key
        self.alpha_factor = (int(self.key)-90)/20.0
        if self.parent.dir > 0:
            self.moveBy(self.parent.glyph_column*self.parent.gwidth,
                -self.parent.glyph_row*self.parent.gheight, 0.0)
        else:
            self.moveBy(11*self.parent.gwidth-self.parent.glyph_column*self.parent.gwidth,
                -self.parent.glyph_row*self.parent.gheight, 0.0)
        self.scaleTo(0.0, 0.0, 0.0)
        self.scaleTo(SineTween(1.0, 1.0, 1.0, 0.3))
        self.color = (self.alpha_factor, 0.3, 0.4, 1.0)

    def onDraw(self):
        glColor4f(self.color[0], self.color[1], self.color[2], self.color[3])
        glBegin(GL_POLYGON)
        glVertex3f(0.0-self.alpha_factor,   0.0,   0.0+self.alpha_factor)
        glVertex3f(1.0,   0.0,   0.0+self.alpha_factor)
        glVertex3f(1.0, 1.0, 0.0+self.alpha_factor)
        glVertex3f(-0.5,   1.5-self.alpha_factor,   0.0+self.alpha_factor)
        glVertex3f(0.0,   0.0+self.alpha_factor,   0.0+self.alpha_factor)
        glEnd()



atlantis = Atlantis()
atlantis.run()
Initiated by Stephan Hechenberger
Thanks to CADRE's 103