コード例 #1
0
    def do_swirl(self, this_program):
        def swirl(x, y, step):
            x -= (scrollphathd.DISPLAY_WIDTH / 2.0)
            y -= (scrollphathd.DISPLAY_HEIGHT / 2.0)

            dist = math.sqrt(pow(x, 2) + pow(y, 2))

            angle = (step / 10.0) + dist / 1.5

            s = math.sin(angle)
            c = math.cos(angle)

            xs = x * c - y * s
            ys = x * s + y * c

            r = abs(xs + ys)
            return max(0.0, 0.7 - min(1.0, r / 8.0))

        while self.program == this_program and not self._got_stop_event():
            timestep = math.sin(time.time() / 18) * 1500

            for x in range(0, WIDTH):
                for y in range(0, HEIGHT):
                    v = swirl(x, y, timestep)
                    scrollphathd.pixel(x, y, v)

            scrollphathd.show()
            time.sleep(0.001)
コード例 #2
0
ファイル: roll.py プロジェクト: mwilde345/scroll-phat-hd
def roll():
    for data in ROLL:
        for x in range(0, scrollphathd.DISPLAY_WIDTH):
            for y in range(0, scrollphathd.DISPLAY_HEIGHT):
                brightness = data[x][y]
                scrollphathd.pixel(x, y, brightness * IMAGE_BRIGHTNESS)
        scrollphathd.show()
        time.sleep(0.01)
コード例 #3
0
def warning():
    speed_factor = 10
    scale = (math.sin(time.time() * speed_factor) + 1) / 2
    offset = 0
    for x in range(scrollphathd.width):
        for y in range(scrollphathd.height):
            offset += 1
            color = 0.85 * scale * (offset % 2)
            scrollphathd.pixel(x, y, color)
    scrollphathd.show()
コード例 #4
0
    def demo(self):
        self.index += 2
        s = math.sin(self.index / 50.0) * 2.0 + 6.0

        for x in range(0, 17):
            for y in range(0, 7):
                v = 0.3 + (0.3 * math.sin((x * s) + self.index / 4.0) *
                           math.cos((y * s) + self.index / 4.0))

                scrollphathd.pixel(x, y, v)
コード例 #5
0
def look_down(num):
  if(num==1):
    for x in range(0, scrollphathd.DISPLAY_WIDTH):
      for y in range(0, scrollphathd.DISPLAY_HEIGHT):
          brightness = CAR_1[x][y]
          scrollphathd.pixel(x, y, brightness * IMAGE_BRIGHTNESS)
  else:
    for x in range(0, scrollphathd.DISPLAY_WIDTH):
      for y in range(0, scrollphathd.DISPLAY_HEIGHT):
          brightness = CAR_2[x][y]
          scrollphathd.pixel(x, y, brightness * IMAGE_BRIGHTNESS)
コード例 #6
0
 def explode(self):
     for r in range(int(self.WIDTH * 1.25)):
         for s in range(r):
             c = 1 + int(math.pi * 2 * r)
             for a in range(c):
                 o = 2 * math.pi / c * a
                 x = int(math.sin(o) * s + self.WIDTH - 1)
                 y = int(math.cos(o) * s + self._hpos)
                 v = s / r * (0.2 + 0.8 * random())
                 if 0 <= x < self.WIDTH and 0 <= y <= self.HEIGHT:
                     scrollphathd.pixel(x, y, v)
         scrollphathd.show()
         time.sleep(0.01)
コード例 #7
0
    def do_plasma(self, this_program):
        i = 0

        while self.program == this_program and not self._got_stop_event():
            i += 2
            s = math.sin(i / 50.0) * 2.0 + 6.0

            for x in range(0, 17):
                for y in range(0, 7):
                    v = 0.3 + (0.3 * math.sin((x * s) + i / 4.0) *
                               math.cos((y * s) + i / 4.0))
                    scrollphathd.pixel(x, y, v)

            scrollphathd.show()
            time.sleep(0.01)
コード例 #8
0
    def render(self, instant=True):

        led_strip_buf = np.zeros((512, 3))
        for led_id in self.leds:
            led = self.leds[led_id]
            if led["type"] == "strip":
                led_strip_buf[led["hardware_id"]] = led["colour"]
            elif led["type"] == "mat":
                y, x = led["hardware_id"]
                y = 8 - y
                v = (max(led["colour"]) / 255.0) * self._eye_brightness
                scrollphathd.pixel(x, y, v)

        self.client.put_pixels(led_strip_buf * self._brightness)
        scrollphathd.show()
コード例 #9
0
def blink():
    for data in BLINK:
        for x in range(0, scrollphathd.DISPLAY_WIDTH):
            for y in range(0, scrollphathd.DISPLAY_HEIGHT):
                brightness = data[x][y]
                scrollphathd.pixel(x, y, brightness * IMAGE_BRIGHTNESS)
        scrollphathd.show()
        time.sleep(0.001)
    time.sleep(.002)
    for data in BLINK_REVERSE:
        for x in range(0, scrollphathd.DISPLAY_WIDTH):
            for y in range(0, scrollphathd.DISPLAY_HEIGHT):
                brightness = data[x][y]
                scrollphathd.pixel(x, y, brightness * IMAGE_BRIGHTNESS)
        scrollphathd.show()
        time.sleep(0.005)
コード例 #10
0
ファイル: amazon.py プロジェクト: mwilde345/scroll-phat-hd
def amazon():
  for z in range(8):
    for x in range(0, scrollphathd.DISPLAY_WIDTH):
      for y in range(0, scrollphathd.DISPLAY_HEIGHT):
          brightness = AMZN[x][y]
          scrollphathd.pixel(x, y, brightness * IMAGE_BRIGHTNESS)
    scrollphathd.show()
    time.sleep(.5)
    for x in range(0, scrollphathd.DISPLAY_WIDTH):
      for y in range(0, scrollphathd.DISPLAY_HEIGHT):
          brightness = AMZN_NEG[x][y]
          scrollphathd.pixel(x, y, brightness * IMAGE_BRIGHTNESS)
    scrollphathd.show()
    time.sleep(.5)
  scrollphathd.clear()
  scrollphathd.show()
コード例 #11
0
    def start():
        i = 0

        while not self.stop:
            i += 2
            s = math.sin(i / 50.0) * 2.0 + 6.0

            for x in range(0, 17):
                for y in range(0, 7):
                    v = 0.3 + (0.3 * math.sin((x * s) + i / 4.0) *
                               math.cos((y * s) + i / 4.0))

                    scrollphathd.pixel(x, y, v)

            time.sleep(0.01)
            scrollphathd.show()
コード例 #12
0
ファイル: look_down.py プロジェクト: mwilde345/scroll-phat-hd
def look_down():
    for data in LOOK_DOWN:
        for x in range(0, scrollphathd.DISPLAY_WIDTH):
            for y in range(0, scrollphathd.DISPLAY_HEIGHT):
                brightness = data[x][y]
                scrollphathd.pixel(x, y, brightness * IMAGE_BRIGHTNESS)
        scrollphathd.show()
        time.sleep(0.01)
    time.sleep(2)
    for data in LOOK_DOWN_REVERSE:
        for x in range(0, scrollphathd.DISPLAY_WIDTH):
            for y in range(0, scrollphathd.DISPLAY_HEIGHT):
                brightness = data[x][y]
                scrollphathd.pixel(x, y, brightness * IMAGE_BRIGHTNESS)
        scrollphathd.show()
        time.sleep(0.01)
コード例 #13
0
    def do_cells(self, this_program):
        rules = [22, 30, 54, 60, 75, 90, 110, 150]
        rule = rules[0]
        maxSteps = 100
        loopCount = 0
        matrix = numpy.zeros((HEIGHT, WIDTH), dtype=numpy.int)
        firstRow = [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0]
        matrix[0] = firstRow
        row = 0
        speed = 10

        while self.program == this_program and not self._got_stop_event():
            for y in range(0, HEIGHT):
                for x in range(0, WIDTH):
                    scrollphathd.pixel(x, y, matrix[y, x])

            scrollphathd.show()
            loopCount += 1

            if loopCount > maxSteps:
                loopCount = 0
                row = 0
                matrix = numpy.zeros((HEIGHT, WIDTH), dtype=numpy.int)
                matrix[0] = firstRow
                rules = numpy.roll(rules, -1, axis=0)
                rule = rules[0]

            inputRow = matrix[row]
            outputRow = numpy.zeros((WIDTH), dtype=numpy.int)

            for x in range(0, WIDTH):
                a = inputRow[x - 1] if x > 0 else inputRow[WIDTH - 1]
                b = inputRow[x]
                c = inputRow[x + 1] if x < WIDTH - 1 else inputRow[0]

                o = 1 << ((a << 2) + (b << 1) + c)

                outputRow[x] = 1 if o & rule else 0

            if row < HEIGHT - 1:
                row = row + 1
            else:
                matrix = numpy.roll(matrix, -1, axis=0)
            matrix[row] = outputRow

            time.sleep(0.01 * speed)
コード例 #14
0
ファイル: phat.py プロジェクト: yagizyalcintas/scrollphat
def send_image():
    if request.method == 'POST':
        try:
            print("headers")
            print(request.headers)
            print("data")
            print(request.data)
            print("headers")
            print(request.files)

            # uploaded_file = request.files['image']
            def get_pixel(x, y):
                p = img.getpixel((x, y))
                if img.getpalette() is not None:
                    r, g, b = img.getpalette()[p:p + 3]
                    p = max(r, g, b)
                return p / 255.0

            for x in request.files:
                print(x)
                uploaded_file = request.files[x]
                uploaded_file.save(x)
                print(uploaded_file.filename)
                img = Image.open(uploaded_file.filename)
                try:
                    for x in range(0, 17):
                        for y in range(0, 7):
                            brightness = get_pixel(x, y)
                            scrollphathd.pixel(x, 6 - y, brightness * 0.5)
                    scrollphathd.flip(x=True, y=False)
                    scrollphathd.show()

                except Exception as e:
                    print(e)
                    scrollphathd.clear()
                    scrollphathd.show()
            return "", 204
        except Exception as e:
            print(e)
            abort(501)
コード例 #15
0
def Robot_Mouth():
    for x in range(0, scrollphathd.DISPLAY_WIDTH):
        for y in range(0, scrollphathd.DISPLAY_HEIGHT):
            brightness = get_pixel(x, y)
            scrollphathd.pixel(x, 6 - y, brightness * IMAGE_BRIGHTNESS)

    start_time = time.time()
    last_weather_time = start_time
    last_tweet_time = start_time
    last_clock_time = start_time

    while Show_Mouth:
        scrollphathd.show()
        time.sleep(0.5)
        scrollphathd.scroll(-1)

        if time.time() - last_clock_time > (30):
            scrollphathd.clear()
            scrollphathd.show()
            clock()
            last_clock_time = time.time()
            for x in range(0, scrollphathd.DISPLAY_WIDTH):
                for y in range(0, scrollphathd.DISPLAY_HEIGHT):
                    brightness = get_pixel(x, y)
                    scrollphathd.pixel(x, 6 - y, brightness * IMAGE_BRIGHTNESS)

        if time.time() - last_weather_time > (30 * 60):
            scrollphathd.clear()
            scrollphathd.show()
            if Check_Internet():
                print_weather()
            last_weather_time = time.time()
            for x in range(0, scrollphathd.DISPLAY_WIDTH):
                for y in range(0, scrollphathd.DISPLAY_HEIGHT):
                    brightness = get_pixel(x, y)
                    scrollphathd.pixel(x, 6 - y, brightness * IMAGE_BRIGHTNESS)

        if time.time() - last_tweet_time > (5 * 60):
            scrollphathd.clear()
            scrollphathd.show()
            if Check_Internet():
                print_hashtag()
            last_tweet_time = time.time()
            for x in range(0, scrollphathd.DISPLAY_WIDTH):
                for y in range(0, scrollphathd.DISPLAY_HEIGHT):
                    brightness = get_pixel(x, y)
                    scrollphathd.pixel(x, 6 - y, brightness * IMAGE_BRIGHTNESS)

    scrollphathd.clear()
    scrollphathd.show()
コード例 #16
0
ファイル: phat.py プロジェクト: yagizyalcintas/scrollphat
def pulse():
    scrollphathd.clear()
    scrollphathd.show()
    dur = 10
    count = 0
    img = Image.open("mouth.bmp")
    img.show()
    scrollphathd.clear()
    scrollphathd.show()

    def get_pixel(x, y):
        p = img.getpixel((x, y))

        if img.getpalette() is not None:
            r, g, b = img.getpalette()[p:p + 3]
            p = max(r, g, b)

        return p / 255.0

    try:
        for x in range(0, scrollphathd.DISPLAY_WIDTH):
            for y in range(0, scrollphathd.DISPLAY_HEIGHT):
                brightness = get_pixel(x, y)
                scrollphathd.pixel(x, 6 - y, brightness * IMAGE_BRIGHTNESS)

        while count < dur * 10:
            scrollphathd.show()
            scrollphathd.scroll(1)
            time.sleep(0.05)
            count = count + 1
        scrollphathd.clear()
        scrollphathd.show()
        return "", 204

    except KeyboardInterrupt:
        scrollphathd.clear()
        scrollphathd.show()
コード例 #17
0
def mainloop():

    # set up the scrollPhat
    scrollphathd.clear()
    # Uncomment the below if your display is upside down
    #   (e.g. if you're using it in a Pimoroni Scroll Bot)
    #scrollphathd.rotate(degrees=180)
    scrollphathd.set_brightness(0.1)

    # define a list of some interesting rule numbers to loop through
    rules = [22, 30, 54, 60, 75, 90, 110, 150]
    rule = rules[0]

    # how many evolve steps to perform before starting the next CA rule
    maxSteps = 100
    loopCount = 0

    # define the matrix of cells and rows that we will be displaying
    matrix = numpy.zeros((7, 17), dtype=numpy.int)

    # set the initial condition of the first row
    # "dot" = single cell at position (0,8); top row, middle LED
    firstRow = [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0]
    matrix[0] = firstRow

    # We need to keep track of which row we are working on
    # the CA fills in from the top row and evolves downwards.
    # When we have filled the last row we'll scroll all the
    # rows up and just evolve the bottom row from then on.
    row = 0

    speed = 10

    while True:

        # redraw first so that it shows the initial contitions when first run
        for y in range(0, 7):
            for x in range(0, 17):
                scrollphathd.pixel(x, y, matrix[y, x])

        scrollphathd.show()

        loopCount += 1

        # if we have performed maxSteps...
        if loopCount > maxSteps:
            # reset a bunch of stuff
            loopCount = 0
            row = 0
            matrix = numpy.zeros((7, 17), dtype=numpy.int)
            matrix[0] = firstRow
            # get a new rule
            rules = numpy.roll(rules, -1, axis=0)
            rule = rules[0]

        # use the current row as the input for the next row
        inputRow = matrix[row]

        # make an empty array to fill with values
        outputRow = numpy.zeros((17), dtype=numpy.int)

        #  the secret sauce...
        #  step through each cell in the output row, calculate its value
        #  from the state of the input cell above and its left and right neighbour

        for x in range(0, 17):

            #  for each output cell, get the values of the input cell
            #  and its left and right neighbours.

            #  because cell 0 has no left neighbour we will
            #  get that value from the last cell in the row.
            #  similarly, the last cell in the row has no right neighbour
            #  so we will use the value of cell 0, effectively wrapping
            #  the horizontal edges of the display

            a = inputRow[x - 1] if x > 0 else inputRow[16]
            b = inputRow[x]
            c = inputRow[x + 1] if x < 16 else inputRow[0]

            #  a, b and c now contain the states of the three input cells
            #  that determine the state of our output cell

            #  there are 8 possible combinations for a,b,c
            #  they are:

            #  abc   abc   abc   abc   abc   abc   abc   abc
            #  111   110   101   100   011   010   001   000

            #  an abc combination will prodcude an output of either
            #  1 or 0 depending on the rule we are using

            #  for example, if we are running rule 30:
            #  the binary representation of 30 is 11110.
            #  we have to left-pad that out a bit so that we also have
            #  8 digits : "00011110"

            #  the rule can then be mapped onto our abc combinations like so:

            #  inputs   111   110   101   100   011   010   001   000
            #  outputs   0     0     0     1     1     1     1     0

            #  if we find an abc of a=1, b=0, c=0 we would match
            #  with "100" and output a 1

            #  if we were using rule number 110 we would get this mapping

            #  inputs   111   110   101   100   011   010   001   000
            #  outputs   0     1     1     0     1     1     0     0

            #  because the padded binary representation of the number 110 is
            #  "01101100" we get no match for "100"

            #  ok, so lets consider the first evolution of rule 30 starting
            #  with a single dot in the center of the first row.
            #  (using a row of seven cells, 17 is too many to type!)

            #  given row 0 =>   0001000

            #  our first abc is "000", 00]0100[0  (remember that we are wrapping)
            #  > this maps to 0

            #  our next abc is "000", [000]1000
            #  > this maps to 0

            #  our next abc is "001", 0[001]000
            #  > this maps to 1 yay!

            #  our next abc is "010", 00[010]00
            #  > this maps to 1

            #  our next abc is "100", 000[100]0
            #  > this maps to 1

            #  our next abc is "000", 0001[000]
            #  > this maps to 0

            #  our next abc is "000", 0]0010[00
            #  > this maps to 0

            #  we now have seven new cells and our our output row will be
            #  > "0011100"

            #  and our cumulative rows will be :
            #  row 0 > 0001000
            #  row 1 > 0011100

            #  after the next step, our cumulative output will be :
            #  row 0 > 0001000
            #  row 1 > 0011100
            #  row 2 > 0110010

            #  so that's nice, but we need a general way to do this for any rule
            #  ...

            #  to convert our input values (abc) into output values for any
            #  rule we will first notice that the input combinations "111",
            #  "110" etc are themselves binary representations of the numbers
            #  7,6,5,4,3,2,1,0 and that they are in index order if we read
            #  right to left.

            #  we can turn our abc result into a number and this will give
            #  the index position of our abc combination using our right to left order.

            #  for example, the abc pattern "011" is binary for 3
            #  ...  int("011", 2) === 3
            #  so we put a 1 in index position 3 (counting from 0, starting from the right)
            #  ... "00001000"
            #  and see if it matches against our binary rule 30

            #  0 0 0 0 1 0 0 0
            #  0 0 0 1 1 1 1 0
            #          ^
            #          ^
            #      a match!

            #  this is equivelant to the bitwise AND operation:
            #  3&30

            #  see here :
            #  https://wiki.python.org/moin/BitwiseOperators
            #  x & y Does a "bitwise and". Each bit of the output is 1 if the
            #  corresponding bit of x AND of y is 1, otherwise it's 0.

            #  so, after all that we now know the state of this output cell.
            #  fortunately the algorithm is a lot shorter than the explaination ;)

            #  construct our abc by bitshift and move a 1 to that index.
            o = 1 << ((a << 2) + (b << 1) + c)

            #  set the output cell to 1 if it &s with the rule, othewise 0
            outputRow[x] = 1 if o & rule else 0

        # incrementally fill in the rows until we fill the last row
        # then roll up the display matrix and evolve the last row
        if row < 6:
            row = row + 1
        else:
            matrix = numpy.roll(matrix, -1, axis=0)

        # set the matrix new row for the next redraw
        matrix[row] = outputRow

        # have a nap
        time.sleep(0.01 * speed)
コード例 #18
0
#!/usr/bin/env python
#displays a dot which bounce off the edges of the scroll phat

import time

import scrollphathd

scrollphathd.pixel(0, 0, 0.5)

try:
    while True:
        scrollphathd.scroll(1, 1)
        scrollphathd.show()
        time.sleep(0.1)
except KeyboardInterrupt:
    scrollphathd.fill(0)
    scrollphathd.show()
コード例 #19
0
	list.append(s.splitlines())

# Function that returns the brightness value nnn as a float, from the array at position i,j, for frame "step" 
def candle(i , j, step):
    r = float(list[step][i][j*3:j*3+3])
    return r

# Set maximal brightness of LED Matrix
scrollphathd.set_brightness(0.5)

# Start rendering loop
timestep = 0
while True:
    if timestep == 332: # the file has 333 frames
      timestep = 0
 
    timestep = timestep + 1
	
    # Render each pixel column by column based on array contents
    for x in range(0, scrollphathd.DISPLAY_WIDTH):
        for y in range(0, scrollphathd.DISPLAY_HEIGHT):
            v = candle(x, y, timestep)
            scrollphathd.pixel(x, y, max(0,v/255))

    # Wait a little before the next frame		
    time.sleep(0.001)
	
    # Show the frame buffer	
    scrollphathd.show()

コード例 #20
0
ファイル: scroll_hat_mini.py プロジェクト: iamsrp/dexter
    def _updater(self):
        """
        The method which will maintain the display.
        """
        # Some state variables
        i_mult = 0.0
        s_mult = 0.0
        o_mult = 0.0
        i_dir = 0.0
        s_dir = 0.0
        o_dir = 0.0

        # And off we go!
        LOG.info("Started update thread")
        while self.is_running:
            # Don't busy-wait
            time.sleep(0.01)

            # What time is love?
            now = time.time()

            # How long since these components went non-idle
            i_since = now - self._input_time
            s_since = now - self._service_time
            o_since = now - self._output_time

            # See what state we want these guys to be in. After 30s we figure
            # that the component is hung and turn it off.
            i_state = 1.0 if i_since < 30.0 else 0.0
            s_state = 1.0 if s_since < 30.0 else 0.0
            o_state = 1.0 if o_since < 30.0 else 0.0

            # Slide the multiplier and direction accordingly
            f = 0.2
            i_mult = (1.0 - f) * i_mult + f * i_state
            s_mult = (1.0 - f) * s_mult + f * s_state
            o_mult = (1.0 - f) * o_mult + f * o_state
            f = 0.01
            i_dir = (1.0 - f) * i_dir + f * self._input_dir
            s_dir = (1.0 - f) * s_dir + f * self._service_dir
            o_dir = (1.0 - f) * o_dir + f * self._output_dir

            # And actually update the display
            for y in range(self._size):
                for x in range(self._size):
                    # The pixel brightnesses, according to the pattern
                    i_v = self._pixel_value(x, y, i_since, i_dir)
                    s_v = self._pixel_value(x, y, s_since, s_dir)
                    o_v = self._pixel_value(x, y, o_since, o_dir)

                    i_x = self._input_off_x + x
                    i_y = self._input_off_y + y
                    s_x = self._service_off_x + x
                    s_y = self._service_off_y + y
                    o_x = self._output_off_x + x
                    o_y = self._output_off_y + y

                    # And set them
                    scrollphathd.pixel(i_x, i_y, i_v * i_mult)
                    scrollphathd.pixel(s_x, s_y, s_v * s_mult)
                    scrollphathd.pixel(o_x, o_y, o_v * o_mult)

            scrollphathd.show()

        # And we're done
        scrollphathd.clear()
        LOG.info("Stopped update thread")
コード例 #21
0
#!/usr/bin/env python
#indicates a dotted pattern
import time
import math

import scrollphathd

speed_factor = 10

try:
    while True:
        scale = (math.sin(time.time() * speed_factor) + 1) / 2
        offset = 0
        for x in range(scrollphathd.width):
            for y in range(scrollphathd.height):
                offset += 1
                color = 0.25 * scale * (offset % 2)
                scrollphathd.pixel(x, y, color)

        scrollphathd.show()

except KeyboardInterrupt:
    scrollphathd.fill(0)
コード例 #22
0
    def run(self):
        """
        The main running loop.
        """

        # State variables
        self.init()
        last = time.time()
        start = last

        # Set things to the starting values

        # Loop forever now
        while True:
            now = time.time()
            since = now - last

            # Move the things down
            if since > self._wait:
                self.step()
                last = now
                self._wait = max(0.0, self._wait - self.WAIT_DIFF)

            # Make it easier or harder
            if self._button_A.is_active:
                self._frac_new = max(self.MIN_FRAC,
                                     self._frac_new - self.FRAC_STEP)
            if self._button_B.is_active:
                self._frac_new = min(self.MAX_FRAC,
                                     self._frac_new + self.FRAC_STEP)

            # Move the player
            if self._button_X.is_active and self._hpos > 0:
                self._hpos -= 1
            if self._button_Y.is_active and self._hpos < self.HEIGHT - 1:
                self._hpos += 1

            # Draw the field
            for (y, row) in enumerate(self._arena):
                for (x, e) in enumerate(row):
                    v = 0.5 if e else 0.0
                    scrollphathd.pixel(x, y, v)

            # Draw the player
            scrollphathd.pixel(self._wpos, self._hpos, 1.0)

            # And display it all
            scrollphathd.show()

            # Collision?
            if self._arena[self._hpos][self._wpos]:
                # Print stats
                print("You survived for %0.1f seconds" % (now - start))
                print()

                # Draw the explosion
                self.explode()

                # And reset things
                self.init()
                start = now
                last = now

            # Wait for  bit befor emoving on
            time.sleep(0.05)
コード例 #23
0
    #print(latest)

    scrollphathd.clear()

    if latest - last > 5:
        # show startup logo
        scrollphathd.clear()
        scrollphathd.fill(0, 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT + 14)
        image_path = os.path.join(os.path.dirname(__file__), IMAGE_FILE2)
        image = Image.open(image_path)
        pixels = image.load()

        for x in range(IMAGE_WIDTH):
            for y in range(IMAGE_HEIGHT):
                r, g, b = pixels[x, y]
                scrollphathd.pixel(x, y + 7, (r / 255) * BRIGHTNESS)

        scrollphathd.write_string('%s ' % int(latest), 1, IMAGE_HEIGHT + 8,
                                  font5x5_numbers, 1, BRIGHTNESS)
        scrollphathd.scroll_to(0, 0)

        for i in range(IMAGE_HEIGHT + 8):
            scrollphathd.show()
            scrollphathd.scroll(0, 1)
            time.sleep(0.05)

    else:
        scrollphathd.fill(0, 0, 0, 50, 14)  # a nice big canvas to work with

        if latest > last:
            scrollphathd.scroll_to(0, 0)
コード例 #24
0
def neutral():
    for x in range(0, scrollphathd.DISPLAY_WIDTH):
        for y in range(0, scrollphathd.DISPLAY_HEIGHT):
            brightness = NEUTRAL[x][y]
            scrollphathd.pixel(x, y, brightness * IMAGE_BRIGHTNESS)
    scrollphathd.show()
コード例 #25
0
        time.sleep(0.1)
        if i > 108: break  #大体このぐらいのカウントで一週
    scrollphathd.clear()

    # プラズマ表示(サンプルより)
    i = 0
    while True:
        i += 2
        s = math.sin(i / 50.0) * 2.0 + 6.0

        for x in range(0, 17):
            for y in range(0, 7):
                v = 0.3 + (0.3 * math.sin((x * s) + i / 4.0) *
                           math.cos((y * s) + i / 4.0))

                scrollphathd.pixel(x, y, v)

        time.sleep(0.01)
        scrollphathd.show()
        if i > 620: break  # これもこのぐらいでブレイク

    # ガンマ(明るさ)の変更ループ
    DELAY = 0.0001
    i = 0
    while True:
        i = i + 1
        for x in range(255):
            scrollphathd.fill(x / 255.0, 0, 0, 17, 7)
            scrollphathd.show()
            time.sleep(DELAY)
        for x in reversed(range(255)):
コード例 #26
0
ファイル: robot-mouth.py プロジェクト: imedgar/bot-assistant
IMAGE_BRIGHTNESS = 0.5

img = Image.open("mouth.bmp")


def get_pixel(x, y):
    p = img.getpixel((x, y))

    if img.getpalette() is not None:
        r, g, b = img.getpalette()[p:p + 3]
        p = max(r, g, b)

    return p / 255.0


try:
    for x in range(0, scrollphathd.DISPLAY_WIDTH):
        for y in range(0, scrollphathd.DISPLAY_HEIGHT):
            brightness = get_pixel(x, y)
            scrollphathd.pixel(x, 6 - y, brightness * IMAGE_BRIGHTNESS)

    while True:
        scrollphathd.show()
        time.sleep(0.03)
        scrollphathd.scroll(-1)

except KeyboardInterrupt:
    scrollphathd.clear()
    scrollphathd.show()