def __init__(self,
                 r,
                 fill=False,
                 c=(225, 0, 0),
                 matrix=None,
                 position=None,
                 environment=None,
                 mass=np.random.randint(1, 10),
                 velocity=None,
                 led_size=(64, 32),
                 bounciness=np.random.sample(),
                 gravity_enabled=True):

        super(CirclePhysSolid, self).__init__(position=position,
                                              environment=environment,
                                              mass=mass,
                                              matrix=matrix,
                                              c=c,
                                              velocity=velocity,
                                              led_size=led_size,
                                              bounciness=bounciness,
                                              gravity_enabled=gravity_enabled)

        self.fill = fill
        self.r = r
        self.pen = Jworld.Pen(canvas=self.m)
def run_visualizer(matrix_length, matrix_height):
    audio = Jworld.JAudio.AudioStream()
    Dmatrix = audio.Dmatrix
    pen = Jworld.Pen(canvas=Dmatrix)

    x_pos = 0
    y_pos = 0

    r_colour_thresh = 0
    g_colour_thresh = 0
    b_colour_thresh = 0

    x_increment = 8  # length / number of boxes

    while True:
        spectrum_values = audio.update()["spectrum"][::8]  # 8 boxes
        waveform_values = util.clamp(audio.update()["peak"], 0, 100)

        while x_pos > matrix_length:
            r_colour_thresh = waveform_values
            b_colour_thresh = x_pos

            # gets the value of the spectrogram
            y_pos = util.clamp(10 * spectrum_values[x_pos/x_increment], 0, matrix_height)

            colour = (r_colour_thresh, g_colour_thresh, b_colour_thresh)
            pen.draw_rect(x_pos + 2, y_pos + 2, x_pos + 4, y_pos + 4, colour, fill=True)
            x_pos += x_increment

        Dmatrix.Clear()
Ejemplo n.º 3
0
def run_visualizer(matrix_length=64,
                   matrix_height=32,
                   time_limited=False,
                   max_time=60):
    audio = Jworld.JAudio.Waveform()
    matrix = audio.Dmatrix
    pen = Jworld.Pen(canvas=matrix)

    initial_time = time.time()

    run = True

    cent_x = matrix.width / 2
    cent_y = matrix.height / 2

    rotate_square = min(matrix.width, matrix.height) * 1.41
    min_rotate = cent_x - rotate_square / 2
    max_rotate = cent_x + rotate_square / 2

    display_square = min(matrix.width, matrix.height) * 0.7
    min_display = cent_x - display_square / 2
    max_display = cent_x + display_square / 2

    deg_to_rad = 2 * 3.14159265 / 360
    rotation = 0
    offset_canvas = matrix.CreateFrameCanvas()

    while run:
        rotation += 1
        rotation %= 360

        for x in range(int(min_rotate), int(max_rotate)):
            for y in range(int(min_rotate), int(max_rotate)):
                ret = rotate(x - cent_x, y - cent_x, deg_to_rad * rotation)
                rot_x = ret["new_x"]
                rot_y = ret["new_y"]

                if x >= min_display and x < max_display and y >= min_display and y < max_display:
                    offset_canvas.SetPixel(
                        rot_x + cent_x, rot_y + cent_y,
                        scale_col(x, min_display, max_display),
                        255 - scale_col(y, min_display, max_display),
                        scale_col(y, min_display, max_display))
                else:
                    offset_canvas.SetPixel(rot_x + cent_x, rot_y + cent_y, 0,
                                           0, 0)

        offset_canvas = matrix.SwapOnVSync(offset_canvas)

        if time_limited:
            delta_time = int(time.time() - initial_time)
            if delta_time > max_time:
                while matrix.brightness > 5:
                    matrix.brightness -= 1
                    time.sleep(.01)
                run = False
Ejemplo n.º 4
0
def display_message(message):
    # initializing the pen object for writing text
    pen = Jworld.Pen(canvas=Jworld.RGBMatrix(options=Jworld.options))
    font = graphics.Font()
    font.LoadFont("../../../fonts/7x13.bdf")

    x = 64
    while True:
        pen.matrix.Clear()
        len = pen.draw_text(c=(225, 0, 0), font=font, text=message, x=0, y=0)

        time.sleep(.03)
        x -= 1
        if x + len < 0:
            break
Ejemplo n.º 5
0
def run_text_scroller(text="hello world"):
    pen = Jworld.Pen(canvas=None)
    matrix = pen.matrix

    font = Jworld.graphics.Font()
    font.LoadFont("../../../fonts/7x13.bdf")

    textColor = Jworld.graphics.Color(255, 255, 0)
    pos = matrix.width
    my_text = text

    while True:
        matrix.Clear()
        len = Jworld.graphics.DrawText(matrix, font, pos, 10, textColor,
                                       my_text)
        pos -= 1
        if pos + len < 0:
            pos = matrix.width

        Jworld.time.sleep(0.05)
Ejemplo n.º 6
0
def run_visualizer(matrix_length=64, matrix_height=32, time_limited=False, max_time=60):
    audio = Jworld.JAudio.Waveform()
    Dmatrix = audio.Dmatrix
    pen = Jworld.Pen(canvas=Dmatrix)

    initial_time = time.time()

    run = True

    while run:
        # Do stuff

        Dmatrix.Clear()

        if time_limited:
            delta_time = int(time.time() - initial_time)
            if delta_time > max_time:
                while Dmatrix.brightness > 5:
                    Dmatrix.brightness -= 1
                    time.sleep(.01)
                run = False
Ejemplo n.º 7
0
def run_visualizer(matrix_length=64,
                   matrix_height=32,
                   time_limited=False,
                   max_time=60):
    audio = Jworld.JAudio.Waveform()
    Dmatrix = audio.Dmatrix
    pen = Jworld.Pen(canvas=Dmatrix)

    initial_time = time.time()

    run = True

    updates_over_threshold = 0
    while run:
        peak = int(10 * Jworld.np.log(audio.update() + 1))
        pen.draw_rect(32 + peak,
                      16 + peak,
                      32 - peak,
                      16 - peak, (50, 50, 50),
                      fill=True,
                      gradient="r_grad_x")

        pen.draw_line(32, 16, 32 + peak * 2, peak * 2, (peak, 0, 0))
        pen.draw_line(32, 16, 32 - peak * 2, peak * 2, (peak, 0, 0))

        pen.draw_line(32, 16, 32 + peak * 2, 32 - peak * 2, (peak, 0, 0))
        pen.draw_line(32, 16, 32 - peak * 2, 32 - peak * 2, (peak, 0, 0))

        for n in range(peak):
            x = random.randint(0, 65)
            y = random.randint(0, 33)
            Dmatrix.SetPixel(x, y)

        if peak > 20:
            updates_over_threshold += 1
        else:
            updates_over_threshold -= 1

        for n in range(updates_over_threshold):
            x1 = random.randint(0, 65)
            y1 = random.randint(0, 33)

            x2 = random.randint(x1 - 5, x1 + 5)
            y2 = random.randint(y1 - 5, y1 + 5)

            pen.draw_rect(x1,
                          y1,
                          x2,
                          y2, (50, 50, updates_over_threshold
                               if updates_over_threshold < 225 else 225),
                          fill=True,
                          gradient="r_grad_x")

        Dmatrix.Clear()

        if time_limited:
            delta_time = int(time.time() - initial_time)
            if delta_time > max_time:
                while Dmatrix.brightness > 5:
                    Dmatrix.brightness -= 1
                    time.sleep(.01)
                run = False
Ejemplo n.º 8
0
 def __init__(self):
     self.tree = []
     self.tree.append(Walker(Vector(32, 16)))
     self.pen = Jworld.Pen(canvas=None)
Ejemplo n.º 9
0
import subprocess
import time
import sys

sys.path.insert(1, '/Users/martingleave/Documents/GitHub/JG_rasp-1')
import led_matrix_interface as Jworld
from led_matrix_interface import graphics

# initializing the pen object for writing text
pen = Jworld.Pen(canvas=Jworld.RGBMatrix(options=Jworld.options))

start_time = time.time()
delta_time = time.time() - start_time

font = graphics.Font()
font.LoadFont("../../../fonts/7x13.bdf")

while delta_time > 0:
    delta_time = 6 - int(time.time() - start_time)
    pen.draw_text(c=(225, 0, 0),
                  font=font,
                  text="Time To Shutdown..." + str(delta_time),
                  x=0,
                  y=16)
    time.sleep(1)
    pen.matrix.Clear()

subprocess.call(["sudo", "halt", "-p"])