Exemplo n.º 1
0
class Config:
    board_size = BOARD_SIZE
    board_colour = Colour(WHITE)
    vehicles = VEHICLE_SETS
    width = WIDTH
    height = HEIGHT
    escape_car_colour = Colour(RED)
Exemplo n.º 2
0
    def pattern(self):

        bottle_states = []
        for r in range(NUM_NODES + 1):
            bottle_states.append(r % 2 == 0)

        stop = False
        while not stop:
            hue = random()
            c1 = hue_to_color(hue)
            c1 = Colour(rgb=(c1[0] / 255.0, c1[1] / 255.0, c1[2] / 255.0))
            c2 = hue_to_color(hue + .5)
            c2 = Colour(rgb=(c2[0] / 255.0, c2[1] / 255.0, c2[2] / 255.0))

            gradient = []
            for c in c1.range_to(c2, 181):
                gradient.append(
                    (int(c.red * 255), int(c.green * 255), int(c.blue * 255)))

            for angle in range(181, 0, -1):
                for bottle, bottle_angle in self.geo.get_near_bottles(
                        angle, 1):
                    if bottle_angle < angle:
                        if bottle_states[bottle]:
                            self.trap.set_color(bottle,
                                                gradient[int(bottle_angle)])
                        else:
                            self.trap.set_color(
                                bottle, gradient[int(180 - bottle_angle)])
                        bottle_states[bottle] = not bottle_states[bottle]
                        sleep(.03)

            if self.stop_thread:
                stop = True
                break
Exemplo n.º 3
0
 def __init__(self):
     self.coloursDict = {
         1: Colour(135, 206, 235, convertToDecimal=True),
         2: Colour(82, 105, 53, convertToDecimal=True),
         3: Colour(146, 108, 77, convertToDecimal=True),
         4: Colour(169, 163, 163, convertToDecimal=True),
         5: Colour(135, 206, 235, convertToDecimal=True),
     }
Exemplo n.º 4
0
def get_vehicle_from_config(vehicle_type, x, y, orientation, rgb,
                            escape_car_colour):
    if vehicle_type == 'car':
        vehicle = Car(Position(x, y), orientation, Colour(rgb))
    elif vehicle_type == 'lorry':
        vehicle = Lorry(Position(x, y), orientation, Colour(rgb))
    else:
        raise Exception('Unknown vehicle_type! {}'.format(vehicle_type))

    if vehicle.colour == escape_car_colour:
        vehicle.is_escape_vehicle = True
    return vehicle
Exemplo n.º 5
0
def __get_ranged_color(critical, current, high, temp_color):
    if current >= critical:
        return temp_color['critical']
    elif current >= high:
        return temp_color['high']
    else:
        start_color = Colour('#' + temp_color['start'])
        end_color = Colour('#' + temp_color['end'])
        color_list = list(start_color.range_to(end_color, high))

        value = int(current)

        return color_list[value]
Exemplo n.º 6
0
 def make_embed(self, test_index) -> discord.Embed:
     c = Colour(self.colour).rgb
     new_c = discord.Colour.from_rgb(int(c[0] * 255), int(c[1] * 255),
                                     int(c[2] * 255))
     test = self.tests[test_index]
     embed = discord.Embed(
         title=f'{self.registration_date.year} {self.make} {self.model}',
         colour=new_c)
     embed.add_field(name='MOT Result', value=test.result, inline=True)
     embed.add_field(name='MOT Date',
                     value=test.completed_date.strftime("%d/%m/%Y"),
                     inline=True)
     if test.result != 'FAILED':
         embed.add_field(name='MOT Expiry',
                         value=test.expiry_date.strftime("%d/%m/%Y"),
                         inline=True)
     else:
         embed.add_field(name='MOT Expiry', value='N/A', inline=True)
     embed.add_field(
         name='MOT Mileage',
         value=
         f'{"{:,}".format(test.odometer_reading.value)}{test.odometer_reading.unit}',
         inline=True)
     embed.add_field(name='MOT Number', value=test.id, inline=True)
     embed.add_field(name='Car Colour', value=self.colour, inline=True)
     return embed
Exemplo n.º 7
0
def main():

    import warnings
    warnings.filterwarnings("ignore")

    # create halo catalogue
    halo_cat = MXXLCatalogue()

    # empty galaxy catalogue
    gal_cat = BGSGalaxyCatalogue(halo_cat)

    # use hods to populate galaxy catalogue
    hod = HOD_BGS()
    gal_cat.add_galaxies(hod)

    # position galaxies around their haloes
    gal_cat.position_galaxies()

    # add g-r colours
    col = Colour()
    gal_cat.add_colours(col)

    # use colour-dependent k-correction to get apparent magnitude
    kcorr = GAMA_KCorrection()
    gal_cat.add_apparent_magnitude(kcorr)

    # cut to galaxies brighter than apparent magnitude threshold
    gal_cat.cut(gal_cat.get("app_mag") <= par.mag_faint)

    # save catalogue to file
    gal_cat.save_to_file(par.output_dir + "cat.hdf5", format="hdf5")
Exemplo n.º 8
0
    def __init__(self, pin, length):
        self._effect = Effects.RGB
        self._thread = None
        self._thread_terminate = False
        self._thread_running = False
        self.pixels = neopixel.NeoPixel(pin, length)
        self._length = length
        self.pixels[0] = (0, 255, 0)
        self.colour = Colour(0, 0, 20)
        self.paused = False
        self._brightness = 1.0

        for i in range(1, length):
            self.pixels[i] = (0, 0, 20)

        self._backup = []
        self._temperature_pixels = []

        self.save_period = Config.TIME_TO_SAVE
        self.restore_timer = MyTimer(self.save_period, self.restore)
        self.dim_timer = MyTimer(self.save_period, self._dim)

        for i in range(0, self._length):
            self._backup.append(self.pixels[i])

        self._prepare_temperature_pixels()

        self.saved = False
Exemplo n.º 9
0
    def getColours(self, venues, dates):
        colours = []
        for ven in venues:
            for date in dates:
                c = Colour(ven, date)
                colours.append(c)

        return colours
Exemplo n.º 10
0
    def __init__(self, sprite):
        super().__init__('rect renderer')
        self.sprite = sprite
        self.body = None

        self.offset = (0, 0)
        self.size = (10, 10)
        self.colour = Colour((255, 10, 10))
Exemplo n.º 11
0
 def getPixel(self, pixelBox):
     (x, y, x2, y2) = pixelBox
     pixSize = x2 - x
     colour = Colour(0, 0, 0)
     for i in range(self.subPixels):
         colour += self.rayfunc(
             Ray3(self.eye,
                  (Point3(random.uniform(x, x2), random.uniform(y, y2), 1) -
                   self.eye)))
     return old_div(colour, self.subPixels)
Exemplo n.º 12
0
 def colour(self):
     if self.entry < 0:
         return Colour(0, 0, 0)
     colour = self.mat.litColour(self.normal, self.ambient, self.lights,
                                 -self.ray.dir, self.texCords)
     if self.reflection:
         colour += self.mat.reflectivity * self.reflection.colour()
     elif self.bgcolour:
         colour += self.mat.reflectivity * self.bgcolour
     return colour
Exemplo n.º 13
0
 def ray_trace(self, ray, scene):
     colour = Colour(0, 0, 0)
     # Find the nearest object hit by the ray in the scene
     dist_hit, obj_hit = self.find_nearest(ray, scene)
     if obj_hit is None:
         return colour
     hit_pos = ray.origin + ray.direction * dist_hit
     hit_normal = obj_hit.normal(hit_pos)
     colour += self.colour_at(obj_hit, hit_pos, hit_normal, scene)
     return colour
Exemplo n.º 14
0
 def make_basic_embed(self):
     c = Colour(self.colour).rgb
     new_c = discord.Colour.from_rgb(int(c[0] * 255), int(c[1] * 255),
                                     int(c[2] * 255))
     embed = discord.Embed(
         title=f'{self.registration_date.year} {self.make} {self.model}',
         colour=new_c)
     embed.add_field(name='MOT Expiry',
                     value=self.mot_expiry_date.strftime("%d/%m/%Y"),
                     inline=True)
     embed.add_field(name='Colour', value=self.colour, inline=True)
     return embed
Exemplo n.º 15
0
    def new_colour(_colour):
        new_colour = utilities.check_vector(_colour, int)

        if len(new_colour) == 3:
            good = True
            for i in range(3):
                if 0 > new_colour[i] > 255:
                    good = False

            if good:
                return Colour(new_colour)

        raise Exception(f'Cannot create colour {new_colour}. Make sure there are three elements between 0 and 255.')
Exemplo n.º 16
0
    def pattern(self):
        stop = False
        while not stop:
            c1 = random_color()
            c1 = Colour(rgb=(c1[0] / 255.0, c1[1] / 255.0, c1[2] / 255.0))
            c2 = random_color()
            c2 = Colour(rgb=(c2[0] / 255.0, c2[1] / 255.0, c2[2] / 255.0))

            gradient = []
            for c in c1.range_to(c2, 181):
                gradient.append(
                    (int(c.red * 255), int(c.green * 255), int(c.blue * 255)))

            for angle in range(181, 0, -1):
                for bottle, bottle_angle in self.geo.get_near_bottles(
                        angle, 1):
                    if bottle_angle < angle:
                        self.trap.set_color(bottle,
                                            gradient[int(bottle_angle)])
                        sleep(.01)

            if self.stop_thread:
                stop = True
                break
    def __init__(self, sprite):
        super().__init__('particle emitter')
        self.sprite = sprite

        self.rate = 1
        self.size = 3
        self.life_time = 10
        self.speed = 1
        self.angle_range = (0, 360)

        self.go = True
        self.colour = Colour((0, 0, 0))

        self.particles = []

        self.count = 0
Exemplo n.º 18
0
    def get_card(self, card_key):
        if card_key in self._card_dict:
            return self._card_dict[card_key]

        colour_val = int(card_key[0:1])
        number = int(card_key[1:])

        if colour_val < 1 or colour_val > 6:
            raise ValueError("Invalid colour val", colour_val)

        if number < 1 or number > 10:
            raise ValueError("Invalid card number", number)

        new_card = Card(Colour(colour_val), number)
        self._card_dict[card_key] = new_card
        return new_card
Exemplo n.º 19
0
    def pixelColour(self, x, y, samples=1):
        pitch = .5 / samples
        colour = Colour(0, 0, 0)
        count = 0
        for subX in range(samples):
            for subY in range(samples):
                count += 1
                ray = self.getRay(x - .5 + (subX + 1) * pitch + subX * pitch,
                                  y - .5 + (subY + 1) * pitch + subY * pitch)
                hit = self.processRay(ray)
                colour = colour + hit.colour()
                #depth = math.log((hit.length() + 0.1), 10)
                #colour = colour + Colour(depth, depth, depth)

        self.pixels[samples] += 1
        return colour / count
Exemplo n.º 20
0
 def getPixel(self, pixelBox):
     (x, y, x2, y2) = pixelBox
     pitch = old_div((x2 - x), (self.subPixels * 2))
     xx = x
     yy = y
     count = 0
     colour = Colour(0, 0, 0)
     for col in range(self.subPixels):
         for row in range(self.subPixels):
             colour += self.rayfunc(
                 Ray3(self.eye,
                      (Point3(xx + pitch, yy + pitch, 1) - self.eye)))
             count += 1
             yy += pitch * 2
         yy = y
         xx += pitch * 2
     assert count == self.subPixels * self.subPixels
     return old_div(colour, count)
Exemplo n.º 21
0
def create_color_stops(breaks, colors='RdYlGn', color_ramps=color_ramps):
    """Convert a list of breaks into color stops using colors from colorBrewer
    or a custom list of color values in RGB, RGBA, HSL, CSS text, or HEX format.
    See www.colorbrewer2.org for a list of color options to pass
    """

    num_breaks = len(breaks)
    stops = []

    if isinstance(colors, list):
        # Check if colors contain a list of color values
        if len(colors) == 0 or len(colors) != num_breaks:
            raise ValueError(
                'custom color list must be of same length as breaks list')

        for color in colors:
            # Check if color is valid string
            try:
                Colour(color)
            except:
                raise ValueError(
                    'The color code {color} is in the wrong format'.format(
                        color=color))

        for i, b in enumerate(breaks):
            stops.append([b, colors[i]])

    else:
        if colors not in color_ramps.keys():
            raise ValueError('color does not exist in colorBrewer!')
        else:

            try:
                ramp = color_ramps[colors][num_breaks]
            except KeyError:
                raise ValueError(
                    "Color ramp {} does not have a {} breaks".format(
                        colors, num_breaks))

            for i, b in enumerate(breaks):
                stops.append([b, ramp[i]])

    return stops
Exemplo n.º 22
0
    def _fade(self, colour1, colour2, steps, interval):
        self._thread_running = True
        lastUpdate = time.time() - interval
        interval = interval / steps

        for i in range(1, steps + 1):
            r = round(((colour1.r * (steps - i)) + (colour2.r * i)) / steps)
            g = round(((colour1.g * (steps - i)) + (colour2.g * i)) / steps)
            b = round(((colour1.b * (steps - i)) + (colour2.b * i)) / steps)

            while ((time.time() - lastUpdate) < interval):
                pass

            colour = Colour(r, g, b)
            for j in range(0, self._length):
                if not self.paused:
                    self._set_pixel(j, colour.r, colour.g, colour.b)

            lastUpdate = time.time()
        self._thread_running = False
        self.colour = colour2
Exemplo n.º 23
0
    def match_color(self, color, convert2discord=True):
        color = color.lower()
        if color in self._color_names:
            rgb = self._color_names[color]

            if not convert2discord:
                return rgb['hex']

            rgb = rgb['rgb']
            rgb = tuple(map(lambda c: c / 255.0, rgb))
        else:
            try:
                rgb = Colour(color)

                if not convert2discord:
                    return rgb.get_hex_l()

                rgb = rgb.rgb
            except:
                return

        return self.check_rgb(rgb)
Exemplo n.º 24
0
    def __init__(
        self,
        x_pos: int,
        y_pos: int,
        text: str = "",
        min_width: int = 10,
        min_height: int = 10,
    ):
        """
        Create a Box

        Args:
          x_pos: The x position of the box
          y_pos: The y position of the box
          text: The text to show in the box
          min_width: The minimum width for the box
          min_height: The minimum height for the box
        """
        self.x_pos = x_pos
        self.y_pos = y_pos
        self.colour = Colour("black")

        # These settings are ratios of how far up/across our anchor point
        # is (0 => left, 0.5 => middle, 1 => right for x)
        self.x_anchor = 0.5
        self.y_anchor = 0.5

        self._min_width = min_width
        self._min_height = min_height

        # Option to put text at the top of the box
        self.text_top = False

        # Setting the text will actually try to resize the box so we need to
        # do this last to make sure the min and max have already been set
        self.text = text
Exemplo n.º 25
0
    def __init__(self,
                 obj,
                 ray,
                 entry,
                 exit,
                 normal=None,
                 material=None,
                 TexCords=None):
        self.obj = obj
        self.entry = entry
        self.exit = exit
        self.normal = normal
        self.normal2 = None
        self.mat = material
        self.texCords = TexCords
        self.ray = ray

        # Undefined variables
        self.reflection = None
        self.bgcolour = None
        self.lights = [None]

        # temp ambiant for when colour is called before calcLights
        self.ambient = Colour(0.8, 0.8, 0.8)
Exemplo n.º 26
0
from geom3 import Point3, Vector3, unit
from colour import Colour
from sphere import Sphere
from plane import Plane
from material import Material
from scene import Scene
from light import *
from texture import *
from CSG import *
from camera import Camera

WIN_SIZE = 300  # Screen window size (square)

SHINY_RED = Material(Colour(0.7, 0.7, 0.7), Colour(0.4, 0.4, 0.4), 100, .2)
SHINY_SPHERE = Material(Colour(0.2, 0.3, 0.7), Colour(0.8, 0.8, 0.8), 200, .3)
MATT_CUBE = Material(Colour(0.7, 0.7, 0.7), Colour(0.9, 0.9, 0.9), 300, .5)
CHECK_FLOOR = Material(
    None, None, None, None,
    Texture_Check(6, Colour(.1, .1, .1), Colour(0.7, 0.7, 0.7)))

scene = Scene([
    Intersection([  # Cube
        Plane(Point3(0.5, 0.0, 0.5), Vector3(0, -1, 0), MATT_CUBE),
        Plane(Point3(0.5, 0.1, 0.5), Vector3(0, 1, 0), MATT_CUBE),
        Plane(Point3(0.2, 0.0, 0.5), Vector3(-1, .3, 0), MATT_CUBE),
        Plane(Point3(0.8, 0.0, 0.5), Vector3(1, .3, 0), MATT_CUBE),
        Plane(Point3(0.5, 0.0, 0.8), Vector3(0, .3, 1), MATT_CUBE),
        Plane(Point3(0.5, 0.0, 0.2), Vector3(0, .3, -1), MATT_CUBE)
    ]),
    Sphere(Point3(0.5, 0.3, 0.5), 0.2, SHINY_SPHERE),
    Plane(Point3(0, 0, 0), Vector3(0, 1, 0), CHECK_FLOOR),
Exemplo n.º 27
0
"""
Unit tests for Deployment class
"""

from unittest.mock import MagicMock, Mock

import pytest
from colour import Colour

from deployment import Deployment

BLACK = Colour("black")


@pytest.fixture(name="simple_deployment")
def simple_deployment_fixture(simple_box):
    """
    This fixture will return a simple Deployment
    with width 10, height 20, x_pos 5, y_pos 15, colour black
    and name "simple"
    """
    deployment = Deployment("simple", simple_box)
    return deployment


@pytest.mark.parametrize("name", ["Steve", "Bob"])
def test_create_deployment(name, simple_box):
    """
    Test that we can create a deployment with the right name
    """
    deployment = Deployment(name, simple_box)
Exemplo n.º 28
0
 def __init__(self, length):
     self.length = length
     self.height = length
     colour = Colour()
     self.colour = colour
Exemplo n.º 29
0
    def __init__(self, hexColor):

        self.hexColor = hexColor
        self.colour = Colour(hexColor)
Exemplo n.º 30
0
from geom3 import Point3, Vector3, unit
from colour import Colour
from sphere import Sphere
from plane import Plane
from material import Material
from scene import Scene
from light import *
from texture import *
from CSG import *
from camera import Camera

WIN_SIZE = 800                              # Screen window size (square)

SHINY_RED = Material(Colour(0.7, 0.1, 0.2), Colour(0.4, 0.4, 0.4), 100, .2)
SHINY_BLUE = Material(Colour(0.2, 0.3, 0.7), Colour(0.8, 0.8, 0.8), 200, .3)
MATT_GREEN = Material(Colour(0.1, 0.85, 0.1))
CHECK_FLOOR = Material(
    None, None, None, None, Texture_Check(
        6, Colour(
            0, 0, 0), Colour(
                0.5, 0.5, 0.5)))

scene = Scene([
    Sphere(Point3(0.35, 0.6, 0.5), 0.25, SHINY_BLUE),
    Difference([
               Intersection([  # Bowl
                   Plane(
                       Point3(
                           0.1, 0.175, 0.8), Vector3(
                           0.4, 1, 0.3), SHINY_BLUE),
                   Sphere(Point3(0.1, 0.175, 0.8), 0.175, SHINY_BLUE),