예제 #1
0
def update(theta, rho, photo, primary_color, secondary_color, balls, strip):
    global transition, time_start
    if time_start == 0:
        time_start = timer()
        transition = 0
        # print "Start fade timer {0}\n".format(time_start),
        sys.stdout.flush()

    percent = rho
    if transition < 1.0:
        for i in range(strip.numPixels() + 1):
            strip.setPixelColor(
                i,
                colorBlend(strip.getPixelColor(i),
                           colorBlend(secondary_color, primary_color, percent),
                           easeOut(transition)))
    else:
        fill(strip, colorBlend(secondary_color, primary_color,
                               percent))  # fill with color based on rho only

    # increment time
    if transition < 1.0:
        time_end = timer()
        transition += time_end - time_start
        time_start = time_end
예제 #2
0
def update(theta, rho, photo, primary_color, secondary_color, balls, strip):
    global transition, time_start
    if time_start == 0:
        time_start = timer()
        transition = 0
        # print "Start rainbow timer {0}\n".format(time_start),
        sys.stdout.flush()

    led_count = strip.numPixels()

    # offset of rainbow
    wheel_deg = int((-theta%360) / 360 * 255)
    # print "theta %s = %s \n" % (theta, wheel_deg),

    for i in range(0,led_count):
        pixel_offset = float(i)/led_count*255.0
        offset = (int(pixel_offset)+wheel_deg) & 255;
        # print "%d wheel_deg %s degrees + pixel_offset %s = %s \n" % (i, wheel_deg, pixel_offset, offset),
        if transition < 1.0:
            strip.setPixelColor(i, colorBlend(strip.getPixelColor(i), wheel(offset),easeOut(transition)))
        else:
            strip.setPixelColor(i, wheel(offset))

    # increment time
    if transition < 1.0:
        time_end = timer()
        transition += time_end - time_start
        time_start = time_end
예제 #3
0
def update(theta, rho, photo, primary_color, secondary_color, balls, strip):
    global transition, time_start, breathe_fade, blue, white
    if time_start == 0:
        time_start = timer()
        transition = 0
        # print "Start software_update timer {0}\n".format(time_start),
        sys.stdout.flush()

    percent = 0.5 + sin(breathe_fade) * 0.5
    if transition < 1.0:
        for i in range(strip.numPixels()+1):
            strip.setPixelColor(i, colorBlend(strip.getPixelColor(i),colorBlend(white,blue,percent),easeOut(transition)))
    else:
        fill(strip, colorBlend(white,blue,percent)) # fill with color based on rho only

    breathe_fade += 0.005

    # increment time
    if transition < 1.0:
        time_end = timer()
        transition += time_end - time_start
        time_start = time_end
예제 #4
0
def update(theta, rho, photo, primary_color, secondary_color, balls, strip):
    global transition, time_start
    if time_start == 0:
        time_start = timer()
        transition = 0
        # print "Start white timer {0}\n".format(time_start),
        # sys.stdout.flush()

    if transition < 1.0:
        for i in range(strip.numPixels() + 1):
            strip.setPixelColor(
                i,
                colorBlend(strip.getPixelColor(i), Color(0, 0, 0, 0),
                           easeOut(transition)))
    else:
        fill(strip, Color(0, 0, 0, 0))  # fill with white

    # increment time
    if transition < 1.0:
        time_end = timer()
        transition += time_end - time_start
        time_start = time_end
예제 #5
0
def update(theta, rho, photo, primary_color, secondary_color, balls, strip):
    global transition, time_start, color_pos, color_range, color_speed, no_color

    if time_start == 0:
        time_start = timer()
        transition = 0
        # print "Start spread timer {0}\n".format(time_start),
        sys.stdout.flush()

    led_count = strip.numPixels()

    # assign h_theta
    h_theta = theta

    # increment sine wave
    # value = rho + sin(color_pos) * color_range;
    # if value < 0: # wrap
    #     value += 256

    # print "Balls %s, Wheel %s\n" % (balls, int(rho*255 + theta*0.2) % 255),
    # sys.stdout.flush()

    # color of spread by ball
    # ball_color = wheel(int(rho*255)) # change based on rho
    ball_color = wheel(int(rho * 255 + theta * 0.2) %
                       255)  # change based on rho (and theta)
    # ball_color = colorBlend(primary_color, secondary_color, rho) # blend between primary/secondary based on rho
    # ball_color = wheel(int(value*255)%255) # change based on rho + sine wave variation
    second_color = wheel(int(rho * 255 + theta * 0.2 - 128) %
                         255)  # change based on rho (and theta)

    # spread out the pixel color based on rho
    # max_spread = 85 # degress on either side of pixel to spread white
    # min_spread = 10 # degress on either side of pixel to spread white
    # spread = max_spread - (max_spread * rho) + min_spread
    spread = 15  # force to specific width
    spread_l = h_theta - spread
    spread_r = h_theta + spread

    start = int((spread_l * led_count) / 360)
    end = int((spread_r * led_count) / 360) + 1
    if (end < start):
        end += led_count

    h_fixed = h_theta % 360

    # print "Rho %s, Theta %s, Adjusted Theta %s, Photo %s, Brightness %s 0.5 %s 0.25 %s\n" % (rho, theta, h_theta, photo, brightness, max(int(brightness/2),1), max(int(brightness/4),1)),
    # sys.stdout.flush()

    for x in range(start, end):
        pos = x % led_count
        degrees = (float(pos * 360) / led_count)

        # fix wrapping degrees
        if (degrees > h_fixed + 180):
            degrees -= 360
        elif (degrees < h_fixed - 180):
            degrees += 360

        # ramp brightness
        t = abs(h_fixed - degrees) / spread

        if t > 0 and t <= 1.0:
            percent = easeIn(t)  # choose an ease function from above
            strip.setPixelColor(
                pos, colorBlend(ball_color, strip.getPixelColor(pos), percent))

            # print "pos {0} ( {1} - {2} ) / {3}, percent {4}\n".format(pos, h_fixed, degrees, spread, t),
            # sys.stdout.flush()

    # second ball coloring
    if balls > 1:
        h_theta = h_theta + 180

        spread = 10  # force to specific width
        spread_l = h_theta - spread
        spread_r = h_theta + spread

        start = int((spread_l * led_count) / 360)
        end = int((spread_r * led_count) / 360) + 1
        if (end < start):
            end += led_count

        h_fixed = h_theta % 360

        for x in range(start, end):
            pos = x % led_count
            degrees = (float(pos * 360) / led_count)

            # fix wrapping degrees
            if (degrees > h_fixed + 180):
                degrees -= 360
            elif (degrees < h_fixed - 180):
                degrees += 360

            # ramp brightness
            t = abs(h_fixed - degrees) / spread

            if t > 0 and t <= 1.0:
                percent = easeIn(t)  # choose an ease function from above
                strip.setPixelColor(
                    pos,
                    colorBlend(second_color, strip.getPixelColor(pos),
                               percent))

    # increment time
    time_end = timer()
    if transition < 1.0:
        transition += time_end - time_start
    # color_pos += (time_end - time_start) * color_speed;
    time_start = time_end
예제 #6
0
def update(theta, rho, photo, primary_color, secondary_color, balls, strip):
    global transition, time_start
    if time_start == 0:
        time_start = timer()
        transition = 0
        # print "Start spread timer {0}\n".format(time_start),
        sys.stdout.flush()

    led_count = strip.numPixels()

    # assign h_theta
    h_theta = theta

    # color of non-pixels
    bg_color = secondary_color

    # color of spread by ball
    ball_color = primary_color

    # spread out the pixel color based on rho
    max_spread = 85 # degress on either side of pixel to spread white
    min_spread = 10 # degress on either side of pixel to spread white
    spread = max_spread - (max_spread * rho) + min_spread
    # spread = 45 # force to specific width
    spread_l = h_theta - spread
    spread_r = h_theta + spread

    start = int( (spread_l * led_count) / 360 )
    end = int( (spread_r * led_count) / 360 ) + 1
    if (end < start):
        end += led_count

    h_fixed = h_theta % 360

    if transition < 1.0:
        for i in range(strip.numPixels()+1):
            if i < start%led_count or i > end%led_count:
                strip.setPixelColor(i, colorBlend(strip.getPixelColor(i),bg_color,easeOut(transition)))
    else:
        fill(strip, bg_color) # default color

    # print "Rho %s, Theta %s, Adjusted Theta %s, Photo %s, Brightness %s 0.5 %s 0.25 %s\n" % (rho, theta, h_theta, photo, brightness, max(int(brightness/2),1), max(int(brightness/4),1)),
    # sys.stdout.flush()

    for x in range(start, end):
        pos = x % led_count
        degrees = (float(pos * 360) / led_count)

        # fix wrapping degrees
        if (degrees > h_fixed + 180):
            degrees -= 360
        elif (degrees < h_fixed - 180):
            degrees += 360

        # ramp brightness
        t = abs(h_fixed - degrees) / spread
        percent = easeInQuad(t) # choose an ease function from above

        # print "pos {0} ( {1} - {2} ) / {3}, percent {4}\n".format(pos, h_fixed, degrees, spread, t),
        # sys.stdout.flush()

        if transition < 1.0:
            strip.setPixelColor(pos, colorBlend(strip.getPixelColor(pos),colorBlend(ball_color,bg_color,percent),easeOut(transition)))
        else:
            strip.setPixelColor(pos, colorBlend(ball_color,bg_color,percent))

    # increment time
    if transition < 1.0:
        time_end = timer()
        transition += time_end - time_start
        time_start = time_end
예제 #7
0
def update(theta, rho, photo, primary_color, secondary_color, balls, strip):
    global state, transition, current_primary, current_secondary, time, time_start, length
    if time_start == 0:
        time_start = timer()
        # fill(strip, Color(0,0,0,0))

    led_count = strip.numPixels()

    # draw current state
    if state == 0:  #white
        if transition < 1.0:
            for i in range(strip.numPixels() + 1):
                strip.setPixelColor(
                    i,
                    colorBlend(strip.getPixelColor(i), current_primary,
                               easeOut(transition)))
        else:
            fill(strip, current_primary)  # default color
    elif state == 2:  # rainbow
        # offset of rainbow
        wheel_deg = int((-theta % 360) / 360 * 255)
        for i in range(0, led_count):
            pixel_offset = float(i) / led_count * 255.0
            offset = (int(pixel_offset) + wheel_deg) & 255
            if transition < 1.0:
                strip.setPixelColor(
                    i,
                    colorBlend(strip.getPixelColor(i), wheel(offset),
                               easeOut(transition)))
            else:
                strip.setPixelColor(i, wheel(offset))
    elif state == 4:  # spread
        # spread out the pixel color based on rho
        max_spread = 85  # degress on either side of pixel to spread white
        min_spread = 10  # degress on either side of pixel to spread white
        spread = max_spread - (max_spread * rho) + min_spread
        spread_l = theta - spread
        spread_r = theta + spread

        start = int((spread_l * led_count) / 360)
        end = int((spread_r * led_count) / 360) + 1
        if (end < start):
            end += led_count

        if transition < 1.0:
            for i in range(strip.numPixels() + 1):
                if i < start % led_count or i > end % led_count:
                    strip.setPixelColor(
                        i,
                        colorBlend(strip.getPixelColor(i), current_secondary,
                                   easeOut(transition)))
        else:
            fill(strip, current_secondary)  # default color

        h_fixed = theta % 360

        for x in range(start, end):
            pos = x % led_count
            degrees = (float(pos * 360) / led_count)

            # fix wrapping degrees
            if (degrees > h_fixed + 180):
                degrees -= 360
            elif (degrees < h_fixed - 180):
                degrees += 360

            # ramp brightness
            t = abs(h_fixed - degrees) / spread
            percent = easeInQuad(t)  # choose an ease function from above

            if transition < 1.0:
                strip.setPixelColor(
                    pos,
                    colorBlend(
                        strip.getPixelColor(pos),
                        colorBlend(current_primary, current_secondary,
                                   percent), easeOut(transition)))
            else:
                strip.setPixelColor(
                    pos, colorBlend(current_primary, current_secondary,
                                    percent))
    else:  # warm/solid
        if transition < 1.0:
            for i in range(strip.numPixels() + 1):
                strip.setPixelColor(
                    i,
                    colorBlend(strip.getPixelColor(i), current_primary,
                               easeOut(transition)))
        else:
            fill(strip, current_primary)  # default color

    # increment time
    time_end = timer()
    time += time_end - time_start
    transition += time_end - time_start
    time_start = time_end

    # change states
    if time > length:
        time = 0
        transition = 0
        state += 1
        if state > 2:
            state = 0
            current_primary = Color(255, 255, 255, 255)
        elif state == 1:  # warm white
            current_primary = Color(255, 98, 0, 89)
        elif state == 3:  # random solid color
            current_primary = wheel(randrange(256))
        elif state == 4:  # random spread background
            current_primary = Color(255, 255, 255, 255)
            current_secondary = wheel(randrange(256))
예제 #8
0
def update(theta, rho, photo, primary_color, secondary_color, balls, strip):
    global transition, time_start
    if time_start == 0:
        time_start = timer()
        transition = 0
        # print "Start calibrate timer {0}\n".format(time_start),
        sys.stdout.flush()

    led_count = strip.numPixels()

    # assign h_theta
    h_theta = theta

    brightness = int(255 * (photo / 1024)) + 1

    # color of non-pixels
    bg_color = Color(0, 0, 0, 0)

    # color of spread by ball
    ball_color = Color(128, 128, 128, 128)

    # spread out the pixel color based on total lights
    spread = 10  # spread over 15 degrees
    spread_l = h_theta - spread
    spread_r = h_theta + spread

    fill(strip, bg_color)  # default color

    start = int((spread_l * led_count) / 360)
    end = int((spread_r * led_count) / 360) + 1
    if (end < start):
        end += led_count

    h_fixed = h_theta % 360

    # print "Rho %s, Theta %s, Adjusted Theta %s, Photo %s, Brightness %s 0.5 %s 0.25 %s\n" % (rho, theta, h_theta, photo, brightness, max(int(brightness/2),1), max(int(brightness/4),1)),
    # sys.stdout.flush()

    for x in range(start, end):
        pos = x % led_count
        degrees = (float(pos * 360) / led_count)

        # fix wrapping degrees
        if (degrees > h_fixed + 180):
            degrees -= 360
        elif (degrees < h_fixed - 180):
            degrees += 360

        # if (degrees >= spread_l and degrees <= spread_r):
        # ramp brightness
        t = abs(h_fixed - degrees) / spread

        # update blend, it is given linear, but needs to be logarithmic(?)
        percent = easeIn(t)  # choose an ease function from above

        # print "pos {0} ( {1} - {2} ) / {3}, percent {4}\n".format(pos, h_fixed, degrees, spread, t),
        # sys.stdout.flush()

        strip.setPixelColor(pos, colorBlend(ball_color, bg_color, percent))
        # strip.setPixelColor(pos, ball_color)

    # increment time
    if transition < 1.0:
        time_end = timer()
        transition += time_end - time_start
        time_start = time_end
예제 #9
0
def update(theta, rho, photo, primary_color, secondary_color, balls, strip):
    global h_theta, h_r, h_easing, t_theta, t_r, t_easing, transition, time_start

    if time_start == 0:
        time_start = timer()
        transition = 0
        print "Start solid timer {0}\n".format(time_start),
        sys.stdout.flush()
        h_theta = theta
        t_theta = theta

    led_count = strip.numPixels()

    # color of non-pixels
    bg_color = secondary_color
    # color of comet by ball
    ball_color = secondary_color
    if transition >= 1.0 and transition < 2.0:
        ball_color = colorBlend(secondary_color, primary_color,
                                easeIn(transition - 1.0))
    else:
        ball_color = primary_color
    tail_color = colorBlend(ball_color, bg_color, easeIn(0.5))

    time_diff = timer() - time_start
    elapsed = 1.0 / 60.0  # assume correct timing
    # print "Time diff %s, Elapsed %s\n" % (time_diff, elapsed),
    # sys.stdout.flush()

    # ease h_theta into theta
    if (h_easing < 1.0):
        dh = (theta - h_theta) * h_easing  # target - current
        h_theta += dh * elapsed
    else:
        h_theta = theta

    # ease t_theta into theta
    dt = (h_theta - t_theta) * t_easing
    t_theta += dt * elapsed

    # fix flashing of ball trying to catch up to big theta
    h_diff = h_theta - theta
    if abs(h_diff) >= 180:
        h_theta = theta
    diff = h_theta - t_theta
    if abs(diff) > 360:  # reset tail if falling too far behind
        if h_theta > t_theta:
            t_theta = h_theta - 360
        else:
            t_theta = h_theta + 360

    # solid positions
    h_x = int((h_theta * led_count) / 360)
    t_x = int((t_theta * led_count) / 360)

    h_fixed = h_theta % 360
    t_fixed = t_theta % 360
    spread = diff

    # head positions
    h_spread = 360.0 / float(led_count) * h_r
    h_start = h_x - h_r
    h_end = h_x + h_r + 1

    # tail positions
    t_spread = 360.0 / float(led_count) * t_r
    t_start = t_x - t_r
    t_end = t_x + t_r + 1

    if transition < 1.0:
        for i in range(strip.numPixels() + 1):
            strip.setPixelColor(
                i,
                colorBlend(strip.getPixelColor(i), bg_color,
                           easeOut(transition)))
    else:
        fill(strip, bg_color)  # default color

    # fade light by tail
    t_diff = max(abs(t_x - t_r - h_end), abs(t_x + t_r - h_start))
    if t_diff > h_r:
        for x in range(t_start, t_end):
            pos = x % led_count
            degrees = (float(x * 360) / led_count)

            t = abs((t_theta - degrees) / t_spread)
            percent = easeIn(t)  # choose an ease function from above

            if transition >= 1.0:
                strip.setPixelColor(pos,
                                    colorBlend(tail_color, bg_color, percent))

    # fade light by ball
    for x in range(h_start, h_end):
        pos = x % led_count
        degrees = (float(x * 360) / led_count)

        t = abs((h_theta - degrees) / h_spread)
        percent = easeIn(t)  # choose an ease function from above

        if transition >= 1.0:
            strip.setPixelColor(pos, colorBlend(ball_color, bg_color, percent))

    # fade between ball-tail
    if spread != 0:
        start = h_x - 1
        end = t_x + 1
        if h_x > t_x:  # reverse order if head is greater
            start = t_x - 1
            end = h_x + 1
        for x in range(start, end):
            pos = x % led_count
            degrees = (float(x * 360) / led_count)

            t = abs((h_theta - degrees) / spread)
            if t <= 1.0 and t > 0:
                percent = t  # linear ease, I want this to be apparent

                if transition >= 1.0:
                    strip.setPixelColor(
                        pos, colorBlend(ball_color, tail_color, percent))

    # print "Theta %s, Head %s, Tail %s\n" % (theta, h_x, t_x),
    # sys.stdout.flush()

    # increment time
    time_end = timer()
    if transition < 2.0:
        transition += time_end - time_start
    time_start = time_end
예제 #10
0
def update(theta, rho, photo, primary_color, secondary_color, balls, strip):
    global transition, time_start, zero_color
    if time_start == 0:
        time_start = timer()
        transition = 0
        # print "Start solid timer {0}\n".format(time_start),
        sys.stdout.flush()

    if transition < 1.0:
        for i in range(strip.numPixels()+1):
            strip.setPixelColor(i, colorBlend(strip.getPixelColor(i),primary_color,easeOut(transition)))
    else:
        fill(strip, primary_color) # fill with color

        led_count = strip.numPixels()
        led_offset = int(float(led_count)/2.0)

        # color the side of the table that you should be standing on for proper tilt orientation
        strip.setPixelColor(led_offset, zero_color)
        strip.setPixelColor(led_offset+1, colorBlend(primary_color,zero_color,0.95))
        strip.setPixelColor(led_offset-1, colorBlend(primary_color,zero_color,0.95))
        strip.setPixelColor(led_offset+2, colorBlend(primary_color,zero_color,0.75))
        strip.setPixelColor(led_offset-2, colorBlend(primary_color,zero_color,0.75))
        strip.setPixelColor(led_offset+3, colorBlend(primary_color,zero_color,0.5))
        strip.setPixelColor(led_offset-3, colorBlend(primary_color,zero_color,0.5))
        strip.setPixelColor(led_offset+4, colorBlend(primary_color,zero_color,0.25))
        strip.setPixelColor(led_offset-4, colorBlend(primary_color,zero_color,0.25))
        strip.setPixelColor(led_offset+5, colorBlend(primary_color,zero_color,0.15))
        strip.setPixelColor(led_offset-5, colorBlend(primary_color,zero_color,0.15))
        strip.setPixelColor(led_offset+6, colorBlend(primary_color,zero_color,0.1))
        strip.setPixelColor(led_offset-6, colorBlend(primary_color,zero_color,0.1))

        # TODO: add blend for tilt pos?

    # increment time
    if transition < 1.0:
        time_end = timer()
        transition += time_end - time_start
        time_start = time_end