Exemple #1
0
    def start(self, font, msg=None, **params):
        #        self.fluepdot.rendering.setMode(Fluepdot.Mode.full)
        self.fluepdot.rendering.setMode(Fluepdot.Mode.diff)

        self.font = Font(font)
        debug(str(self.font))

        self.msg = "hello, world."
        if msg:
            self.msg = msg

        info("start scroll: {:s}".format(self.msg))

        self.mask = Mask()
        self.text = self.font.render(self.msg, fixed=True)

        p0 = int(math.floor(FRAMESIZE.w / (self.font.size.w + 1)))

        p1 = p0 - len(self.msg)

        self.pos0 = Position((self.font.size.w + 1) * int(p1 / 2), 0)

        #        self.pos0 = Position(int(FRAMESIZE.w/2)-int(self.text.w/2), 0 )

        self.mask.addMask(self.text, pos=self.pos0, wrap=True)

        self.fluepdot.buffer.write(self.mask)

        self.l = self.text.w
        self.k = 0

        return True
Exemple #2
0
    def draw(self, scroll, alignv, alignh, **params):

        self.mask = Mask()
        if scroll and alignv in [AlignVertical.top, AlignVertical.bottom]:
            rest = Size(FRAMESIZE.w, FRAMESIZE.h - (self.font.size.h + 1))
            top = Position(0, 0)
            bot = Position(0, self.font.size.h + 1)

            prev = self.fluepdot.buffer.read()
            if alignv == AlignVertical.top:
                tmp = prev.subMask(pos=top, size=rest)
                self.mask.addMask(tmp, pos=bot)
            elif alignv == AlignVertical.bottom:
                tmp = prev.subMask(pos=bot, size=rest)
                self.mask.addMask(tmp, pos=top)

        pos = Position(0, 0)
        if alignv == AlignVertical.top:
            pos.y = 0
        elif alignv == AlignVertical.center:
            pos.y = math.floor(abs(FRAMESIZE.h - self.text.h) / 2)
        elif alignv == AlignVertical.bottom:
            pos.y = FRAMESIZE.h - self.text.h

        if alignh == AlignHorizontal.left:
            pos.x = 0
        elif alignh == AlignHorizontal.center:
            pos.x = math.floor(abs(FRAMESIZE.w - self.text.w) / 2)
        elif alignh == AlignHorizontal.right:
            pos.x = FRAMESIZE.w - self.text.w

        self.mask.addMask(self.text, pos=pos)
        return self.mask
Exemple #3
0
 def start(self,**params):
     log("start reset".format())
     
     self.fluepdot.buffer.write( Mask() )
     self.fluepdot.buffer.write( Mask().inverse() )
     self.fluepdot.buffer.write( Mask() )
             
     return False
Exemple #4
0
    def render(self, style, invert, cutoff, **params):

        ret = Mask()

        if style == Style.check:
            for y in range(FRAMESIZE.h):
                for x in range(FRAMESIZE.w):
                    if x % 2 != y % 2:
                        ret[x, y] = True

        elif style == Style.gauss:
            for y in range(FRAMESIZE.h):
                for x in range(FRAMESIZE.w):
                    if random.gauss(0., 1.) > cutoff:
                        ret[x, y] = True

        elif style == Style.font:
            fill = self.font.render_repertoire(offset=self.offset,
                                               size=self.mask.size())
            self.offset += 1
            ret.addMask(fill)

        elif style == Style.axis:
            fill = Axis(self.mask.size())
            ret.addMask(fill)

        elif style == Style.border:
            fill = Border(self.mask.size())
            ret.addMask(fill)

        if invert:
            ret = ret.inverse()

        return ret
Exemple #5
0
 def read(self):
     ret = Mask()
     debug("framebuffer read")
     if not self.noread:
         rsp = http.get(self.address, "framebuffer", None)
         ret = Framebuffer.MaskFromResponse(rsp)
     return ret
Exemple #6
0
    def draw(self, invert, **params):

        cx = int(FRAMESIZE.w / 2)
        cy = int(FRAMESIZE.h / 2)

        r0 = random.gauss(0., 1.5)
        r1 = random.gauss(0., 2.)

        x = cx + int(r0 * (cx / 4.))
        y = cy + int(r1 * (cy / 4.))

        prev = Mask(mask=self.mask)

        self.mask[x, y] ^= True
        self.mask[x, y - 1] ^= True
        self.mask[x + 1, y] ^= True
        self.mask[x, y + 1] ^= True
        self.mask[x - 1, y] ^= True

        self.fluepdot.pixel.flip(x, y, self.mask[x, y])
        self.fluepdot.pixel.flip(x, y - 1, self.mask[x, y - 1])
        self.fluepdot.pixel.flip(x - 1, y, self.mask[x - 1, y])
        self.fluepdot.pixel.flip(x + 1, y, self.mask[x + 1, y])
        self.fluepdot.pixel.flip(x, y + 1, self.mask[x, y + 1])

        log(str(self.mask))
        return self.mask
Exemple #7
0
    def draw(self, **params):

        pos = Position(0, 0)

        self.mask = Mask()  #self.fluepdot.buffer.read()
        for i in range(self.rows):
            try:
                self.mask.addMask(self.font.render(self.buffer[i]),
                                  pos=self.pos[i])
            except Error as x:
                pass

#        self.mask.mask(self.buf,pos=pos)
        ret = self.fluepdot.buffer.write(self.mask)
        info(str(self.mask))
        return ret
Exemple #8
0
    def draw(self, **params):

        self.life.step()
        self.mask = Mask(mask=self.life)

        self.fluepdot.buffer.write(self.mask)
        info(str(self.mask))
        return self.mask
Exemple #9
0
    def draw(self,**params):
        
        self.life.step()
        mask = Mask(mask=self.life)

        self.fluepdot.buffer.write(mask)
        
        return mask
Exemple #10
0
    def draw(self, **params):

        prev = self.fluepdot.buffer.read()

        mask = Mask(mask=self.life)
        self.fluepdot.buffer.write(mask)

        info(str(mask))
        return mask
Exemple #11
0
    def text(self, x, y, font, msg):
        params = {'x': x, 'y': y, 'font': font}
        ret = Mask()
        debug("text {:s}".format(msg))
        if not self.nowrite:
            rsp = http.post(self.address, "framebuffer/text", params, data=msg)
            ret = Framebuffer.MaskFromResponse(rsp)

        return ret
Exemple #12
0
    def draw(self, **params):

        ret = []

        k = self.k
        L = self.text.w

        W, H = self.font.size.w + 1, self.font.size.h + 1

        next = Mask()
        pos0 = Position(-W, 0)
        pos1 = Position(k * W, 0)

        if k != 0:
            txt0 = self.text.subMask(size=Size(k * W, H))
            next.addMask(txt0, pos=self.pos0 + pos0, wrap=True)

        if self.l - k != 0:
            txt1 = self.text.subMask(pos=Position((k) * W, 0),
                                     size=Size((self.l - k) * W, H))
            next.addMask(txt1, pos=self.pos0 + pos1, wrap=True)

#        log("from\n"+str(self.mask))
#        log("to\n"+str(next))

        steps = Morph2(self.mask, next)

        if len(steps) >= 2:
            return steps[1]
        return steps[0]

        steps = [self.mask, next]

        for i in range(len(steps)):
            step = steps[i]
            ret += [step]
            self.mask = step

        self.k += 1
        if self.k > self.l:
            log("step")
            self.k = 0
            self.pos0.x -= W
            if self.pos0.x <= -L:
                self.pos0.x += FRAMESIZE.w

        return ret
Exemple #13
0
 def MaskFromResponse(self, rsp):
     ret = Mask(size=FRAMESIZE)
     x, y = 0, 0
     if rsp == None:
         return
     for row in rsp:
         if y >= FRAMESIZE.h:
             raise Error("invalid response: line count {} > {}".format(
                 y, FRAMESIZE.h))
         x = 0
         for col in row:
             if x > FRAMESIZE.w:
                 raise Error(
                     "invalid response: column count {} > {}".format(
                         x, FRAMESIZE.w))
             if col == 0x0A:
                 pass
             elif col == 0x20:
                 ret[x, y] = False
             else:
                 ret[x, y] = True
             x += 1
         y += 1
     return ret
Exemple #14
0
    def start(self, randomize, **params):
        info("start guns")
        self.fluepdot.rendering.setMode(Fluepdot.Mode.diff)

        self.life = life.Life(mask=self.mask)

        pos1 = Position(10, 2)
        pos2 = Position(60, 7)
        off1 = Position(x=24, y=10)
        off2 = Position(x=24, y=-5)

        self.life.spawn(life.Pattern.gun, pos=pos1)
        self.life.spawn(life.Pattern.eater, pos=pos1 + off1)

        self.life.spawn(life.Pattern.gun, pos=pos2, flip=Flip.horizontal)
        self.life.spawn(life.Pattern.eater,
                        pos=pos2 + off2,
                        flip=Flip.horizontal)

        self.mask = Mask(self.life)

        self.draw(**params)

        return True
Exemple #15
0
    def draw(self, **params):

        ret = []

        k = self.k
        L = self.l

        W, H = self.font.size.w + 1, self.font.size.h + 1

        next = Mask()
        pos0 = Position(k, 0)

        next = Mask()
        next.addMask(self.text, pos=self.pos0 + pos0, wrap=True)

        log("from\n" + str(self.mask))
        log("to\n" + str(next))

        #        steps = Morph2(self.mask,next)
        #        steps = Scan(self.mask,next)
        #        steps = [self.mask,next]

        steps = [self.mask, next]

        return next

        for i in range(len(steps)):
            step = steps[i]
            ret += [step]
            self.mask = step

        self.k += 1

        if self.k >= self.l:
            log("step")
            self.k = 0
            self.pos0.x += self.l
            if self.pos0.x + self.l >= FRAMESIZE.w:
                self.pos0.x -= FRAMESIZE.w

        return ret
Exemple #16
0
    def draw(self,**params):

        self.life.step()

        return Mask(mask=self.life)
Exemple #17
0
class Scroll(Mode):

    DefaultFont = FONT.font3x5

    def start(self, font, msg=None, **params):
        #        self.fluepdot.rendering.setMode(Fluepdot.Mode.full)
        self.fluepdot.rendering.setMode(Fluepdot.Mode.diff)

        self.font = Font(font)
        debug(str(self.font))

        self.msg = "hello, world."
        if msg:
            self.msg = msg

        info("start scroll: {:s}".format(self.msg))

        self.mask = Mask()
        self.text = self.font.render(self.msg, fixed=True)

        p0 = int(math.floor(FRAMESIZE.w / (self.font.size.w + 1)))

        p1 = p0 - len(self.msg)

        self.pos0 = Position((self.font.size.w + 1) * int(p1 / 2), 0)

        #        self.pos0 = Position(int(FRAMESIZE.w/2)-int(self.text.w/2), 0 )

        self.mask.addMask(self.text, pos=self.pos0, wrap=True)

        self.fluepdot.buffer.write(self.mask)

        self.l = int(self.text.w / (self.font.size.w + 1))
        self.k = 0

        return True

    def draw(self, **params):

        ret = []

        k = self.k
        L = self.text.w

        W, H = self.font.size.w + 1, self.font.size.h + 1

        next = Mask()
        pos0 = Position(-W, 0)
        pos1 = Position(k * W, 0)

        if k != 0:
            txt0 = self.text.subMask(size=Size(k * W, H))
            next.addMask(txt0, pos=self.pos0 + pos0, wrap=True)

        if self.l - k != 0:
            txt1 = self.text.subMask(pos=Position((k) * W, 0),
                                     size=Size((self.l - k) * W, H))
            next.addMask(txt1, pos=self.pos0 + pos1, wrap=True)

#        log("from\n"+str(self.mask))
#        log("to\n"+str(next))

        steps = Morph2(self.mask, next)

        if len(steps) >= 2:
            return steps[1]
        return steps[0]

        steps = [self.mask, next]

        for i in range(len(steps)):
            step = steps[i]
            ret += [step]
            self.mask = step

        self.k += 1
        if self.k > self.l:
            log("step")
            self.k = 0
            self.pos0.x -= W
            if self.pos0.x <= -L:
                self.pos0.x += FRAMESIZE.w

        return ret

    flags = [
        Mode.FLAG("font", DefaultFont),
        ("P:", "pause=", "pause", 1.0, "pause", lambda x: int(x)),
        (None, None, "msg", "hello, world.", "message", None),
    ]
Exemple #18
0
class Smooth(Mode):

    DefaultFont = FONT.font3x5

    def start(self, font, msg=None, **params):
        #        self.fluepdot.rendering.setMode(Fluepdot.Mode.full)
        self.fluepdot.rendering.setMode(Fluepdot.Mode.diff)

        self.font = Font(font)
        debug(str(self.font))

        self.msg = "hello, world."
        if msg:
            self.msg = msg

        info("start scroll: {:s}".format(self.msg))

        self.mask = Mask()
        self.text = self.font.render(self.msg, fixed=True)

        p0 = int(math.floor(FRAMESIZE.w / (self.font.size.w + 1)))

        p1 = p0 - len(self.msg)

        self.pos0 = Position((self.font.size.w + 1) * int(p1 / 2), 0)

        #        self.pos0 = Position(int(FRAMESIZE.w/2)-int(self.text.w/2), 0 )

        self.mask.addMask(self.text, pos=self.pos0, wrap=True)

        self.fluepdot.buffer.write(self.mask)

        self.l = self.text.w
        self.k = 0

        return True

    def draw(self, **params):

        ret = []

        k = self.k
        L = self.l

        W, H = self.font.size.w + 1, self.font.size.h + 1

        next = Mask()
        pos0 = Position(k, 0)

        next = Mask()
        next.addMask(self.text, pos=self.pos0 + pos0, wrap=True)

        log("from\n" + str(self.mask))
        log("to\n" + str(next))

        #        steps = Morph2(self.mask,next)
        #        steps = Scan(self.mask,next)
        #        steps = [self.mask,next]

        steps = [self.mask, next]

        return next

        for i in range(len(steps)):
            step = steps[i]
            ret += [step]
            self.mask = step

        self.k += 1

        if self.k >= self.l:
            log("step")
            self.k = 0
            self.pos0.x += self.l
            if self.pos0.x + self.l >= FRAMESIZE.w:
                self.pos0.x -= FRAMESIZE.w

        return ret

    flags = [
        Mode.FLAG("font", DefaultFont),
        ("P:", "pause=", "pause", 1.0, "pause", lambda x: int(x)),
        (None, None, "msg", "hello, world.", "message", None),
    ]
Exemple #19
0
    def draw(self, style, stamp, cuckoo, **params):

        if self.kuckuck and self.kuckuck.active():
            hour = int(self.kuckuck.repeat / 1)
            count = int(self.kuckuck.count / 1) + 1
            ret = Mask()

            idx = self.kuckuck.count % 2

            if 1 <= hour <= 4:
                vader = invader.INVADER.one.Mask(idx).double()
                msk = Mask(size=Size((4 + vader.w) * hour, vader.h))
                for c in range(hour):
                    pos = Position(c * (4 + vader.w), 0)
                    msk.addMask(vader, pos=pos)
                ret.addMask(msk)

            elif 5 <= hour <= 8:
                vader = invader.INVADER.one.Mask(idx)
                msk = Mask(size=Size((2 + vader.w) * hour, vader.h))
                for c in range(hour):
                    pos = Position(c * (2 + vader.w), 0)
                    msk.addMask(vader, pos=pos)
                ret.addMask(msk)

            elif 9 <= hour <= 12:
                vader = invader.INVADER.one.Mask(idx)
                msk = Mask(size=Size((2 + vader.w) * ceil(hour / 2), 2 *
                                     (vader.h)))
                for c in range(hour):
                    pos = Position(int(c / 2) * (2 + vader.w), 0)
                    if c % 2 == 1:
                        pos.y += vader.h
                    msk.addMask(vader, pos=pos)
                ret.addMask(msk)

            return ret

        hour = datetime.datetime.now(self.timezone).hour
        if stamp != "":
            hour = (datetime.datetime.fromisoformat(stamp) +
                    (datetime.datetime.now(self.timezone) - self.start)).hour

        if cuckoo == True and hour != self.hour:
            self.step(style, stamp, **params)
            times = hour % 12
            if times == 0:
                times = 12
            self.kuckuck = dotlife.time.Clock.Timer(1500., times)
            debug("KUCKUCK {:}".format(self.kuckuck))
            self.hour = hour
            self.step(style, stamp, **params)
            prev = self.mask
            self.mask = self.next
            return self.draw(style, stamp, cuckoo, **params)  # recurse once!

        if self.next != self.mask:

            if style in [Clock.Style.small, Clock.Style.large]:
                m = Morph2(self.mask, self.next, steps=1, flipcount=1)
                debug("to\n" + str(self.next))
                self.mask = m[1]
            elif style in [Clock.Style.split]:
                m = Morph2(self.mask, self.next, steps=1, flipcount=2)
                debug("to\n" + str(self.next))
                self.mask = m[1]
            else:
                #                debug("to\n"+str(self.next))
                self.mask = self.next

        self.hour = hour
        return self.mask
Exemple #20
0
 def draw(self,**params):
     return Mask()
Exemple #21
0
class Echo(Mode):

    DefaultFont = FONT.font5x5

    def start(self, font, alignv, scroll, msg="hello, world", **params):
        dump(params)
        self.fluepdot.rendering.setMode(Fluepdot.Mode.full)
        self.font = Font(font)
        self.msg = msg

        info("start echo: {:s}".format(self.msg))

        if scroll and alignv == AlignVertical.center:
            log("cannot scroll with center vertical alignment")
            scroll = False

        self.text = self.font.render(self.msg)
        log("text is {:}".format(self.text.size()))
        log(str(self.text))

        self.mask = self.draw(scroll, alignv, **params)
        return False

    def draw(self, scroll, alignv, alignh, **params):

        self.mask = Mask()
        if scroll and alignv in [AlignVertical.top, AlignVertical.bottom]:
            rest = Size(FRAMESIZE.w, FRAMESIZE.h - (self.font.size.h + 1))
            top = Position(0, 0)
            bot = Position(0, self.font.size.h + 1)

            prev = self.fluepdot.buffer.read()
            if alignv == AlignVertical.top:
                tmp = prev.subMask(pos=top, size=rest)
                self.mask.addMask(tmp, pos=bot)
            elif alignv == AlignVertical.bottom:
                tmp = prev.subMask(pos=bot, size=rest)
                self.mask.addMask(tmp, pos=top)

        pos = Position(0, 0)
        if alignv == AlignVertical.top:
            pos.y = 0
        elif alignv == AlignVertical.center:
            pos.y = math.floor(abs(FRAMESIZE.h - self.text.h) / 2)
        elif alignv == AlignVertical.bottom:
            pos.y = FRAMESIZE.h - self.text.h

        if alignh == AlignHorizontal.left:
            pos.x = 0
        elif alignh == AlignHorizontal.center:
            pos.x = math.floor(abs(FRAMESIZE.w - self.text.w) / 2)
        elif alignh == AlignHorizontal.right:
            pos.x = FRAMESIZE.w - self.text.w

        self.mask.addMask(self.text, pos=pos)
        return self.mask

    flags = [
        ("S", "scroll", "scroll", False, "scroll line?", None),
        Mode.FLAG("font", DefaultFont),
        Mode.FLAG("msg"),
        Mode.FLAG("alignv", AlignVertical.center),
        Mode.FLAG("alignh", AlignHorizontal.center),
    ]
Exemple #22
0
class Pipe(Mode):

    DefaultFont = FONT.font3x5

    def start(self, font, **params):
        #        self.fluepdot.rendering.setMode(Fluepdot.Mode.full)
        self.fluepdot.rendering.setMode(Fluepdot.Mode.diff)

        self.font = Font(font)
        log(str(self.font))

        info("start pipe".format())

        if font == FONT.font3x5:
            self.pos = [Position(0, 2), Position(0, 9)]
            self.buffer = [" ", " "]
        elif font == FONT.font5x5:
            self.pos = [Position(0, 2), Position(0, 9)]
            self.buffer = [" ", " "]
        elif font == FONT.font5x7:
            self.pos = [Position(0, 0), Position(0, 9)]
            self.buffer = [" ", " "]
        else:
            self.pos = [Position(0, 0)]
            self.buffer = [" "]
        self.rows = len(self.buffer)

        #        self.buf = self.font.render(self.msg)
        #        log(str(self.buf))

        self.mask = self.draw(**params)

        while True:
            line = sys.stdin.readline()
            if not line:
                log("end of file.")
                break
            debug("read " + line)
            if len(self.buffer) > 1:
                self.buffer[1] = self.buffer[0]
            self.buffer[0] = line.rstrip()[:30]
            self.draw(**params)

        return False

    def draw(self, **params):

        pos = Position(0, 0)

        self.mask = Mask()  #self.fluepdot.buffer.read()
        for i in range(self.rows):
            try:
                self.mask.addMask(self.font.render(self.buffer[i]),
                                  pos=self.pos[i])
            except Error as x:
                pass

#        self.mask.mask(self.buf,pos=pos)
        ret = self.fluepdot.buffer.write(self.mask)
        info(str(self.mask))
        return ret

    flags = [
        Mode.FLAG("font", DefaultFont),
    ]