def move(self, angle=None):
        # Gravity
        if angle:
            xangle, yangle, zangle = angle
            self.xdist += self.xangle/90
            self.ydist += self.yangle/90

        # Move the point to a new position.  If it hits a wall, reverse the
        # direction of the ball.
        self.x, self.y = (self.x+self.xdist, self.y+self.ydist)
        if self.x >= led.width() or self.x < 0:
            self.xdist = - self.xdist
        if self.y >= led.height() or self.y < 0:
            self.ydist = - self.ydist
    def move(self, angle=None):
        # Gravity
        if angle:
            xangle, yangle, zangle = angle
            self.xdist += self.xangle / 90
            self.ydist += self.yangle / 90

        # Move the point to a new position.  If it hits a wall, reverse the
        # direction of the ball.
        self.x, self.y = (self.x + self.xdist, self.y + self.ydist)
        if self.x >= led.width() or self.x < 0:
            self.xdist = -self.xdist
        if self.y >= led.height() or self.y < 0:
            self.ydist = -self.ydist
Exemplo n.º 3
0
#
# Copyright (c) 2014, Scott Silver Labs, LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import time
from rstem import led

WIDTH=led.width()
HEIGHT=led.height()

for x in range(WIDTH):
    for y in range(HEIGHT):
        for w in range(WIDTH-x):
            for h in range(HEIGHT-y):
                led.erase()
                led.rect((x,y), (w,h))
                led.show()
                time.sleep(0.01);
Exemplo n.º 4
0
#
# Copyright (c) 2014, Scott Silver Labs, LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import time
from rstem import led

WIDTH = led.width()
HEIGHT = led.height()

for x in range(WIDTH):
    for y in range(HEIGHT):
        for w in range(WIDTH - x):
            for h in range(HEIGHT - y):
                led.erase()
                led.rect((x, y), (w, h))
                led.show()
                time.sleep(0.01)
sprite_period = 0.2
sprite_steps = sprite_period / period
step = 0
sprites = cycle([LEDSprite("ball%d.txt" % i) for i in range(4)])
sprite = sprites.next()
while True:
    # Draw the ball
    led.erase()
    led.sprite(sprite, (int(x), int(y)))
    led.show()

    # Change to next sprite, once every sprite_steps
    step += 1
    if step % sprite_steps == 0:
        sprite = sprites.next()

    # Gravity
    xangle, yangle, zangle = accel.get_angle()
    xdist += xangle / 90
    ydist += yangle / 90

    # Move the point to a new position.  If it hits a wall, reverse the
    # direction of the ball.
    x, y = (x + xdist, y + ydist)
    if x >= (led.width() - (sprite.width() - 1)) or x < 0:
        xdist = -xdist * 0.99
    if y >= (led.height() - (sprite.height() - 1)) or y < 0:
        ydist = -ydist * 0.99

    time.sleep(period)
Exemplo n.º 6
0
#
# Create a marquee sign - a string of dots that rotates around the border of
# the LED matrices.
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License version 2 as published by the
# Free Software Foundation.  See the file COPYING included with this software
# for the full license.
#
import time
from rstem import led

# Create a list of points, that are all the points of the marquee border, in
# order.
max_width = led.width() - 1
max_height = led.height() - 1
top = [(x, max_height) for x in range(max_width)]
right = [(max_width, max_height-y) for y in range(max_height)]
bottom = [(max_width-x, 0) for x in range(max_width)]
left = [(0, y) for y in range(max_height)]
marquee = top + right + bottom +  left
percent_on = 30

while True:
    # For each point in the marquee, up to the defined percent_on, draw the
    # point
    led.erase()
    for i, point in enumerate(marquee):
        if i % len(marquee) < (percent_on/100.0) * len(marquee):
            led.point(point)
    led.show()
# Copyright (c) 2014, Scott Silver Labs, LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import time
from rstem import led
from rstem import accel

xbase, ybase =  accel.get_data()
x, y = (led.width()/2, led.height()/2)
while True:
    xaccel, yaccel =  accel.get_data()
    xchg = (xaccel - xbase)/20.0
    ychg = (yaccel - ybase)/20.0
    x, y = led.bound(int(x + xchg), int(y + ychg))

    led.erase()
    led.point(x, y)
    led.show()
    time.sleep(0.1);
x = 0.0
y = 0.0
xdist = 0.1
ydist = 0.5
period = 0.01
sprite_period = 0.2
sprite_steps = sprite_period / period
step = 0
sprites = [LEDSprite("ball%d.txt" % i) for i in range(4)]
while True:
    # Draw the ball
    sprite = sprites[n]
    led.erase()
    led.sprite(sprite, (int(x), int(y)))
    led.show()

    # Change to next sprite, once every sprite_steps
    step += 1
    if step % sprite_steps == 0:
        n = (n + 1) % len(sprites)

    # Move the point to a new position.  If it hits a wall, reverse the
    # direction of the ball.
    x, y = (x + xdist, y + ydist)
    if x >= (led.width() - (sprite.width() - 1)) or x < 0:
        xdist = -xdist
    if y >= (led.height() - (sprite.height() - 1)) or y < 0:
        ydist = -ydist

    time.sleep(period)