Beispiel #1
0
def color_byte_array(color_value):
    """
    convert color into a 3 byte bytearray

    :param color_value: 6-digit (e.g. #fa3b2c), 3-digit (e.g. #fbb),
    fully spelled color (e.g. white)
    """
    color = Color(color_value)
    return bytearray([
        int(round(color.get_red()*255)),
        int(round(color.get_green()*255)),
        int(round(color.get_blue()*255)),
    ])
Beispiel #2
0
 def circle(self,
            pos,
            arc,
            color: Color = Color("black"),
            alpha: float = 1,
            strokecolor=None,
            strokewidth: int = 1):
     self.context.set_line_width(strokewidth)
     if strokecolor:
         self.context.set_source_rgba(strokecolor.get_red(),
                                      strokecolor.get_blue(),
                                      strokecolor.get_green(), alpha)
         self.context.arc(pos[0], pos[1], arc, 0, 2 * math.pi)
         self.context.stroke_preserve()
         self.context.set_source_rgba(color.get_red(), color.get_blue(),
                                      color.get_green(), alpha)
         self.context.fill()
     else:
         self.context.set_source_rgba(color.get_red(), color.get_blue(),
                                      color.get_green(), alpha)
         self.context.arc(pos[0], pos[1], arc, 0, 2 * math.pi)
         self.context.stroke()
    def create_shader_of_color(self, color):
        all_shaders = cmds.ls(mat=True)
        repeated_shader = [shdr for shdr in all_shaders if shdr == color]

        if repeated_shader:
            print 'There already exists a shader called {}'.format(color)
        else:
            col = Color(color)
            shader = cmds.shadingNode('lambert', asShader=True, name=color)
            cmds.setAttr('{}.color'.format(shader),
                         col.get_red(),
                         col.get_green(),
                         col.get_blue(),
                         type='double3')
Beispiel #4
0
def dynamic_css_project(project_id: int):
    redis = current_app.config.get('SESSION_REDIS')
    cache_key = 'dynamic_css_project_%s' % project_id
    if not redis.exists(cache_key):
        from colour import Color
        import math
        project_api = sw.ProjectApi(api_client=g.api)
        project = project_api.projects_project_id_get(project_id=project_id)
        if project.id:
            cc = Color(color=project.accent_color)
            accent_color_rgb = '%s, %s, %s' % (math.floor(
                cc.get_red() * 255), math.floor(
                    cc.get_green() * 255), math.floor(cc.get_blue() * 255))
            cdn_base_url = current_app.config.get('CDN_BASE_URL')
            stylesheet_str = render_template('project.css.template',
                                             accent_color=project.accent_color,
                                             accent_color_rgb=accent_color_rgb,
                                             cdn_base_url=cdn_base_url)
            redis.set(cache_key, stylesheet_str, ex=60)
        else:
            abort(404)
    content = redis.get(cache_key)
    return Response(content, content_type='text/css')
Beispiel #5
0
def string_to_colornum(name):
    c = Color(name)
    r = int(c.get_red() * 255)
    g = int(c.get_green() * 255)
    b = int(c.get_blue() * 255)
    return (r, g, b)
Beispiel #6
0
def color_from_name(name):
    c = Color(name)
    r = int(c.get_red() * 255)
    g = int(c.get_green() * 255)
    b = int(c.get_blue() * 255)
    return compose_color(r, g, b)