Exemplo n.º 1
0
class PdsPlugin:
    def __init__(self, matrix=True, delay=0.2):
        self.matrix = matrix
        self.author = 'Infected'
        self.name = 'PDS Plugin'
        self.version = '0.1a'

        self.image = Image(64, 16)
        self.screen = Screen(matrix=matrix, show=True, fps=int(delay))
        self.screen.add(self.image, mode="invert")
        # self.monitor = Stream(matrix=self.matrix)
        # self.delay = float(delay)

    def get_info(self):
        """Get the current state and information of the plugin"""
        print(self.name, self.author, self.version, sep='\n')

    def get_delay(self):
        return self.delay

    def get_image(self):
        return self.image

    def set_pixmap(self, pixmap):
        self.image.set_pixmap(pixmap)

    def get_pixmap(self):
        return self.image.get_pixmap()

    def stream(self):

        self.screen.refresh()

    def blank(self):
        self.image.blank()
Exemplo n.º 2
0
class ClockPlugin:
    def __init__(self):
        self.author = 'Infected'
        self.name = 'Clock Plugin'
        self.version = 'V3.23-4.2-DOS.26__release'
        self.time = datetime.now()
        self.timer = Text()
        self.canvas = Image(64, 16)
        self.time_frame = Image(64, 16)
        self.canvas_draw = Drawer(self.canvas)
        self.invert = Image(64, 16)
        self.invert.fill()

        self.screen = Screen(matrix=True, show=False, fps=15)
        self.screen.add(self.time_frame, refresh=True)
        self.screen.add(self.timer, refresh=True, x=3, y=3)
        self.screen.add(self.canvas, refresh=False)
        self.screen.add(self.invert, mode='invert', refresh=False)

        self.gen_canvas()

    def get_info(self):
        """Get the current state and information of the plugin"""
        print(color(self.name, "red"),
              color(self.author, "green"),
              color(self.version, "magenta"),
              sep='\n')

    def gen_canvas(self):
        self.canvas_draw.line(0, 0, 63, 0)
        self.canvas_draw.line(0, 0, 0, 15)
        self.canvas_draw.line(0, 15, 63, 15)
        self.canvas_draw.line(63, 0, 63, 15)

    def refresh(self):
        self.time = datetime.now()

    def print_time(self):
        self.timer.edit('{}:{}:{}'.format(
            str(self.time.hour).zfill(2),
            str(self.time.minute).zfill(2),
            str(self.time.second).zfill(2)),
            font='fontbignum')

    def stream(self):
        self.refresh()
        self.print_time()
        self.screen.refresh()
Exemplo n.º 3
0
    def __init__(self):
        msg("input()", 2, "Hbd_plugin.__init__()")
        self.name_label = input(color("Enter label: ", "red")).lower()
        self.name_text = input(color("Enter name: ", "yellow")).lower()

        self.mask = Image(64,16)
        self.mask.fill()

        self.bg = Image(64, 16)
        self.drawer = Drawer(self.bg)
        self.drawer.dot(0, 0)
        self.drawer.dot(0, 15)
        self.drawer.dot(63, 0)
        self.drawer.dot(63, 15)

        self.label = Text(text="§" + self.name_label + "§")
        self.name = Text(text=self.name_text)

        self.screen = Screen(matrix=True, show=True, fps=1.7, tty='/dev/ttyACM1')

        self.screen.add(self.bg, refresh=False)

        xloc_label = (64 - abs(self.label.width)) // 2
        self.screen.add(self.label, x=xloc_label, y=1, refresh=False)

        xloc_text = (64 - abs(self.name.width)) // 2
        self.screen.add(self.name, x=xloc_text, y=8, refresh=False)

        self.screen.add(self.mask, refresh=False, mode="invert")
Exemplo n.º 4
0
    def __init__(self, matrix=True, delay=0.2):
        self.matrix = matrix
        self.author = 'Infected'
        self.name = 'PDS Plugin'
        self.version = '0.1a'

        self.image = Image(64, 16)
        self.screen = Screen(matrix=matrix, show=True, fps=int(delay))
        self.screen.add(self.image, mode="invert")
Exemplo n.º 5
0
class CrepeBot(ApplicationSession):
    def __init__(self, *args,**kwargs):
        super(CrepeBot, self).__init__(*args, **kwargs)
        self.screen = Screen(matrix=True, show=True)
        self.pbm = Image()
        self.bar = Image()
        self.splash = Text('init v1.0')
        self.percentage_text = Text('0')
        self.bar_x = 40
        self.bar_y = 7

        self.screen.add(self.pbm, 0, 0, False)
        self.screen.add(self.bar, self.bar_x, self.bar_y, True)
        self.screen.add(self.splash, 25, 0, True)
        self.screen.add(self.percentage_text, 40, 10, True)

    @coroutine
    def onJoin(self, details):
        def onRefresh(*queue):
            try:
                self.refresh(queue[0]['percent'], queue[0]['name'])
            except ValueError as e:
                print(e)
            except IndexError as e:
                print(e)
            print(queue)

        self.subscribe(onRefresh, 'queue')

    def refresh(self, percentage, name):
        self.splash.edit(str(name).lower)
        self.refresh_bar(percentage)
        self.percentage_text.edit(str(percentage) + '%')
        self.screen.refresh()

    def refresh_bar(self, percentage):
        self.bar.draw_line(x1=0, y1=0, x2=percentage // 5, y2=0)
        self.bar.draw_line(x1=0, y1=1, x2=percentage // 5, y2=1)
Exemplo n.º 6
0
    def __init__(self, *args,**kwargs):
        super(CrepeBot, self).__init__(*args, **kwargs)
        self.screen = Screen(matrix=True, show=True)
        self.pbm = Image()
        self.bar = Image()
        self.splash = Text('init v1.0')
        self.percentage_text = Text('0')
        self.bar_x = 40
        self.bar_y = 7

        self.screen.add(self.pbm, 0, 0, False)
        self.screen.add(self.bar, self.bar_x, self.bar_y, True)
        self.screen.add(self.splash, 25, 0, True)
        self.screen.add(self.percentage_text, 40, 10, True)
Exemplo n.º 7
0
    def render(self, world, use_alpha=True):
        total_colors = torch.zeros((self.image_width * self.image_height, 3),
                                   device=self.device)
        total_alpha = torch.zeros((self.image_width * self.image_height, 1),
                                  device=self.device)
        for _ in range(self.antialiasing):
            x = torch.tile(
                torch.linspace(0, (self.out_shape[1] - 1) / self.out_shape[1],
                               self.out_shape[1]),
                (self.out_shape[0], )).unsqueeze(1)
            y = torch.repeat_interleave(
                torch.linspace(0, (self.out_shape[0] - 1) / self.out_shape[0],
                               self.out_shape[0]),
                self.out_shape[1]).unsqueeze(1)

            x += torch.rand(x.shape) / self.out_shape[1]
            y += torch.rand(y.shape) / self.out_shape[0]

            ray = Rays(origin=self.origin,
                       directions=self.lower_left_corner +
                       x * self.horizontal + y * self.vertical - self.origin,
                       device=self.device)

            color = torch.full(ray.pos.size(),
                               self.background_color,
                               device=self.device)
            alpha = torch.zeros((self.image_width * self.image_height, 1),
                                device=self.device)

            self.timestep_init((self.image_width * self.image_height, 1))

            for _ in tqdm(range(self.steps), disable=not self.debug):
                ray, color, alpha = self.step(ray, world, color, alpha)

            total_colors += color
            total_alpha = torch.logical_or(total_alpha, alpha)

        scale = 1 / self.antialiasing
        total_colors = torch.sqrt(scale * total_colors)
        return Image.from_flat(total_colors,
                               total_alpha,
                               self.image_width,
                               self.image_height,
                               use_alpha=use_alpha)
Exemplo n.º 8
0
    def __init__(self):
        self.author = 'Infected'
        self.name = 'Clock Plugin'
        self.version = 'V3.23-4.2-DOS.26__release'
        self.time = datetime.now()
        self.timer = Text()
        self.canvas = Image(64, 16)
        self.time_frame = Image(64, 16)
        self.canvas_draw = Drawer(self.canvas)
        self.invert = Image(64, 16)
        self.invert.fill()

        self.screen = Screen(matrix=True, show=False, fps=15)
        self.screen.add(self.time_frame, refresh=True)
        self.screen.add(self.timer, refresh=True, x=3, y=3)
        self.screen.add(self.canvas, refresh=False)
        self.screen.add(self.invert, mode='invert', refresh=False)

        self.gen_canvas()
Exemplo n.º 9
0
    def __init__(
            self,
            width=MAT_WIDTH,
            height=MAT_HEIGHT,
            matrix=True,
            show=False,
            guishow=False,
            fps=0,
            tty='/dev/ttyACM0'):

        if fps > 0:
            self.fps = 1 / fps
        else:
            self.fps = 0
        self.image = Image(width=width, height=height)
        self.streamer = Stream(matrix=matrix, tty=tty)
        self.show = show
        self.childs = []
        if guishow:
            self.show_gui()
Exemplo n.º 10
0
    def __init__(self, x=64, y=16):
        self.image = Image(width=x, height=y)
        self.drawer = Drawer(self.image)
        self.updater = Updater(self)

        self.x = x
        self.y = y

        self.live = False
        self.drawmode = True
        self.updatethread = None

        self.create_window()
        self.create_canvas()
        self.create_buttons()
        self.root.mainloop()    # Launch tkinter eventloop
        # This is run only after tkinter is closed and its event loop ends
        # Cleaning up any potential loose ends at close of program
        if self.updatethread is not None:
            self.updater.live = False
            self.updatethread.join()
Exemplo n.º 11
0
class Hbd_plugin:
    def __init__(self):
        msg("input()", 2, "Hbd_plugin.__init__()")
        self.name_label = input(color("Enter label: ", "red")).lower()
        self.name_text = input(color("Enter name: ", "yellow")).lower()

        self.mask = Image(64,16)
        self.mask.fill()

        self.bg = Image(64, 16)
        self.drawer = Drawer(self.bg)
        self.drawer.dot(0, 0)
        self.drawer.dot(0, 15)
        self.drawer.dot(63, 0)
        self.drawer.dot(63, 15)

        self.label = Text(text="§" + self.name_label + "§")
        self.name = Text(text=self.name_text)

        self.screen = Screen(matrix=True, show=True, fps=1.7, tty='/dev/ttyACM1')

        self.screen.add(self.bg, refresh=False)

        xloc_label = (64 - abs(self.label.width)) // 2
        self.screen.add(self.label, x=xloc_label, y=1, refresh=False)

        xloc_text = (64 - abs(self.name.width)) // 2
        self.screen.add(self.name, x=xloc_text, y=8, refresh=False)

        self.screen.add(self.mask, refresh=False, mode="invert")

    def stream(self):
        try:
            blink = False
            while True:
                blink = not blink
                if blink:
                    self.mask.blank()
                else:
                    self.mask.fill()

                self.screen.refresh()
        except KeyboardInterrupt:
            print()
            msg(self.name_label, 0, "label")
            msg(self.name_text, 0, "name")
            exit()
Exemplo n.º 12
0
    def render(self, world, antialiasing=1):
        colors = torch.zeros((self.image_width * self.image_height, 3),
                             device=dev)
        for _ in range(antialiasing):
            x = torch.tile(
                torch.linspace(0, (self.out_shape[1] - 1) / self.out_shape[1],
                               self.out_shape[1]),
                (self.out_shape[0], )).unsqueeze(1)
            y = torch.repeat_interleave(
                torch.linspace(0, (self.out_shape[0] - 1) / self.out_shape[0],
                               self.out_shape[0]),
                self.out_shape[1]).unsqueeze(1)
            if antialiasing != 1:
                x += torch.rand(x.shape) / self.out_shape[1]
                y += torch.rand(y.shape) / self.out_shape[0]

            ray = Rays(origin=self.origin,
                       directions=self.lower_left_corner +
                       x * self.horizontal + y * self.vertical - self.origin)
            colors += ray.trace(world, self.render_depth)

        scale = 1 / antialiasing
        colors = torch.sqrt(scale * colors)
        return Image.from_flat(colors, self.image_width, self.image_height)
Exemplo n.º 13
0
class MatrixDrawer:
    def __init__(self, x=64, y=16):
        self.image = Image(width=x, height=y)
        self.drawer = Drawer(self.image)
        self.updater = Updater(self)

        self.x = x
        self.y = y

        self.live = False
        self.drawmode = True
        self.updatethread = None

        self.create_window()
        self.create_canvas()
        self.create_buttons()
        self.root.mainloop()    # Launch tkinter eventloop
        # This is run only after tkinter is closed and its event loop ends
        # Cleaning up any potential loose ends at close of program
        if self.updatethread is not None:
            self.updater.live = False
            self.updatethread.join()

    def create_window(self):
        self.root = tkinter.Tk()
        self.root.configure(bg="light blue")
        self.root.title("Matrix Drawer")

        self.root.bind("<Button-1>", self.mouse_interact_left)
        self.root.bind("<B1-Motion>", self.mouse_interact_left)
        self.root.bind("<Button-3>", self.mouse_interact_right)
        self.root.bind("<B3-Motion>", self.mouse_interact_right)

    def create_canvas(self):
        self.canvasframe = tkinter.Frame(self.root)
        self.canvasframe.pack(side="right")
        pixel_size = 20
        self.canvas = tkinter.Canvas(self.canvasframe, bg="black",
                                     height=self.y*pixel_size,
                                     width=self.x*pixel_size)

        self.canvas.grid(row=0, column=0)

        for y in range(self.y):
            for x in range(self.x):
                self.canvas.create_oval(x*pixel_size, y*pixel_size,
                                        x*pixel_size + pixel_size,
                                        y*pixel_size + pixel_size,
                                        fill="grey")

    def create_buttons(self):
        self.buttonframe = tkinter.Frame(self.root, bg="light blue")
        self.buttonframe.pack(side="left")
        self.updatebutton = tkinter.Button(self.buttonframe,
                                             text="Send To Matrix",
                                             bg="Yellow",
                                             command=self.updater.one_refresh
                                             )
        self.clearbutton = tkinter.Button(self.buttonframe,
                                          text="Clear All",
                                          bg="Yellow",
                                          command=self.clearall
                                          )

        self.fillbutton = tkinter.Button(self.buttonframe,
                                         text="Fill All",
                                         bg="Yellow",
                                         command=self.fillall
                                         )
        self.livebutton = tkinter.Button(self.buttonframe,
                                         text="Status: Manual",
                                         bg="Yellow",
                                         command=self.togglelive
                                         )
        self.drawbutton = tkinter.Button(self.buttonframe,
                                         command=self.toggledraw,
                                         text="Draw Mode",
                                         bg="Yellow",
                                         relief="sunken",
                                         activebackground="Yellow"
                                         )
        self.erasebutton = tkinter.Button(self.buttonframe,
                                          command=self.toggleerase,
                                          text="Erase Mode",
                                          bg="Grey",
                                          activebackground="Grey"
                                          )

        self.updatebutton.grid(row=0, column=0, columnspan=2)
        self.clearbutton.grid(row=1, column=0, columnspan=2)
        self.fillbutton.grid(row=2, column=0, columnspan=2)
        self.livebutton.grid(row=3, column=0, columnspan=2)
        self.drawbutton.grid(row=4, column=0)
        self.erasebutton.grid(row=4, column=1)

    def toggledraw(self):
        """
        Sets left mouse button to drawing
        """
        self.drawmode = True
        self.drawbutton.configure(relief="sunken",
                                  bg="Yellow",
                                  activebackground="Yellow")
        self.erasebutton.configure(relief="raised",
                                   bg="Grey",
                                   activebackground="Grey")

    def toggleerase(self):
        """
        Sets left mouse button to erasing
        """
        self.drawmode = False
        self.drawbutton.configure(relief="raised",
                                  bg="Grey",
                                  activebackground="Grey")
        self.erasebutton.configure(relief="sunken",
                                   bg="Yellow",
                                   activebackground="Yellow")

    def togglelive(self):
        """
        Creates new thread and launches permanent loop to keep matrix updated
        in real time
        """
        if self.updater.live:   # we were already live, going manual now
            self.livebutton.configure(text="Status: Manual")
            # Stop the infinite loop in the other thread and terminate it
            self.updater.live = False
            self.updatethread.join()
            self.updatethread = None

        else:           # we were manual, now going live
            self.livebutton.configure(text="Status: Live")
            self.updater.live = True
            # Open a new thread and launch the infinite update loop
            self.updatethread = threading.Thread(target=self.updater.toggle_live)
            self.updatethread.start()

    def clearall(self):
        """
        Clears all pixels, resetting them back to grey
        """
        for i in range(self.x * self.y):
            self.canvas.itemconfig(i+1, fill="grey")

        self.image.blank()

    def fillall(self):
        """
        Fills all pixels, setting them to red
        """
        for i in range(self.x * self.y):
            self.canvas.itemconfig(i+1, fill="red")

        self.image.fill()

    def mouse_interact_left(self, event):
        """
        Left mouse's function depends on the 2 draw/erase buttons available to
        the user
        """
        if event.widget.winfo_id() == self.canvas.winfo_id():
            x = self.canvas.canvasx(event.x)
            y = self.canvas.canvasy(event.y)

            pixel = self.canvas.find_closest(x, y)

            if self.drawmode:
                self.canvas.itemconfig(pixel, fill="red")
                self.drawer.dot((pixel[0]-1) % self.x,
                                (pixel[0] - 1) // self.x)

            else:
                self.canvas.itemconfig(pixel, fill="grey")
                self.drawer.erase((pixel[0]-1) % self.x,
                                (pixel[0] - 1) // self.x)

    def mouse_interact_right(self, event):
        """
        Right mouse button always used for erasing
        """
        if event.widget.winfo_id() == self.canvas.winfo_id():
            x = self.canvas.canvasx(event.x)
            y = self.canvas.canvasy(event.y)

            pixel = self.canvas.find_closest(x, y)
            self.canvas.itemconfig(pixel, fill="grey")
            self.drawer.erase((pixel[0]-1) % self.x,
                              (pixel[0] - 1) // self.x)
Exemplo n.º 14
0
class Screen:
    """
    Screen is the Image manager for the plugins.
    Each child of it is an Image and can be added with the 'add' method.
    On each 'refresh' all the images are flattened to one Image and sent to
    the streamer

    Screen must have the same size of the matrix

    Keyword arguments:
    x -- x height (default MAT_HEIGHT)
    y -- y width (default MAT_WIDTH)
    matrix -- output to serial (default True)
    show -- verbose output (default False)
    fps -- not implemented (default 0)
    """
    def __init__(
            self,
            width=MAT_WIDTH,
            height=MAT_HEIGHT,
            matrix=True,
            show=False,
            guishow=False,
            fps=0,
            tty='/dev/ttyACM0'):

        if fps > 0:
            self.fps = 1 / fps
        else:
            self.fps = 0
        self.image = Image(width=width, height=height)
        self.streamer = Stream(matrix=matrix, tty=tty)
        self.show = show
        self.childs = []
        if guishow:
            self.show_gui()

    def add(self, element, x=0, y=0, refresh=True, mode="fill", name="Child"):
        """
        Add a new Image to the childs.

        Keyword arguments:
        image -- Image
        x -- x paste location (default 0)
        y -- y paste location (default 0)
        refresh -- blank Image after refresh (default True)
        mode -- paste mode [Image.paste()] (default "fill")
        name -- name (default "Child")
        """
        if str(type(element)) == "<class 'libs.slide.Slide'>":
            self.childs.append((element.view, x, y, refresh, mode, name))
        elif str(type(element)) == "<class 'libs.text.Text'>":
            self.childs.append((element, x, y, refresh, mode, name))
        elif str(type(element)) == "<class 'libs.image.Image'>":
            self.childs.append((element, x, y, refresh, mode, name))
        else:
            msg("not a valid element", 2, "Screen.add()", type(element))

    def remove(self, id_):
        """Delete a child by his id"""
        if id_ <= len(self.childs) - 1:
            msg(self.childs.pop(id_)[5], 0, "Removed")
        else:
            msg("no such child", 2, "Screen.remove()", len(self.childs), id_)


    def refresh(self):
        """
        Flatten all childs into one Image and send it to the streamer
        and/or print it in the terminal.
        """
        self.image.blank()
        for child in self.childs:
            self.image.paste(child[0], x=child[1], y=child[2], mode=child[4])

            # Refresh
            if child[3]:
                child[0].blank()

        self.streamer.set_data(self.image)
        self.streamer.send_to_serial()
        if self.show:
            system('clear')
            print(self.streamer)
        sleep(self.fps)

    def __str__(self):
        count = len(self.childs) - 1
        string = color("Screen", "green") + "\n"
        for n, child in enumerate(self.childs):
            if n < count:
                string += color('├─', 'blue')
            else:
                string += color('└─', 'blue')

            string += color(str(n), 'red')
            string += color("..", 'yellow')
            string += color(child[5], 'green', False, None, "Underline")
            if child[3]:
                string += "[" + color("1", "magenta", False) + "]"
            else:
                string += "[" + color("O", "magenta", False) + "]"
            string += "\n"
        return string

    def show_gui(self):
        """
        Instantiates the tkinter gui and gets it running. The gui is updated
        from within itself by a function that is run at the end of each
        turn of the tkinter mainloop.
        """
        gui_thread = Thread(target=lambda: GuiViewer(self.image))
        gui_thread.daemon = True
        gui_thread.start()