Example #1
0
    def __init__(self, interval=10, limit=10):
        Tile.__init__(self, interval, limit)
        b = Block(8, 8).fill(LampState.FLIP)

        self.__masterFrame = Frame()
        self.__masterFrame.add(self.getFrame(), 0, 0).add(b, 0, 0).hide(b)
        self.__flipped = False
        self.__flipper = b
Example #2
0
 def __compose(self, f1, f2):
     '''
     This isn't totally right as a case analysis - the nudging
     property is subtle - but it'll do as a demo.
     '''
     if f1 is None and f2 is None:
         return None
     else:
         frame = Frame()
         if not f1 is None: frame.add(f1, 0, 0)
         if not f2 is None: frame.add(f2, 8, 0)
         return frame
Example #3
0
class FlipTile(Tile):
    '''
    Abstract widget class for one Tile. We also have the ability
    to completely invert whatever the concrete subclass chooses
    to do.
    '''

    def __init__(self, interval=10, limit=10):
        Tile.__init__(self, interval, limit)
        b = Block(8, 8).fill(LampState.FLIP)

        self.__masterFrame = Frame()
        self.__masterFrame.add(self.getFrame(), 0, 0).add(b, 0, 0).hide(b)
        self.__flipped = False
        self.__flipper = b

    def recyclable(self): return True

    def getMasterFrame(self):
        'Return the master frame for display'
        return self.__masterFrame

    def prepare(self):
        if self.__flipped:
            self.__masterFrame.hide(self.__flipper)
        else:
            self.__masterFrame.show(self.__flipper)

        self.__flipped = not self.__flipped
Example #4
0
'''
A simple toggle of a 4 x 4 block of LEDs. Push any
button to show the block.
'''

from net.loadbang.shado import Frame, Block
from net.loadbang.shado.types import LampState
from config import renderer

block = Block(4, 4).fill(LampState.ON)

frame = Frame()
frame.add(block, 2, 2)
blank = Frame()

def bang():
    '''ignore metronome input.'''
    pass

def press(x, y, n):
    if n == 1:
        test()
    else:
        clear()

def test():
    renderer.render(frame)

def clear():
    renderer.render(blank)
        across the entire grid.
        """
        if how != 0:
            state = self.getLamp(x, y)
            if state == LampState.OFF:
                self.setLamp(x, y, LampState.ON)
            else:
                self.setLamp(x, y, LampState.OFF)

            draw()

        return True


block = MyBlock()
frame = Frame()
manager = PressManager(frame)

# We can no longer add a block to a frame more than once (we don't use stamps
# any more) so we have to add a ViewPort to each instance.

for x in range(0, 8, 2):
    for y in range(0, 8, 2):
        frame.add(ViewPort(block, 0, 0, 2, 2), x, y)


def bang():
    pass


def press(x, y, how):
Example #6
0
    def __init__(self, name):
        self.__name = name

        # General tools:
        self.__random = Random()

        # Full frame, which can hold two tiles next to each other (X or Y):
        ffr = Frame()

        # Window frame, original matching the monome, within which we move
        # the full frame

        wfr = Frame()

        # Cropped renderable, which is the one we actually render (so that we
        # don't overwrite any adjacent pixels in a bigger design).

        port = ViewPort(wfr, 0, 0, 8, 8)

        # Create a pool of tiles - we can populate __tilePool to hard-wire the
        # first tile if we want to test it explicitly.
        # Cursor() is a special-case, manually loaded for the first few bars.

        self.__fixedTiles = {
            'CURSOR' : Cursor(),
            'BANG' : Bang()
        }

        self.__tilePool = []

        self.__usedPool = [
            Moonbase(),
            Hanoi(False),
            Hanoi(True),
            Eclipse(),
            Spell(),
            Shards(1),
            Shards(3),
            Bars(),
            Border(),
            Flash4(4),
            Flash4(2),
            Cross(),
            Counter(),
            PixelFlip(),
            FourWay()
        ]

        # Set up the first tile:
        t = self.__chooseTile()

        # Set up out state: the stamp for our starting tile.
        ffr.add(t.getMasterFrame(), 0, 0)
        self.__this = TileState(t)
        self.__next00 = None

        # Locate the full frame at (0, 0) within the Monome.
        wfr.add(ffr, 0, 0)

        # We'll need these later:
        self.__fullFrame = ffr
        self.__windFrame = wfr
        self.__viewPort = port

        # Not used (yet), but let's be clean:
        self.__vector = (0, 0)

        self.__nudging = False
Example #7
0
'''
Simple animation. Turn on the 10msec
metronome to see things move.
'''

from net.loadbang.shado import Frame, Block, ViewPort
from net.loadbang.shado.types import LampState
from config import renderer

block = Block(4, 4).fill(LampState.THRU)

# We can no longer add a block to a frame more than once (we don't use stamps
# any more) so we have to add a sub-frame to each instance.

frame = Frame()

position = 0

frame.add(Frame().add(block, 0, 0), 0, 0)
frame.add(Frame().add(block, 0, 0), 4, 0)
frame.add(Frame().add(block, 0, 0), 0, 4)
frame.add(Frame().add(block, 0, 0), 4, 4)
frame.add(Frame().add(block, 0, 0), 2, 2)

count = 0


def bang():
    global count
    count += 1
    if count % 10 == 0: doit()
Example #8
0
'''
A slightly smarter version of Simple, using shado's
button-tracking machinery.
'''

from net.loadbang.shado import Block, PressManager, ViewPort, Frame
from net.loadbang.shado.types import LampState
from config import renderer, monomeWidth, monomeHeight

block = Block(4, 4).fill(LampState.ON)

frame = Frame().add(block, 2, 2).hide(block)


class MyViewPort(ViewPort):
    '''
    In order to catch button presses, we'll put a ViewPort around
    the frame, but build it in Python with a callback.
    '''
    def __init__(self, router, x, y, width, height):
        ViewPort.__init__(self, router, x, y, width, height)

    def press(self, x, y, how):
        '''callback from shado: deal with a button press'''
        if how != 0:
            frame.show(block)
        else:
            frame.hide(block)

        renderer.render(self)
        return True
Example #9
0
Decimal counter using glyphs for the digits.
Needs the 10msec metronome.
'''

from net.loadbang.shado import Frame, Block
from net.loadbang.shado.types import LampState
from config import renderer

digits = [
    '111 101 101 101 111', '110 010 010 010 010', '111 001 111 100 111',
    '111 001 111 001 111', '101 101 111 001 001', '111 100 111 001 111',
    '111 100 111 101 111', '111 001 001 001 001', '111 101 111 101 111',
    '111 101 111 001 111'
]

frame = Frame()
renderer.render(frame)

mainframe = Frame()
f = mainframe.add(frame, 0, 0)

lftBlocks = [Block(digits[i]) for i in range(10)]
rhtBlocks = [Block(digits[i]) for i in range(10)]

for i in range(10):
    frame.add(lftBlocks[i], 0, 0).add(rhtBlocks[i], 5, 0)

counter = 99
interval = 0

Example #10
0
    def __init__(self):
        Block.__init__(self, 1, 1)
        self.fill(LampState.OFF)

    def press(self, x, y, how):
        if how != 0:
            if self.getLamp(0, 0) == LampState.OFF:
                self.fill(LampState.ON)
            else:
                self.fill(LampState.OFF)

            draw()

        return True

frame = Frame()
manager = PressManager(frame)

# 8 x 16 just for our personal testing:

for x in range(16):
    for y in range(8):
        frame.add(MyBlock(), x, y)

def bang():
    pass

def press(x, y, how):
    manager.press(x, y, how)

def draw():
Example #11
0
'''
A simple raise/lower demo: two tiles in
a frame.
'''

from net.loadbang.shado import Frame, Block
from net.loadbang.shado.types import LampState
from config import renderer

outer = Block(4, 4).fill(LampState.ON)
inner = Block(2, 2).fill(LampState.OFF)

frame = Frame().add(inner, 3, 3).add(outer, 2, 2)


def bang():
    pass


def press(x, y, n):
    "Dumb button press handling: we aren't passing presses to shado."
    if n == 1:
        frame.top(inner)
    else:
        frame.bottom(inner)

    renderer.render(frame)


renderer.render(frame)
Example #12
0
'''
Draw a cross for the last pressed button.
'''

from config import renderer
from net.loadbang.shado import Frame, Block
from net.loadbang.shado.types import LampState

vertical = Block(1, 16).fill(LampState.ON)
horizontal = Block(16, 1).fill(LampState.ON)

frame = Frame().add(vertical, 0, 0).add(horizontal, 0, 0)


def hide():
    frame.hide(vertical)
    frame.hide(horizontal)
    renderer.render(frame)


hide()


def bang():
    pass


def press(x, y, n):
    if n == 1:
        frame.moveTo(vertical, x, 0).show(vertical)
        frame.moveTo(horizontal, 0, y).show(horizontal)
Example #13
0
    def __init__(self, interval=10, limit=10):
        self.__clientFrame = Frame()

        self.__interval = interval
        self.__hLimit = interval * limit
        self.__counter = 0
Example #14
0
from config import renderer

digits = [
    '111 101 101 101 111',
    '110 010 010 010 010',
    '111 001 111 100 111',
    '111 001 111 001 111',
    '101 101 111 001 001',
    '111 100 111 001 111',
    '111 100 111 101 111',
    '111 001 001 001 001',
    '111 101 111 101 111',
    '111 101 111 001 111'
]

frame = Frame()
renderer.render(frame)

mainframe = Frame()
f = mainframe.add(frame, 0, 0)

lftBlocks = [Block(digits[i]) for i in range(10)]
rhtBlocks = [Block(digits[i]) for i in range(10)]

for i in range(10):
    frame.add(lftBlocks[i], 0, 0).add(rhtBlocks[i], 5, 0)

counter = 99
interval = 0

def bang():
Example #15
0
'''
A simple toggle of a 4 x 4 block of LEDs. Push any
button to show the block.
'''

from net.loadbang.shado import Frame, Block
from net.loadbang.shado.types import LampState
from config import renderer

block = Block(4, 4).fill(LampState.ON)

frame = Frame()
frame.add(block, 2, 2)
blank = Frame()


def bang():
    '''ignore metronome input.'''
    pass


def press(x, y, n):
    if n == 1:
        test()
    else:
        clear()


def test():
    renderer.render(frame)
Example #16
0
        across the entire grid.
        '''
        if how != 0:
            state = self.getLamp(x, y)
            if state == LampState.OFF:
                self.setLamp(x, y, LampState.ON)
            else:
                self.setLamp(x, y, LampState.OFF)

            draw()

        return True


block = MyBlock()
frame = Frame()
manager = PressManager(frame)

# We can no longer add a block to a frame more than once (we don't use stamps
# any more) so we have to add a ViewPort to each instance.

for x in range(0, 8, 2):
    for y in range(0, 8, 2):
        frame.add(ViewPort(block, 0, 0, 2, 2), x, y)


def bang():
    pass


def press(x, y, how):
Example #17
0
        Block.__init__(self, 1, 1)
        self.fill(LampState.OFF)

    def press(self, x, y, how):
        if how != 0:
            if self.getLamp(0, 0) == LampState.OFF:
                self.fill(LampState.ON)
            else:
                self.fill(LampState.OFF)

            draw()

        return True


frame = Frame()
manager = PressManager(frame)

# 8 x 16 just for our personal testing:

for x in range(16):
    for y in range(8):
        frame.add(MyBlock(), x, y)


def bang():
    pass


def press(x, y, how):
    manager.press(x, y, how)
Example #18
0
from __future__ import generators
from net.loadbang.shado import Frame, Block
from net.loadbang.shado.types import LampState
from config import renderer

outer = Block(4, 4).fill(LampState.ON)
inner = Block(2, 2).fill(LampState.FLIP)

def posGenerator():
    while True:
        for i in range(8): yield i

pos = posGenerator()
n = pos.next()
frame = Frame().add(outer, 2, 2).add(inner, n, n)

frame.hide(outer)

count = 0

def bang():
    global count
    count += 1
    if count % 10 == 0: doit()

def press(x, y, n):
    if n == 1:
        frame.show(outer)
    else:
        frame.hide(outer)
Example #19
0
'''
Simple animation. Turn on the 10msec
metronome to see things move.
'''

from net.loadbang.shado import Frame, Block, ViewPort
from net.loadbang.shado.types import LampState
from config import renderer

block = Block(4, 4).fill(LampState.THRU)

# We can no longer add a block to a frame more than once (we don't use stamps
# any more) so we have to add a sub-frame to each instance.

frame = Frame()

position = 0

frame.add(Frame().add(block, 0, 0), 0, 0)
frame.add(Frame().add(block, 0, 0), 4, 0)
frame.add(Frame().add(block, 0, 0), 0, 4)
frame.add(Frame().add(block, 0, 0), 4, 4)
frame.add(Frame().add(block, 0, 0), 2, 2)

count = 0

def bang():
    global count
    count += 1
    if count % 10 == 0: doit()