예제 #1
0
class Ground(DynamicSprite):

    NIGHT_COLOR = Pixel(0, 0, 0)
    DIRT_COLOR = Pixel(120, 72, 0)
    MEADOW_COLOR = Pixel(0, 92, 9)
    HILL_COLOR = Pixel(0, 123, 12)
    GRASS_COLOR = Pixel(1, 166, 17)

    def __init__(self, ground_color=None, brightness_variance=.05):
        self.ground_color = ground_color or Ground.DIRT_COLOR
        self.brightness_variance = brightness_variance

        super(Ground, self).__init__()

        self.ground_buffer = None

    def update_from(self, world, elapsed_time):
        super(Ground, self).update_from(world, elapsed_time)
        pixels = world.pixels_for_sprite(self)
        pixel_len = len(pixels)

        if self.ground_buffer is None or len(self.ground_buffer) != pixel_len:
            self.ground_buffer = [self.ground_color] * pixel_len

            for i in range(0, pixel_len):
                self.ground_buffer[i] = self.ground_color.copy()

                picker = randint(0, 10)
                if picker < 2:
                    self.ground_buffer[i] = l_shift_range(
                        self.ground_buffer[i], self.brightness_variance,
                        SHIFT_UP)
                elif picker > 7:
                    self.ground_buffer[i] = l_shift_range(
                        self.ground_buffer[i], self.brightness_variance,
                        SHIFT_DOWN)

    def _do_render(self, pixel_buffer):

        for i in range(0, len(pixel_buffer)):
            pixel_buffer[i].blend(self.ground_buffer[i])

        super(Ground, self)._do_render(pixel_buffer)
예제 #2
0
class LinearAgent1D(LocationAgent):

    DEFAULT_COLOR = Pixel(255, 255, 255)

    def __init__(self,
                 uuid,
                 api_url,
                 world,
                 default_color=None,

                 min_position=0.,
                 max_position=1.,
                 position_field="position_regression",

                 refresh_max_rate_ms=250,
                 stale_time_ms=5*1000,
                 trigger_time_ms=500,
                 state={}):
        super(LinearAgent1D, self).__init__( uuid,
                                             api_url,
                                             world,
                                             default_color=default_color,
                                             refresh_max_rate_ms=refresh_max_rate_ms,
                                             stale_time_ms=stale_time_ms,
                                             trigger_time_ms=trigger_time_ms,
                                             state=state )
        self.min_position = min_position
        self.max_position = max_position
        self.position_field = position_field

    def _get_beacon_location(self, beacon):
        pixel_position = None

        if "predict" in beacon and self.position_field in beacon["predict"]:
            real_position = float( beacon["predict"][self.position_field] )

            #we want to turn the "real" position into a floating value between 0 ... 1
            position_ratio = ( real_position - self.min_position) / ( self.max_position - self.min_position )
            position_ratio = max( 0., min(1., position_ratio) )

            #use the ratio against the world size to get where we are - make sure it is an integer
            pixel_position = int( position_ratio * self.world.size )

        return pixel_position

    def act_on_beacon(self, beacon):
        super(LocationAgent, self).act_on_beacon(beacon)

        splotch_color = self._get_beacon_color(beacon)
        location = self._get_beacon_location(beacon)

        splotch = self._add_splotch(splotch_color, position=location)

        return splotch
예제 #3
0
    def _get_beacon_color(self, beacon):
        if "metadata" in beacon and beacon["metadata"] and "color" in beacon[
                "metadata"]:
            color = beacon["metadata"]["color"]

            #we're going to toss some alpha on top if the color doesn't have any
            #  ... this just looks better faded a bit
            if len(color) == 6:
                color += "44"

            return Pixel.from_rgb_string(color)

        return None
예제 #4
0
    def __init__(self,
                 clouds=2,
                 cloud_color=None,
                 world_size=25,
                 cloud_min_radius=2,
                 cloud_max_radius=10):
        super(CloudCover, self).__init__()
        self.cloud_color = cloud_color or Pixel(237, 237, 237, 200)

        for i in range(clouds):
            self.add_sprite(
                Cloud.generate(color=self.cloud_color,
                               min_radius=cloud_min_radius,
                               max_radius=cloud_max_radius,
                               world_size=world_size))
예제 #5
0
    def generate_splotch(cls, world_size, color=None, position=None):
        COLORS = [[255, 0, 0], [0, 255, 0], [0, 0, 255]]

        color = color or Pixel.from_tuple(COLORS[randint(0, len(COLORS) - 1)])

        if position is None:
            position = randint(0, world_size)

        radius = randint(0, 2)
        splotch = SolidEdgeSplotch(color, position, radius)

        #dynamic activity
        splotch.add_dynamic(
            ExpandFade(maximum_radius=10,
                       expansion_rate_ms=200,
                       destroy_on_max=True))

        return splotch
예제 #6
0
class Sky(CloudCover):
    SKY_COLOR = Pixel(0, 0, 128)

    def __init__(self,
                 clouds=2,
                 sky_color=None,
                 cloud_color=None,
                 world_size=25):
        self.cloud_color = cloud_color or Cloud.CLOUD_COLOR
        self.sky_color = sky_color or Sky.SKY_COLOR

        super(Sky, self).__init__(clouds=clouds,
                                  cloud_color=cloud_color,
                                  world_size=world_size)

    def _do_render(self, pixel_buffer):

        #paint the sky first
        for i in range(0, len(pixel_buffer)):
            pixel_buffer[i].blend(self.sky_color)

        #paint the clouds second
        super(Sky, self)._do_render(pixel_buffer)
예제 #7
0
class Cloud(Splotch):
    CLOUD_COLOR = Pixel(100, 100, 100, 200)

    @classmethod
    def generate(cls,
                 color=None,
                 position=None,
                 min_radius=2,
                 max_radius=6,
                 min_movement=0.01,
                 max_movement=0.33,
                 world_size=25):

        #static shape
        color = color or Cloud.CLOUD_COLOR
        position = randint(0, world_size)
        radius = randint(min_radius, max_radius)
        cloud = cls(color, position, radius)

        #dynamic activity
        movement = uniform(min_movement, max_movement)
        cloud.add_dynamic(RightDrift(movement_chance=movement))

        return cloud
import utime
from random import randint
from display import Pixel, PixelPower

PixelPower(True)
View = Pixel()

RGB = (0, 0, 0)


def Draw(x, y):
    View.LoadXY(x, y, RGB)
    View.Show()
    utime.sleep_ms(1)


r, g, b, br = 1, 1, 1, 1

while True:
    RGB = (r * br, g * br, b * br)
    print('RGB:' + str(RGB))

    br = br + 5

    if br > 20:
        br = 1
        r, g, b = randint(0, 2), randint(0, 2), randint(0, 2)

    x, y = 2, 2

    r, u, l, d = 1, 1, 2, 2
예제 #9
0
파일: sequence.py 프로젝트: mackay/ruby
 def _process_arg_value(self, value):
     if str(value).startswith("Pixel|"):
         rgb = hex_to_RGB(value.split("|")[-1])
         return Pixel.from_tuple(rgb)
     return value
예제 #10
0
                        help='Run timing profiler')

    parser.add_argument('url', type=str, help="base api url in the form of http[s]://host:port/api")

    arg = parser.parse_args(sys.argv[1:])

    location_color_map = None
    if arg.map:
        location_color_map = { }
        map_tuple = [ ]
        for token in arg.map.split(","):
            map_tuple.append(token)

            if len(map_tuple) == 4:
                location_color_map[map_tuple[0]] = Pixel( int(map_tuple[1]),
                                                          int(map_tuple[2]),
                                                          int(map_tuple[3]) )
                map_tuple = [ ]

    enable_threading = True
    if arg.virtual:
        enable_threading = False

    world = World(arg.world, enable_threading=enable_threading)
    world.add_sprite( Ground(ground_color=Ground.NIGHT_COLOR, brightness_variance=0.0) )

    if arg.virtual:
        from display.renderers.virtual import PyGameRenderer
        world.add_renderer( PyGameRenderer() )
    if arg.led:
        from display.renderers.led import NeoPixelRenderer
예제 #11
0
    def get_color(cls):
        star_index = randint(0, len(cls.STAR_COLORS) - 1)
        color = cls.STAR_COLORS[star_index]

        return Pixel(color[0], color[1], color[2])
예제 #12
0
class LocationAgent(HTTPBeaconAgent):

    DEFAULT_COLOR = Pixel(255, 255, 255)

    STATE_SPRITE_COUNT = "sprite_count"

    def __init__(self,
                 uuid,
                 api_url,
                 world,
                 default_color=None,
                 location_color_map=None,
                 splotches_per_action=3,
                 refresh_max_rate_ms=250,
                 stale_time_ms=5 * 1000,
                 trigger_time_ms=500,
                 state={}):
        super(LocationAgent,
              self).__init__(uuid,
                             api_url,
                             refresh_max_rate_ms=refresh_max_rate_ms,
                             stale_time_ms=stale_time_ms,
                             trigger_time_ms=trigger_time_ms,
                             state=state)

        self.default_color = default_color or LocationAgent.DEFAULT_COLOR
        self.location_color_map = location_color_map or {}

        self.world = world
        self.splotches_per_action = splotches_per_action

    def _setup(self):
        self._set_state(LocationAgent.STATE_SPRITE_COUNT, 0)

    def _get_beacon_location(self, beacon):
        if "predict" in beacon and "location" in beacon["predict"]:
            return beacon["predict"]["location"]

        return None

    def _get_beacon_color(self, beacon):
        if "metadata" in beacon and beacon["metadata"] and "color" in beacon[
                "metadata"]:
            color = beacon["metadata"]["color"]

            #we're going to toss some alpha on top if the color doesn't have any
            #  ... this just looks better faded a bit
            if len(color) == 6:
                color += "44"

            return Pixel.from_rgb_string(color)

        return None

    def _add_splotch(self, color, position=None):
        splotch = ExpandingSplotches.generate_splotch(self.world.size,
                                                      color,
                                                      position=position)
        self.world.add_sprite(splotch)

        self._increment_sprite_count()

        return splotch

    def _add_point(self, position, color):
        point = Point(color=color, position=position)
        point.add_dynamic(Lifespan(life_ms=2500))

        self.world.add_sprite(point)
        self._increment_sprite_count()

        return point

    def _increment_sprite_count(self):
        sprite_count = self._get_state(LocationAgent.STATE_SPRITE_COUNT, 0)
        sprite_count += 1
        self._set_state(LocationAgent.STATE_SPRITE_COUNT, sprite_count)

    def act_on_beacon(self, beacon):
        super(LocationAgent, self).act_on_beacon(beacon)

        splotch_color = self.default_color
        beacon_color = self._get_beacon_color(beacon)
        location = self._get_beacon_location(beacon)

        if location and location in self.location_color_map:
            splotch_color = self.location_color_map[location]

        for i in range(0, self.splotches_per_action):
            splotch = self._add_splotch(splotch_color)

            if beacon_color:
                self._add_point(splotch.position, beacon_color)
예제 #13
0
from display import Pixel, PixelPower
PixelPower(True)
View = Pixel()

RGB = (10, 10, 10)
View.LoadXY(1, 1, RGB)
View.LoadPos(24, RGB)
View.Show()
예제 #14
0
 def __init__(self):
     self.View = Pixel()
     # Snake 1 Food 2 None 0 In Area
     self.Area = [0] * self.View.Sum
     self.Snake = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0]
     self.Area[0], self.Area[1] = 1, 0
예제 #15
0
        from display.renderers.led import NeoPixelRenderer
        scene.add_renderer(NeoPixelRenderer())

    for item in args.scene.split(","):
        target = item.split("_")[-1]
        layer_indicator = item.split("_")[0]

        pixel_count = OUTER_PIXELS
        layer = TwoLayerWorld.OUTER_TRACK
        if layer_indicator == "i":
            pixel_count = PIXELS - OUTER_PIXELS
            layer = TwoLayerWorld.INNER_TRACK

        if "single" == target:
            components = item.split("_")
            color = Pixel(int(components[1]), int(components[2]),
                          int(components[3]))

            # scene.add_sprite( SingleColor( color ), layer )
            scene.add_sprite(SequenceColor([color]), layer)

        if "ombre" in target:
            components = item.split("_")
            from_color = Pixel(int(components[1]), int(components[2]),
                               int(components[3]))

            to_color = Pixel(int(components[4]), int(components[5]),
                             int(components[6]))

            ombre_cls = OmbreColor
            if "ombre-oi" == target:
                ombre_cls = OuterInnterOmbre
예제 #16
0
    def get_color(cls):
        index = randint(0, len(cls.RAIN_COLORS) - 1)
        color = cls.RAIN_COLORS[index]

        return Pixel(color[0], color[1], color[2], 128)
예제 #17
0
import utime
from random import randint
from machine import I2C, Pin
from mpu9250 import MPU9250

i2c = I2C(scl=Pin(22), sda=Pin(21), freq=200000)
sensor = MPU9250(i2c)
print("MPU9250 id: " + hex(sensor.whoami))
from display import Pixel, PixelPower

PixelPower(True)
View = Pixel()
X, Y, Color, Flag = 2, 2, 2, 0
while True:
    # print('acceleration:', sensor.acceleration)
    # print('gyro:', sensor.gyro)
    # print('magnetic:', sensor.magnetic)
    A = sensor.acceleration  # -1 and -2 Software correction
    View.LoadXY(X, Y, (0, 0, 0), False)
    if (A[1] > -1 and A[1] > X and X < View.Max - 1):
        X = X + 1
    elif (A[1] < -1 and A[1] < X and X > View.Min):
        X = X - 1
    if (A[0] > -2 and A[0] > Y and Y > View.Min):
        Y = Y - 1
    elif (A[0] < -2 and A[0] < Y and Y < View.Max - 1):
        Y = Y + 1

    Color = Color + Flag
    if (Color == 10):
        Flag = -2