예제 #1
0
def light_or_dark(is_dark=True):
    accent = colors.accent_colors(is_dark)
    fb = colors.foreground_background(is_dark)
    rgb = {
        'profile': fb['foreground'],
        'edge': fb['foreground'],
        'ct': accent['blue'],
        'ray': fb['foreground'],
        'rayfan_fill': [254, 197, 254, 64],  # magenta, 25%
        'ax_ray': rgb2mpl([138, 43, 226]),  # blueviolet
        'pr_ray': rgb2mpl([198, 113, 113]),  # sgi salmon
    }
    return {**rgb, **accent, **fb}
예제 #2
0
    def create_paraxial_layout(self, view):
        parax_model = self.opt_model.parax_model

        ax_color = rgb2mpl([138, 43, 226])  # blueviolet
        ax_poly = ParaxialRay(self.opt_model,
                              parax_model.ax,
                              color=ax_color,
                              label='axial ray')
        pr_color = rgb2mpl([198, 113, 113])  # sgi salmon
        pr_poly = ParaxialRay(self.opt_model,
                              parax_model.pr,
                              color=pr_color,
                              label='chief ray')
        return [ax_poly, pr_poly]
예제 #3
0
    def create_polygon(self, poly, **kwargs):
        def highlight(p):
            fc = p.get_facecolor()
            ec = p.get_edgecolor()
            lw = p.get_linewidth()
            p.unhilite = (fc, ec, lw)
            alpha = fc[3] + 0.5
            if alpha > 1.0:
                alpha -= 1.0  # subtract 0.5 instead of adding
            p.set_facecolor((fc[0], fc[1], fc[2], alpha))

        def unhighlight(p):
            fc, ec, lw = p.unhilite
            p.set_facecolor(fc)
            p.set_edgecolor(ec)
            p.set_linewidth(lw)
            p.unhilite = None

        if 'linewidth' not in kwargs:
            kwargs['linewidth'] = self.linewidth
        fill_color = kwargs.pop('fill_color',
                                self._rgb['background1'] + '40')  # 25%
        if not isinstance(fill_color, str):
            fill_color = rgb2mpl.rgb2mpl(fill_color)
        p = patches.Polygon(poly,
                            closed=True,
                            facecolor=fill_color,
                            edgecolor=self._rgb['foreground'],
                            **kwargs)
        p.highlight = highlight
        p.unhighlight = unhighlight
        return p
예제 #4
0
    def create_polygon(self, poly, rgb_color, **kwargs):
        def highlight(p):
            fc = p.get_facecolor()
            ec = p.get_edgecolor()
            lw = p.get_linewidth()
            p.unhilite = (fc, ec, lw)
            alpha = fc[3] + 0.5
            if alpha > 1.0:
                alpha -= 1.0  # subtract 0.5 instead of adding
            p.set_facecolor((fc[0], fc[1], fc[2], alpha))

        def unhighlight(p):
            fc, ec, lw = p.unhilite
            p.set_facecolor(fc)
            p.set_edgecolor(ec)
            p.set_linewidth(lw)
            p.unhilite = None

        if 'linewidth' not in kwargs:
            kwargs['linewidth'] = self.linewidth
        fill_color = rgb2mpl(kwargs.pop('fill_color', rgb_color))
        p = Polygon(poly, closed=True, fc=fill_color, ec='black', **kwargs)
        p.highlight = highlight
        p.unhighlight = unhighlight
        return p
예제 #5
0
 def create_polygon(self, poly, rgb_color, **kwargs):
     p = Polygon(poly,
                 closed=True,
                 fc=rgb2mpl(rgb_color),
                 ec='black',
                 **kwargs)
     p.set_linewidth(self.linewidth)
     return p
예제 #6
0
 def create_polygon(self, poly, **kwargs):
     rgb_color = kwargs.pop('fill_color')
     p = Polygon(poly,
                 closed=True,
                 fc=rgb2mpl(rgb_color),
                 ec='black',
                 **kwargs)
     p.set_linewidth(self.linewidth)
     return p
예제 #7
0
    def update_shape(self, view):
        n_color = rgb2mpl([138, 43, 226])  # blueviolet
        sys = self.diagram.opt_model.parax_model.sys
        shape = self.diagram.shape
        self.handles['shape'] = shape[self.node], 'vertex', {'linestyle': '',
                                                             'marker': 's',
                                                             'picker': 6,
                                                             'color': n_color,
                                                             'hilite': 'red',
                                                             'zorder': 3.}
        # define the "constant spacing" or "slide" constraint
        slide_pts = compute_slide_line(shape, self.node, sys[self.node][rmd])
        if slide_pts is not None:
            seg = [*slide_pts]
            f_color = rgb2mpl([138, 43, 226, 63])  # blueviolet
            h_color = rgb2mpl([138, 43, 226, 255])  # blueviolet

            self.handles['slide'] = seg, 'polyline', {'linestyle': ':',
                                                      'picker': 6,
                                                      'color': f_color,
                                                      'hilite': h_color,
                                                      'zorder': 2.5}
        gui_handles = {}
        for key, graphics_handle in self.handles.items():
            poly_data, poly_type, kwargs = graphics_handle
            poly = np.array(poly_data)
            if poly_type == 'vertex':
                p = view.create_vertex(poly, **kwargs)
            elif poly_type == 'polyline':
                p = view.create_polyline(poly, **kwargs)
            elif poly_type == 'polygon':
                p = view.create_polygon(poly, self.render_color(),
                                        **kwargs)
            else:
                break
            if len(poly.shape) > 1:
                bbox = bbox_from_poly(poly)
            else:
                x = poly[0]
                y = poly[1]
                bbox = np.array([[x, y], [x, y]])
            gui_handles[key] = GUIHandle(p, bbox)
        return gui_handles
예제 #8
0
    def update_shape(self, view):
        node_color = rgb2mpl([138, 43, 226])  # blueviolet
        sys = self.diagram.opt_model.parax_model.sys
        shape = self.diagram.shape
        dgm_rgb = self.diagram.dgm_rgb
        self.handles['shape'] = (shape[self.node], 'vertex', {
            'linestyle': '',
            'linewidth': 3,
            'marker': 's',
            'picker': 6,
            'color': dgm_rgb['node'],
            'hilite': dgm_rgb['hilite'],
            'zorder': 3.
        })
        # define the "constant spacing" or "slide" constraint
        if view.enable_slide:
            slide_pts = compute_slide_line(shape, self.node,
                                           sys[self.node][rmd])
            if slide_pts is not None:
                seg = [*slide_pts]
                f_color = rgb2mpl([138, 43, 226, 127])  # blueviolet
                h_color = rgb2mpl([138, 43, 226, 255])  # blueviolet

                hilite_kwargs = {
                    'color': dgm_rgb['slide'],
                    'linewidth': 3,
                    'linestyle': '-'
                }
                self.handles['slide'] = (seg, 'polyline', {
                    'linestyle': '--',
                    'linewidth': 3,
                    'picker': 6,
                    'color': dgm_rgb['slide'],
                    'hilite': hilite_kwargs,
                    'zorder': 2.5
                })
        return view.create_patches(self.handles)