Exemplo n.º 1
0
    def __init__(self, x, y, ax, msize=1, area=None, **kwargs):
        marker_size = 50

        # change markers if area is defined.
        # solution taken from here:
        # https://stackoverflow.com/questions/52303660/iterating-markers-in-plots/52303895#52303895
        # create array for linewidth corresponding to intensity
        if area is not None:
            area_sub = (area - min(area))
            area_norm = area_sub / max(area_sub)
            marker_linewidth = 2 + 13 * (1 - area_norm)
        else:
            # create frame like marker
            marker_linewidth = 5 * np.ones_like(y)

        # create all paths
        frames = []
        for marker_lw in marker_linewidth:
            marker_rest = marker_size - 2 * marker_lw
            markerstring = (f'm 0,0 v 0 {marker_size} h {marker_size} '
                            f'v -{marker_size} '
                            f'z m {marker_lw},{marker_lw} '
                            f'h {marker_rest} v {marker_rest} '
                            f'h -{marker_rest} z')
            frame = parse_path(markerstring)
            frames.append(frame)

        self.n = len(x)
        self.ax = ax
        self.ax.figure.canvas.draw()
        self.size_data = msize
        self.size = msize
        self.sc = self.mscatter(x, y, s=self.size, m=frames, **kwargs)
        self._resize()
        self.cid = ax.figure.canvas.mpl_connect('draw_event', self._resize)
Exemplo n.º 2
0
 def get_baseline_end(self,
                      glyph_type,
                      position,
                      rotation=0.0,
                      user_parameters=None):
     glyph = self.glyphs_library[glyph_type]
     merged_parameters = glyph['defaults'].copy()
     if user_parameters is not None:
         # Collate parameters (user parameters take priority)
         for key in user_parameters.keys():
             merged_parameters[key] = user_parameters[key]
     baseline_path = None
     for path in glyph['paths']:
         if path['class'] == 'baseline':
             svg_text = self.__eval_svg_data(path['d'], merged_parameters)
             baseline_path = svgpath2mpl.parse_path(svg_text)
             break
     if baseline_path is not None:
         # Draw glyph to the axis with correct styling parameters
         baseline_y = glyph['defaults']['baseline_y']
         y_flipped_path = self.__flip_position_rotate_glyph(
             baseline_path, baseline_y, position, rotation)
         return (y_flipped_path.vertices[1, 0], y_flipped_path.vertices[1,
                                                                        1])
     else:
         return None
Exemplo n.º 3
0
 def __init__(self, angle=None, path_string=None):
     self.angle = angle or []
     self.path_string = path_string or """m 66.893258,227.10128 h 5.37899 v 0.91881 h 1.65571 l 1e-5,-3.8513 3.68556,-1e-5 v -1.43933
     l -2.23863,10e-6 v -2.73937 l 5.379,-1e-5 v 2.73938 h -2.23862 v 1.43933 h 3.68556 v 8.60486 l -3.68556,1e-5 v 1.43158
     h 2.23862 v 2.73989 h -5.37899 l -1e-5,-2.73989 h 2.23863 v -1.43159 h -3.68556 v -3.8513 h -1.65573 l 1e-5,0.91881 h -5.379 z"""
     self.path = parse_path( self.path_string )
     self.path.vertices -= self.path.vertices.mean( axis=0 )
     self.marker = mpl.markers.MarkerStyle( marker=self.path )
     self.marker._transform = self.marker.get_transform().rotate_deg(angle)
Exemplo n.º 4
0
    def get_rawpaths_to_draw(self, glyph, merged_params):
        new_paths_to_draw = []
        for path in glyph['paths']:
            if path['type'] not in ['baseline']:
                svg_text = self.eval_svg_data(path['d'], merged_params)
                new_paths_to_draw.append(svg2mpl.parse_path(svg_text))
        for circle in glyph['circles']:
            new_paths_to_draw.append(self.get_circle_path(circle))

        return new_paths_to_draw
Exemplo n.º 5
0
    def load_svg(path):
        """
        """

        paths, attributes = svg2paths(path)

        result = ddd.group2()

        for k, v in enumerate(attributes):
            #print(v)  # v['d']  # print d-string of k-th path in SVG

            # Ex svgpath = 'M10 10 C 20 20, 40 20, 50 10Z'
            mpl_path = parse_path(v['d'])
            '''
            import matplotlib.pyplot as plt
            fig = plt.figure(figsize=(200, 200))
            ax = fig.add_subplot(111)
            ax.axis([0, 0, 200, 200])
            collection = matplotlib.collections.PathCollection([mpl_path])
            collection.set_transform(ax.transData)
            #patch = matplotlib.patches.PathPatch(mpl_path, facecolor="red", lw=2)
            ax.add_artist(collection)
            #ax.add_patch(patch)
            ax.set_xlim([0, 200])
            ax.set_ylim([200, 0])
            plt.show()
            '''

            coords = mpl_path.to_polygons(closed_only=True)

            item = ddd.polygon(coords[0]).clean()  #.convex_hull()

            for c in coords[1:]:
                ng = ddd.polygon(c).clean()  #.convex_hull()
                #ng.show()
                #print (ng.geom.is_valid)
                #if not ng.geom.is_valid: continue
                if item.contains(ng):
                    item = item.subtract(ng)
                else:
                    item = item.union(ng)

            #result = ddd.group([ddd.polygon(c) for c in coords], empty=2)
            result.append(item)

        #result = result.scale([1.0 / (48 * 64), -1.0 / (48 * 64)])
        #result = result.simplify(0.005)  #
        #result.show()

        result = result.union().scale([1, -1]).clean(0)
        xmin, ymin, xmax, ymax = result.bounds()
        result = result.translate([0, -(ymin + ymax)])
        #result = ddd.align.anchor(result, ddd.ANCHOR_CENTER)

        return result
Exemplo n.º 6
0
def test_parse_path():
    path = parse_path(d)
    patch = mpl.patches.PathPatch(path,
                                  facecolor=fill,
                                  edgecolor=stroke,
                                  linewidth=stroke_width)

    fig = plt.figure(figsize=(12, 5.25))
    ax = fig.add_subplot(111)
    ax.add_patch(patch)
    ax.set_aspect(1)
    ax.set_xlim([0, 1200])
    ax.set_ylim([0, 400])
Exemplo n.º 7
0
    def open(self):
        # read the sveg file
        doc = minidom.parse(self._filename)
        path_strings = [
            path.getAttribute('d') for path in doc.getElementsByTagName('path')
        ]
        doc.unlink()

        # the path_strings will now be an array of strings containing coords
        self._paths = []
        for entry in path_strings:
            path = svgpath2mpl.parse_path(entry)
            self._paths.append(path)
Exemplo n.º 8
0
def parse_svg_into_mpl(svg_path):

    mpl_path = parse_path(svg_path)

    def center(mpl_path):
        mpl_path.vertices -= mpl_path.vertices.mean(axis=0)
        return mpl_path

    def upsidedown(mpl_path):
        mpl_path.vertices[:, 1] *= -1
        return mpl_path

    return upsidedown(center(mpl_path))
Exemplo n.º 9
0
def get_glyph_patch(path_data, color, x, y, dx, dy, **kwargs):
    kwargs.setdefault('facecolor', color)
    kwargs.setdefault('edgecolor', 'none')
    path = parse_path(path_data)
    # normalize and flip upside down
    path.vertices[:, 0] -= path.vertices[:, 0].min()
    path.vertices[:, 1] -= path.vertices[:, 1].min()
    path.vertices[:, 0] /= path.vertices[:, 0].max()
    path.vertices[:, 1] /= path.vertices[:, 1].max()
    path.vertices[:, 1] = 1 - path.vertices[:, 1]
    # scale then translate
    path.vertices *= [dx, dy]
    path.vertices += [x, y]
    return PathPatch(path, **kwargs)
Exemplo n.º 10
0
def add_fish(ax, offset=(0, 0), scale=1):
    """Plot the siluhette of a fish."""
    path_fish = "m0 0c-13.119 71.131-12.078 130.72-12.078 138.78-5.372 8.506-3.932 18.626-3.264 23.963-6.671 1.112-2.891 4.002-2.891 5.114s-2.224 8.005.445 9.116c-.223 3.113.222 0 0 1.557-.223 1.556-3.558 3.558-2.891 8.227.667 4.67 3.558 10.228 6.226 9.784 2.224 4.892 5.559 4.669 7.56 4.447 2.001-.223 8.672-.445 10.228-6.004 5.115-1.556 5.562-4.002 5.559-6.67-.003-3.341.223-8.45-3.113-12.008 3.336-4.224.667-13.786-3.335-13.786 1.59-8.161-2.446-13.786-3.558-20.679-2.223-34.909-.298-102.74 1.112-141.84"
    path = parse_path(path_fish)
    min_p = np.min(path.vertices, 0)
    path.vertices -= min_p
    f = np.abs(path.vertices[:, 1]).max() * scale
    path.vertices[:, 0] = path.vertices[:, 0] / f
    path.vertices[:, 1] = path.vertices[:, 1] / f

    path.vertices += np.array(offset)

    collection = collections.PathCollection([path],
                                            linewidths=0,
                                            facecolors=["#909090"])
    ax.add_artist(collection)
Exemplo n.º 11
0
def test_parse_path():
    d = "M300,200 h-150 a150,150 0 1,0 150,-150 z"
    fill = "red"
    stroke = "blue"
    stroke_width = 5

    path = parse_path(d)
    patch = mpl.patches.PathPatch(path,
                                  facecolor=fill,
                                  edgecolor=stroke,
                                  linewidth=stroke_width)

    fig = plt.figure(figsize=(12, 5.25))
    ax = fig.add_subplot(111)
    ax.add_patch(patch)
    ax.set_aspect(1)
    ax.set_xlim([0, 1200])
    ax.set_ylim([0, 400])
Exemplo n.º 12
0
def assign_nested_coords(
    slices: List[Slice], svg_file: str, bread_box: BoundingBox
) -> List[Slice]:
    Y_MAX = 210
    L_x = int(bread_box.width)
    L_y = int(bread_box.height)
    L_y_mm = _NEST_L * L_y / L_x / _MM_IN_COORD_UNITS
    reverse_scaler = _MM_IN_COORD_UNITS * L_x / _NEST_L

    tree = etree.parse(svg_file)
    root = tree.getroot()
    path_elems = root.findall(".//{http://www.w3.org/2000/svg}path")
    paths = [parse_path(elem.attrib["d"]) for elem in path_elems]

    # Rotation matrix to rotate to bread box angle
    rotation_mat = np.array(
        [
            [np.cos(bread_box.angle), -np.sin(bread_box.angle)],
            [np.sin(bread_box.angle), np.cos(bread_box.angle)],
        ]
    )

    for idx, (slice_, path) in enumerate(zip(slices, paths)):

        # Translate to origin
        vertices = np.array(path.vertices)
        vertices[:, 1] -= Y_MAX - L_y_mm
        # Scale to original image size
        scaled = vertices * reverse_scaler

        # Rotate polygons so that they're back at the bread box angle
        # dot product is 2 x 2 * 2 x num_points -> 2 x num_points
        # Transpose that, and we're back to num_points x 2
        scaled = np.dot(rotation_mat, scaled.T).T

        # Translate to bread
        # scaled[:, 0] += bread.box[0]
        # scaled[:, 1] += bread.box[1]
        scaled[:, 0] += bread_box.reference[0]
        scaled[:, 1] += bread_box.reference[1]

        slice_.nested_coords = scaled

    return slices
Exemplo n.º 13
0
    def open(self):
        # read the svg file

        if os.path.exists(self._filename):
            doc = minidom.parse(self._filename)
        else:
            # see if we can find a built in version
            local_content = pkgutil.get_data('frc1678.limeplotter.loader', 'svgs/' + self._filename)
            doc = minidom.parseString(local_content)

        path_strings = [path.getAttribute('d') for path
                        in doc.getElementsByTagName('path')]
        doc.unlink()

        # the path_strings will now be an array of strings containing coords
        self._paths = []
        for entry in path_strings:
            path = svgpath2mpl.parse_path(entry)
            self._paths.append(path)
Exemplo n.º 14
0
 def draw_glyph(self,
                ax,
                glyph_type,
                position,
                rotation=0.0,
                user_parameters=None,
                user_style=None):
     glyph = self.glyphs_library[glyph_type]
     merged_parameters = glyph['defaults'].copy()
     if user_parameters is not None:
         # Collate parameters (user parameters take priority)
         for key in user_parameters.keys():
             merged_parameters[key] = user_parameters[key]
     paths_to_draw = []
     for path in glyph['paths']:
         if path['class'] not in ['baseline', 'bounding-box']:
             merged_style = path['style']
             if path['id'] is not None and user_style is not None and path[
                     'id'] in user_style.keys():
                 # Merge the styling dictionaries (user takes preference)
                 merged_style = user_style[path['id']].copy()
                 for k in path['style'].keys():
                     if k not in merged_style.keys():
                         merged_style[k] = path['style'][k]
             svg_text = self.__eval_svg_data(path['d'], merged_parameters)
             paths_to_draw.append(
                 [svgpath2mpl.parse_path(svg_text), merged_style])
     # Draw glyph to the axis with correct styling parameters
     baseline_y = glyph['defaults']['baseline_y']
     all_y_flipped_paths = []
     for path in paths_to_draw:
         y_flipped_path = self.__flip_position_rotate_glyph(
             path[0], baseline_y, position, rotation)
         all_y_flipped_paths.append([y_flipped_path])
         patch = patches.PathPatch(y_flipped_path, **path[1])
         if ax is not None:
             ax.add_patch(patch)
     return self.__bounds_from_paths_to_draw(
         all_y_flipped_paths), self.get_baseline_end(
             glyph_type,
             position,
             rotation=rotation,
             user_parameters=user_parameters)
Exemplo n.º 15
0
def get_hurricane_marker():
    hurricane = parse_path(
        """M 188.79857,492.55018 L 180.09663,484.17671 L 188.57725,474.97463 
     C 212.44187,449.07984 230.37031,423.34927 246.04359,392.5 
     C 254.14781,376.5487 265.0005,350.78866 265.0005,347.50373 
     C 265.0005,346.53236 263.21255,347.40666 259.7505,350.07094 
     C 251.67361,356.28665 233.85001,364.64767 222.5005,367.54485 
     C 204.24051,372.20605 178.92084,371.97166 159.45635,366.96123 
     C 147.77122,363.95331 130.93184,355.3283 122.0005,347.77659 
     C 95.11018,325.04006 81.65749,291.36529 81.74139,247 
     C 81.78993,221.33674 85.91479,197.1747 94.55247,171.95714 
     C 111.06665,123.74428 136.98179,82.210848 180.29075,34.54693 
     L 185.6999,28.59386 L 189.6002,31.718323 
     C 191.74536,33.436777 195.9159,37.308373 198.86805,40.32187 
     L 204.23561,45.800955 L 193.66355,57.483549 
     C 168.69038,85.080007 151.53704,109.91644 136.8182,139.79028 
     C 130.67851,152.2516 118.91503,180.17836 119.52809,180.83739 
     C 119.70071,181.02295 122.91512,178.62979 126.67122,175.51926 
     C 144.84799,160.46658 171.06913,152.9127 200.0005,154.39429 
     C 227.96505,155.82638 249.78837,164.40176 267.15103,180.78081 
     C 291.49094,203.74185 302.41509,234.21538 302.36063,279 
     C 302.33536,299.77768 300.97355,312.12979 296.41891,332.89349 
     C 286.70405,377.18157 262.85893,424.36347 228.55502,467.17452 
     C 219.26505,478.76833 199.25099,501.02345 198.17004,500.96183 
     C 197.80179,500.94084 193.58463,497.15559 188.79857,492.55018 
     z M 212.92994,343.99452 C 242.28307,336.85605 266.31414,312.68729 
     273.9846,282.59004 C 276.76052,271.6979 276.75301,253.72727 273.96762,242 
     C 266.78666,211.76606 241.98871,187.12253 211.5005,179.92186 
     C 203.8953,178.12567 200.40831,177.86988 189.0005,178.27134 
     C 173.93019,178.80168 167.30498,180.26871 156.08925,185.55888 
     C 132.8924,196.50023 116.23621,216.81521 109.90648,241.88639 
     C 108.09535,249.06004 107.84969,252.38603 108.2077,264.88639 
     C 108.58615,278.10034 108.93262,280.39476 111.82513,288.842 
     C 113.58452,293.98009 116.23139,300.28009 117.70707,302.842 
     C 137.50495,337.21285 174.70639,353.29022 212.92994,343.99452 z""")
    return hurricane
Exemplo n.º 16
0
def main():
    popu = input("Enter a number for the initial population: ")
    if popu != '':
        INITIAL_POPULATION = int(popu)
    food = input("Enter a number for the food amount: ")
    if food != '':
        FOOD_PER_STEP = int(food)
    carrot = parse_path(
        """m 1.258156,32.01557 c -2.03400005,2.607 -1.15300005,5.051 -0.45800005,5.904 1.52000005,2.286 3.61800005,3.695 6.23600005,4.188 0.207,0.039 0.418,0.052 0.627,0.078 -0.27,0.227 -0.529,0.455 -0.773,0.685 -1.757,1.663 -2.6,3.44 -2.505,5.282 0.146,2.819 2.484,4.646 2.584,4.723 l 0.047,0.034 c 4.119,2.797 8.743,-0.588 8.938,-0.734 l 0.176,-0.168 c 0.072,-0.088 0.141,-0.191 0.212,-0.282 0.452,2.319 1.705,4.163 3.73,5.479 0.475,0.38 3.506,2.62 7.043,0.823 0.438,-0.223 0.834,-0.511 1.208,-0.827 1.036,0.293 2.188,0.381 3.33,-0.023 1.552,-0.55 2.568,-1.871 2.718,-3.535 0.16,-1.769 -0.732,-3.482 -2.271,-4.365 -1.409,-0.808 -3.097,-2.304 -4.665,-5.047 0.933,0.064 1.835,-0.035 2.687,-0.342 5.081,-1.825 25.176999,-31.267 28.741999,-40.8279992 0.3,-0.806 0.144,-1.649 -0.409,-2.20300001 -0.367,-0.367 -0.862,-0.56 -1.39,-0.56 -0.267,0 -0.542,0.049 -0.813,0.15 C 46.623156,4.0375708 17.061156,24.03357 15.266156,29.03257 c -0.245,0.683 -0.361,1.399 -0.37,2.136 -2.742,-1.343 -4.192,-2.65 -4.948,-3.688 -1.102,-1.512 -2.879,-2.446 -4.651,-2.446 -0.019,0 -0.038,0 -0.057,0 -1.477,0.017 -2.788,0.695 -3.598,1.86 -1.20400005,1.734 -0.77700005,3.606 -0.135,4.83 -0.085,0.098 -0.173,0.193 -0.249,0.291 z m 1.16,4.732 c -0.114,-0.149 -1.049,-1.483 0.3,-3.347 0.042,0.05 0.086,0.095 0.129,0.144 0.073,0.084 0.146,0.165 0.22,0.247 0.189,0.211 0.379,0.414 0.572,0.609 0.059,0.06 0.118,0.12 0.177,0.178 3.13,3.066 6.698,4.031 9.936,4.031 1.148,0 2.255,-0.121 3.286,-0.31 -0.111,0.05 -0.226,0.1 -0.339,0.149 -0.157,0.069 -0.314,0.138 -0.475,0.206 -0.173,0.073 -0.348,0.144 -0.526,0.214 -0.148,0.059 -0.3,0.116 -0.451,0.173 -0.278,0.104 -0.56,0.205 -0.847,0.301 -0.179,0.06 -0.358,0.12 -0.539,0.175 -0.175,0.054 -0.353,0.105 -0.53,0.155 -0.197,0.055 -0.395,0.106 -0.594,0.155 -0.195,0.048 -0.391,0.095 -0.588,0.137 -0.276,0.059 -0.553,0.111 -0.831,0.155 -0.15,0.024 -0.3,0.044 -0.45,0.063 -1.174,0.152 -2.349,0.167 -3.466,-0.042 -2.096,-0.395 -3.711,-1.484 -4.984,-3.393 z m 12.247,13.89 c -0.582,0.397 -3.809,2.431 -6.496,0.637 -0.179,-0.147 -1.696,-1.45 -1.787,-3.226 -0.063,-1.23 0.57,-2.484 1.883,-3.727 0.769,-0.728 1.705,-1.448 2.783,-2.141 0.133,-0.017 0.265,-0.044 0.398,-0.064 0.28,-0.042 0.559,-0.084 0.836,-0.138 0.192,-0.038 0.38,-0.083 0.57,-0.126 0.219,-0.05 0.437,-0.099 0.653,-0.156 0.201,-0.052 0.399,-0.108 0.597,-0.166 0.199,-0.058 0.396,-0.117 0.592,-0.179 0.203,-0.065 0.404,-0.13 0.603,-0.199 0.179,-0.062 0.354,-0.126 0.529,-0.191 0.206,-0.076 0.412,-0.151 0.613,-0.231 0.136,-0.054 0.267,-0.11 0.401,-0.165 0.869,-0.359 1.678,-0.736 2.403,-1.106 0.01,-0.005 0.022,-0.011 0.032,-0.016 -0.613,1.136 -1.257,2.483 -1.805,3.936 -0.034,0.091 -0.071,0.179 -0.104,0.271 -0.094,0.259 -0.18,0.523 -0.267,0.788 -0.047,0.144 -0.097,0.287 -0.141,0.433 -0.077,0.251 -0.144,0.504 -0.212,0.759 -0.043,0.162 -0.087,0.323 -0.126,0.486 -0.06,0.251 -0.112,0.503 -0.162,0.756 -0.033,0.168 -0.065,0.335 -0.093,0.504 -0.042,0.251 -0.076,0.502 -0.105,0.753 -0.01,0.088 -0.028,0.175 -0.037,0.263 -0.515,0.847 -1.027,1.585 -1.558,2.245 z m 11.506,5.625 c -2.549,1.269 -4.77,-0.552 -4.86,-0.627 -0.035,-0.03 -0.071,-0.057 -0.109,-0.082 -1.609,-1.033 -2.56,-2.422 -2.906,-4.245 -0.148,-0.778 -0.17,-1.594 -0.109,-2.424 l 0.007,-0.09 c 0.13,-1.575 0.579,-3.198 1.149,-4.707 -0.041,0.959 0.005,1.947 0.167,2.941 0.005,0.031 0.012,0.061 0.017,0.091 0.037,0.215 0.078,0.43 0.126,0.646 0.029,0.132 0.063,0.264 0.097,0.395 0.028,0.108 0.056,0.217 0.088,0.325 0.051,0.179 0.106,0.357 0.166,0.535 0.016,0.048 0.034,0.097 0.051,0.145 0.49,1.399 1.266,2.769 2.419,4.049 0.032,0.035 0.064,0.071 0.096,0.106 0.165,0.179 0.334,0.356 0.514,0.53 0.087,0.085 0.18,0.169 0.271,0.253 0.139,0.128 0.275,0.257 0.423,0.382 0.269,0.231 0.55,0.459 0.849,0.682 0.002,0.002 0.009,0.008 0.012,0.01 0.08,0.07 0.256,0.215 0.507,0.403 0.002,10e-4 0.003,0.003 0.005,0.004 0.256,0.191 0.589,0.42 0.985,0.655 0.013,0.009 0.023,0.016 0.035,0.023 z m 4.933,-5.25 c 0.864,0.495 1.364,1.457 1.275,2.45 -0.038,0.415 -0.249,1.424 -1.394,1.829 -0.323,0.115 -0.656,0.164 -0.989,0.164 -0.53,0 -1.06,-0.128 -1.559,-0.313 0,0 -0.002,-10e-4 -0.003,-10e-4 -0.013,-0.005 -0.025,-0.011 -0.038,-0.016 -0.172,-0.065 -0.341,-0.135 -0.503,-0.212 -0.08,-0.038 -0.155,-0.078 -0.233,-0.117 -0.13,-0.067 -0.259,-0.135 -0.379,-0.204 -0.047,-0.027 -0.094,-0.054 -0.139,-0.081 -0.536,-0.323 -0.949,-0.643 -1.152,-0.808 -0.039,-0.033 -0.063,-0.054 -0.068,-0.057 -0.023,-0.021 -0.047,-0.04 -0.072,-0.059 -0.436,-0.323 -0.837,-0.664 -1.21,-1.018 -0.106,-0.101 -0.193,-0.206 -0.293,-0.308 -0.255,-0.26 -0.503,-0.524 -0.726,-0.799 -0.098,-0.121 -0.182,-0.244 -0.272,-0.366 -0.204,-0.276 -0.398,-0.558 -0.571,-0.849 -0.068,-0.114 -0.133,-0.229 -0.195,-0.344 -0.188,-0.347 -0.359,-0.703 -0.504,-1.07 -0.023,-0.057 -0.049,-0.114 -0.071,-0.171 -0.703,-1.876 -0.863,-4.005 -0.467,-6.378 0.275,-1.644 0.779,-3.137 1.257,-4.291 0.169,0.608 0.348,1.182 0.53,1.739 0.03,0.093 0.062,0.182 0.093,0.274 0.17,0.507 0.346,0.994 0.525,1.46 0.031,0.079 0.06,0.159 0.091,0.238 2.152,5.445 4.893,8.062 7.067,9.308 z m -13.956,-21.303 c 0.539,-1.499 4.297,-4.767 9.365,-8.555 0.085,0.035 0.169,0.074 0.266,0.085 1.633,0.179 3.748,1.023 4.792,2.505 0.318,0.452 0.944,0.559 1.394,0.241 0.452,-0.318 0.56,-0.942 0.241,-1.394 -1.109,-1.572 -2.916,-2.526 -4.562,-3.004 3.18,-2.305 6.722,-4.729 10.247,-7.024 0.149,0.131 0.326,0.232 0.538,0.256 1.025,0.112 2.349,0.635 2.994,1.549 0.318,0.451 0.941,0.56 1.394,0.24 0.451,-0.318 0.559,-0.942 0.24,-1.394 -0.734,-1.041 -1.888,-1.696 -2.982,-2.059 6.474,-4.1239992 12.591999,-7.6099992 15.874999,-8.8339992 0.022,-0.008 0.042,-0.014 0.057,-0.02 -0.004,0.017 -0.01,0.037 -0.018,0.059 -0.807,2.164 -2.306,5.08 -4.199,8.3459992 -0.036,-0.036 -0.059,-0.08 -0.101,-0.111 -0.718,-0.527 -1.481,-0.9849992 -2.267,-1.3599992 -0.139,-0.066 -0.286,-0.098 -0.431,-0.098 -0.373,0 -0.731,0.21 -0.903,0.569 -0.237999,0.4989992 -0.027,1.0959992 0.471,1.3329992 0.674,0.322 1.329,0.715 1.947,1.168 0.097,0.071 0.205,0.114 0.314,0.145 -2.341,3.913 -5.151999,8.212 -7.997999,12.302 -0.381,-0.991 -1.01,-1.993 -1.946,-2.654 -0.175,-0.124 -0.376,-0.183 -0.576,-0.183 -0.314,0 -0.623,0.147 -0.818,0.423 -0.318,0.451 -0.211,1.075 0.24,1.394 0.915,0.646 1.437,1.969 1.549,2.995 0.006,0.057 0.035,0.104 0.05,0.158 -2.214,3.111 -4.395,6.021 -6.341,8.453 -0.477,-1.648 -1.432,-3.461 -3.007,-4.572 -0.175,-0.124 -0.376,-0.183 -0.576,-0.183 -0.314,0 -0.624,0.147 -0.818,0.423 -0.318,0.452 -0.211,1.075 0.24,1.394 1.482,1.046 2.326,3.161 2.505,4.792 0.005,0.043 0.028,0.078 0.038,0.119 -2.251,2.678 -4.035,4.473 -4.92,4.791 -0.49,0.176 -0.998,0.264 -1.529,0.264 -0.502,0 -1.026,-0.079 -1.576,-0.237 -0.44,-0.994 -0.842,-2.074 -1.208,-3.224 -0.024,-0.075 -0.048,-0.149 -0.071,-0.225 -0.151,-0.486 -0.294,-0.988 -0.432,-1.499 -0.031,-0.115 -0.063,-0.224 -0.094,-0.341 -0.158,-0.607 -0.309,-1.228 -0.448,-1.868 -0.009,-0.042 -0.03,-0.079 -0.044,-0.12 -0.014,-0.039 -0.024,-0.08 -0.043,-0.117 -0.005,-0.011 -0.009,-0.022 -0.015,-0.033 -0.017,-0.031 -0.041,-0.055 -0.061,-0.083 -0.005,-0.007 -0.01,-0.014 -0.016,-0.021 -0.023,-0.031 -0.042,-0.065 -0.068,-0.093 -0.006,-0.006 -0.01,-0.013 -0.016,-0.019 v 0 c 0,0 -10e-4,0 -10e-4,0 -0.003,-0.003 -0.006,-0.005 -0.009,-0.007 -0.028,-0.028 -0.062,-0.049 -0.094,-0.074 -0.007,-0.006 -0.014,-0.011 -0.021,-0.017 -0.026,-0.02 -0.049,-0.044 -0.077,-0.061 -0.011,-0.007 -0.023,-0.011 -0.035,-0.017 -0.023,-0.013 -0.048,-0.022 -0.072,-0.033 -0.023,-0.01 -0.045,-0.016 -0.068,-0.025 -0.031,-0.011 -0.058,-0.029 -0.09,-0.037 -0.575,-0.146 -1.134,-0.297 -1.68,-0.452 -0.124,-0.035 -0.239,-0.071 -0.36,-0.106 -0.428,-0.124 -0.85,-0.25 -1.259,-0.379 -0.105,-0.033 -0.204,-0.066 -0.307,-0.1 -0.426,-0.138 -0.844,-0.278 -1.247,-0.421 -0.07,-0.025 -0.139,-0.049 -0.208,-0.074 -0.463,-0.167 -0.913,-0.336 -1.344,-0.509 -10e-4,0 -0.002,-10e-4 -0.003,-10e-4 -0.131,-0.845 -0.065,-1.623 0.202,-2.366 z m -13.863,-1.672 c 0.566,-0.815 1.388,-0.995 1.978,-1.001 0.012,0 0.024,0 0.036,0 1.143,0 2.302,0.62 3.034,1.624 1.384,1.898 3.854,3.585 7.34,5.049 0.006,0.003 0.01,0.009 0.017,0.012 0.039,0.016 0.081,0.031 0.12,0.047 0.303,0.126 0.62,0.249 0.939,0.371 0.276,0.106 0.556,0.211 0.843,0.315 0.292,0.105 0.586,0.21 0.891,0.313 0.418,0.142 0.851,0.279 1.29,0.415 0.165,0.051 0.315,0.105 0.483,0.155 -0.081,0.032 -0.173,0.063 -0.257,0.095 -0.03,0.008 -0.061,0.001 -0.09,0.011 -3.12,1.138 -8.458,2.239 -13.087,-0.973 -0.239,-0.167 -0.474,-0.359 -0.709,-0.55 -0.113,-0.091 -0.228,-0.169 -0.34,-0.266 -0.71,-0.617 -1.399,-1.35 -2.056,-2.213 l -0.127,-0.169 c -0.004,-0.005 -0.01,-0.007 -0.013,-0.012 -0.34,-0.465 -1.212,-1.899 -0.292,-3.223 z"""
    )

    carrot.vertices -= carrot.vertices.mean(axis=0)

    smiley = parse_path(
        """"m 347.64443,921.20355 c -6.883,-57.336 -2.6723,-121.13 -35.926,-170.34 -17.542,-13.456 -62.225,-56.831 -57.208,-52.071 18.748,44.024 77.104,55.949 75.103,110.81 8.1597,36.772 13.133,74.222 18.031,111.6 z m -258.189997,-346.34 c 25.171997,-3.8064 43.673997,-44.382 41.885997,-55.706 -7.3239,23.655 -23.896,40.531 -41.885997,55.706 z m 628.479997,-236.06 c -1.779,-20.66 -55.921,-56.37 -25.998,-18.91 10.007,4.34 20.943,7.66 25.998,18.91 z m -45.023,12.577 c -2.8411,44.7 70.653,30.773 46.861,-9.6744 3.9793,28.688 -30.631,43.155 -39.51,12.577 l -7.3507,-2.9023 z m 2.7565,-119.96 c -2.3865,-41.699 53.947,-63.222 33.186,-105.86 -30.943,-17.882 -76.078,-10.378 -107.03,7.3432 -8.2848,15.315 34.813,45.901 17.566,7.9225 13.758,-23.693 80.078,-38.098 87.155,2.7965 -4.2562,31.694 -41.913,53.324 -30.874,87.795 z m -66.156,-29.023 c 10.25,-14.102 19.063,-25.796 7.1236,-2.7267 -2.8604,5.3701 -2.6104,10.988 -7.1236,2.7267 z m -207.66,-3.8698 c -0.10805,-20.197 -48.73,-38.927 -5.714,-23.46 10.022,3.2245 8.1687,66.87 5.714,23.46 z m 79.224,-1.8175 c -17.476,-47.579 -73.365,-51.482 -114.64,-45.424 -21.664,-0.32891 -33.078,2.7175 -5.9334,9.5109 35.39,9.8535 77.152,-21.652 104.05,19.24 5.7071,5.3332 11.227,10.89 16.525,16.673 z m 105.46,21.166 c -52.091,-14.482 -108.47,-26.319 -160.45,-4.6811 -18.44,8.6743 -86.769,-6.6037 -35.108,6.6811 39.866,10.145 76.69,-23.706 117.45,-13.609 23.992,15.492 51.022,13.599 78.101,11.609 z m 85.462,23.21 c -16.225,-37.805 -66.334,-46.794 -89.592,-10.471 -28.99,35.062 -25.359,85.807 -25.263,129.47 5.7022,-48.939 3.6284,-108.83 47.171,-140.06 20.745,-21.153 53.474,3.4394 67.684,21.061 z m -358.35,316.36 c 26.633,-38.951 76.761,-14.479 114.86,-20.082 53.729,0.18419 114.27,-4.9813 156.34,-44.029 38.69,-41.413 79.154,-88.349 83.171,-149.35 2.4552,-26.699 23.629,-74.632 5.0694,-86.287 3.5256,63.348 -14.314,130.19 -60.674,173.36 -22.343,26.773 -29.813,68.139 -68.135,77.049 -45.879,26.301 -100.76,25.525 -149.82,10.855 -27.955,4.0489 -68.894,6.3497 -80.81,38.485 z m 33.078,-185.75 c 3.8182,-37.825 45.265,-65.234 30.347,-105.17 -13.655,-50.865 -50.914,-91.342 -58.831,-144.43 0.4057,-45.736998 -66.402,-36.230998 -77.402,-40.445998 21.81,1.95 44.821,-0.094 65.905,4.2674 32.855,24.738998 15.67,76.714998 47.536,106.209998 6.9482,40.395 59.634,73.978 32.308,116.53 -15.362,19.857 -32.587,37.348 -39.862,63.036 z m -121.29,-118.03 c 0.70143,-42.665 0.30714,-84.337 -29.941,-115.4 -26.344,-31.299 46.398,-25.741 23.943,-17.394 -48.709,-3.6859 1.676,49.392 16.105,65.076 4.2605,22.855 -3.6789,46.167 -10.107,67.721 z m -117.61,203.16 c 9.4695,-36.014 34.54,-65.621 37.672,-103.52 11.797,-42.405 43.455,-77.827 81.651,-94.839 25.707,-24.103 50.175,-65.14 30.448,-101.55 -12.467,-18.843 -52.034,-58.286998 -24.809,-75.459998 -14.667,34.527998 32.45,67.327998 36.754,103.519998 1.2462,33.461 -19.368,75.797 -52.418,83.633 -29.313,24.19 -55.311,58.737 -69.692,95.178 -8.1985,32.848 -22.838,64.132 -39.605,93.04 z m 178.81,54.45 c -44.497,-4.2194 -60.999,-58.973 -106.78,-57.263 -17.486,-8.0092 -65.897,5.9 -68.718,11.967 36.328,-12.991 79.046,-17.746 110.81,10.008 16.987,20.464 39.093,32.335 64.69,35.288 z m -1.2994,120.4 c 12.148,-34.838 35.277,-72.496 16.243,-110.14 13.036,40.451 -14.143,71.135 -16.243,110.14 z m -265.079997,-68.408 c -11.2020002,-35.178 3.7535,-93.91 47.429,-86.879 -38.743,1.4054 -54.588,46.163 -47.429,86.879 z m 24.689,-45.15 c 2.4701,-42.009 73.334997,-69.767 89.020997,-26.3 3.7224,18.608 2.3143,34.275 -3.258,6.4616 -9.4696,-43.394 -72.235997,-23.093 -81.565997,11.65 l -2.2264,4.2318 -1.9702,3.9568 z m 12.99,36.26 c -4.2188,-15.197 -16.913,-44.427 -22.74,-15.734 -13.973,21.717 2.3182,28.987 2.8756,0.60572 7.4118,-0.36253 6.6809,24.037 19.865,15.128 z m 134.489997,69.78 c -24.268,21.52 -48.605,-1.794 -46.555,-29.035 0.30079,-9.3188 56.727,-7.4693 46.223,25.884 l 0.24174,2.2906 0.0908,0.86038 z m -70.819,80.722 c -43.201997,-14.292 -84.890997,-48.194 -81.629997,-100.75 -3.7943,-15.514 -31.3080002,-51.742 -5.5141,-19.827 15.121,36.903 19.906,86.563 60.515,106.37 8.654197,5.1775 17.564997,9.8761 26.629997,14.203 z m 242.99,227.8 c 25.415,-56.737 7.7583,-123.68 -15.628,-177.76 -12.96,-33.069 -45.755,-50.476 -59.74,-82.187 13.773,-19.31 -18.29,-44.873 -11.362,-15.432 8.7537,22.412 25.288,48.91 46.241,68.101 46.6,55.559 57.402,136.92 40.488,207.28 z m -263.14,-24.627 c 27.434,-53.628 37.779,-115.57 40.977,-175.79 3.1467,-19.457 -27.096,-34.082 1.2549,-15.75 8.13,32.197 -2.1381,66.874 -7.1827,99.22 -7.4559,32.445 -11.338,67.597 -35.049,92.324 z m 105.26,-119.71 c -3.7907,43.752 -26.968,81.963 -60.729,107.08 -17.945,11.8 -54.559997,68.89 -67.675997,39.261 -3.1839,-24.473 33.914997,-31.388 10.99,-6.3001 -22.531,34.387 30.464997,-7.4727 34.900997,-21.012 31.459,-22.909 58.392,-52.983 71.372,-91.55 3.8901,-9.0796 7.6122,-18.24 11.142,-27.481 z m -16.243,-76.617 c 17.213,31.902 15.864,73.212 23.155,109.5 0.60121,13.697 24.361,54.359 8.9119,18.997 -13.304,-41.835 -10.159,-90.586 -27.519,-129.18 -0.18011,-0.70874 -14.292,-3.2205 -4.548,0.68408 z m 51.328,-56.779 c -16.724,32.457 -34.867,66.99 -26.448,105.7 5.778,42.764 10.198,87.027 25.896,127.19 19.922,33.893 46.755,82.137 91.503,72.54 18.288,-2.7402 42.119,-40.692 10.404,-16.755 -37.144,21.138 -76.296,-15.696 -92.26,-49.254 -29.14,-51.916 -22.904,-113.74 -18.192,-171.02 -1.8509,-26.26 51.728,-78.11 16.058,-87.737 -7.952,4.0068 -8.6249,11.244 -6.9624,19.329 z"""
    )
    smiley.vertices -= smiley.vertices.mean(axis=0)

    game = Game(FOOD_PER_STEP, INITIAL_POPULATION)
    print("Initial state ")
    print("Population: ", len(game.rabbits))
    i = 1
    pop = len(game.rabbits)

    fig, axs = plt.subplots(2, 2)
    fig.suptitle('Natural Selection Simulation')
    its = np.array([0])
    speeds = np.array([1.0])
    sizes = np.array([1.0])
    pops = np.array([INITIAL_POPULATION])

    xc = np.array([r.posx for r in game.rabbits])
    yc = np.array([r.posy for r in game.rabbits])
    ss = np.array([r.size for r in game.rabbits])

    xp = np.array([r.posx for r in game.foods])
    yp = np.array([r.posy for r in game.foods])

    axs[0][0].title.set_text("\n\nDistribution")
    axs[0][0].scatter(xc, yc, s=ss * 200, color='black', marker=smiley)
    axs[0][0].scatter(xp, yp, s=50.0, marker=carrot, color='orange')
    axs[0][0].set_facecolor('mediumseagreen')
    axs[0][0].set_xlim([0, GAME_X])
    axs[0][0].set_ylim([0, GAME_Y])

    axs[0][1].plot(its, speeds, 'b')
    axs[0][1].set_xlim([0, 100])
    axs[0][1].set_xlabel('Iterations')
    axs[0][1].set_ylabel('Avg. speed')
    axs[0][1].set_ylim([0, 3])

    axs[1][0].plot(its, sizes, 'g')
    axs[1][0].set_xlim([0, 100])
    axs[1][0].set_ylim([0, 5])
    axs[1][0].set_xlabel('Iterations')
    axs[1][0].set_ylabel('Avg. size')

    axs[1][1].plot(its, pops, 'r')
    axs[1][1].set_xlim([0, 100])
    axs[1][1].set_ylim([0, 500])
    axs[1][1].set_xlabel('Iterations')
    axs[1][1].set_ylabel('Population')
    plt.draw()

    while True > 0:
        if len(game.rabbits) == 0:
            plt.pause(0.1)
            continue
        plt.pause(0.1)
        game.movement()
        game.clean()
        game.reproduce()
        game.clean()
        print("Iteration #", i)
        sum_speed = 0
        sum_size = 0
        sum_energy = 0
        for r in game.rabbits:
            sum_speed += r.speed
            sum_size += r.size
            sum_energy += r.energy_level
        its = np.append(its, i)
        speeds = np.append(speeds, sum_speed / pop)
        sizes = np.append(sizes, sum_size / pop)
        pops = np.append(pops, pop)
        xc = np.array([r.posx for r in game.rabbits])
        yc = np.array([r.posy for r in game.rabbits])
        ss = np.array([r.size for r in game.rabbits])
        xp = np.array([r.posx for r in game.foods])
        yp = np.array([r.posy for r in game.foods])
        print(
            "    Population: {}  Avg. speed: {:.4f}   Avg. size: {:.4f}  Avg. energy: {:.4f}"
            .format(pop, sum_speed / pop, sum_size / pop, sum_energy / pop))
        print("        SD. speed: {:.4f}  SD. sizes: {:.4f}".format(
            np.std(speeds), np.std(sizes)))
        axs[0][0].clear()
        axs[0][0].scatter(xc, yc, s=ss * 200.0, color='black', marker=smiley)
        axs[0][0].scatter(xp, yp, s=50.0, marker=carrot, color='orange')
        axs[0][0].set_xticklabels([])
        axs[0][0].set_yticklabels([])

        axs[0][1].plot(its, speeds, 'b')
        axs[0][1].set_xlim([0, max(NUM_ITERATIONS, i + 10)])
        axs[0][1].set_ylim([0, max(3, max(speeds) + 1)])

        axs[1][0].plot(its, sizes, 'g')
        axs[1][0].set_xlim([0, max(NUM_ITERATIONS, i + 10)])
        axs[1][0].set_ylim([0, max(3, max(sizes) + 1)])

        axs[1][1].plot(its, pops, 'r')
        axs[1][1].set_xlim([0, max(NUM_ITERATIONS, i + 10)])
        axs[1][1].set_ylim([0, max(10, max(pops) + 100)])
        plt.draw()
        if i == 1:
            time.sleep(1)
        i += 1
        pop = len(game.rabbits)
            "id": [utils.get_id(i) for i in p],
            "labels": l
        }
        print([utils.get_id(i) for i in p])


# Editor Interface Plot

ng = pd.read_csv('Database/NGC.csv')
ms = pd.read_csv('Database/messier_objects.csv')
cb = pd.read_csv('Database/constellation_borders.csv')
ty1 = pd.read_csv('Database/tycho-1.csv')
ty2 = pd.read_csv('Database/tycho-2.csv')

ga = parse_path(
    """M 490.60742,303.18917 A 276.31408,119.52378 28.9 0 1 190.94051,274.29027 276.31408,119.52378 28.9 0 1 6.8010582,36.113705 276.31408,119.52378 28.9 0 1 306.46799,65.012613 276.31408,119.52378 28.9 0 1 490.60742,303.18917 Z"""
)
ga.vertices -= ga.vertices.mean(axis=0)
# red

cl = parse_path(
    """M 541.64941,265.49102 A 270.8247,265.49102 0 0 1 270.82471,530.98205 270.8247,265.49102 0 0 1 0,265.49102 270.8247,265.49102 0 0 1 270.82471,0 270.8247,265.49102 0 0 1 541.64941,265.49102 Z"""
)
cl.vertices -= cl.vertices.mean(axis=0)
# yellow

pn2 = parse_path(
    """m 0,326.75709 v 18.09653 h 671.61069 v -18.09653 z m 326.7571,344.85359 h 18.0965 V 0 h -18.0965 z"""
)
pn2.vertices -= pn2.vertices.mean(axis=0)
# black
Exemplo n.º 18
0
def char(ch):
    def tuple_to_imag(t):
        return t[0] + t[1] * 1j

    from freetype import Face
    #face = Face('/usr/share/fonts/truetype/dejavu/DejaVuSerif.ttf')
    face = Face(ddd.DATA_DIR + '/fonts/OpenSansEmoji.ttf')
    face.set_char_size(48 * 64)
    face.load_char(ch)

    #kerning = face.get_kerning(ch, 'x')  # or from previous, actually?
    #print(kerning)

    outline = face.glyph.outline
    y = [t[1] for t in outline.points]
    # flip the points
    outline_points = [(p[0], max(y) - p[1]) for p in outline.points]

    start, end = 0, 0
    paths = []

    for i in range(len(outline.contours)):
        end = outline.contours[i]
        points = outline_points[start:end + 1]
        points.append(points[0])
        tags = outline.tags[start:end + 1]
        tags.append(tags[0])

        segments = [
            [
                points[0],
            ],
        ]
        for j in range(1, len(points)):
            segments[-1].append(points[j])
            if tags[j] and j < (len(points) - 1):
                segments.append([
                    points[j],
                ])

        for segment in segments:
            if len(segment) == 2:
                paths.append(
                    Line(start=tuple_to_imag(segment[0]),
                         end=tuple_to_imag(segment[1])))
            elif len(segment) == 3:
                paths.append(
                    QuadraticBezier(start=tuple_to_imag(segment[0]),
                                    control=tuple_to_imag(segment[1]),
                                    end=tuple_to_imag(segment[2])))
            elif len(segment) == 4:
                C = ((segment[1][0] + segment[2][0]) / 2.0,
                     (segment[1][1] + segment[2][1]) / 2.0)

                paths.append(
                    QuadraticBezier(start=tuple_to_imag(segment[0]),
                                    control=tuple_to_imag(segment[1]),
                                    end=tuple_to_imag(C)))
                paths.append(
                    QuadraticBezier(start=tuple_to_imag(C),
                                    control=tuple_to_imag(segment[2]),
                                    end=tuple_to_imag(segment[3])))

        start = end + 1

    path = Path(*paths)
    #wsvg(path, filename="/tmp/test.svg")
    path_d = path.d()

    # https://gis.stackexchange.com/questions/301605/how-to-create-shape-in-shapely-from-an-svg-path-element
    # This page also has info about SVG reading!

    from svgpath2mpl import parse_path
    #svgpath = 'M10 10 C 20 20, 40 20, 50 10Z'
    mpl_path = parse_path(path_d)
    coords = mpl_path.to_polygons()

    # Add or subtract
    char_2d = ddd.polygon(coords[0])
    for c in coords[1:]:
        ng = ddd.polygon(c)
        #print (ng.geom.is_valid)
        if not ng.geom.is_valid: continue
        if char_2d.contains(ng):
            char_2d = char_2d.subtract(ng)
        else:
            char_2d = char_2d.union(ng)

    #result = ddd.group([ddd.polygon(c) for c in coords], empty=2)
    result = char_2d
    result = result.scale([1.0 / (48 * 64), -1.0 / (48 * 64)])

    result = result.simplify(0.005)  #

    return result
Exemplo n.º 19
0
def visualize2D(tick, obs, params, robots, robot1, centroid, traj_global):
    """
    Visualization: transition to sub pub is needed
    """

    draw_map(obs)
    # draw_gradient(robots[1].U) if params.num_robots > 1 \
    #     else draw_gradient(robots[0].U)

    smiley = parse_path(
        """M458 2420 c-215 -38 -368 -257 -329 -469 34 -182 175 -314 354 -329 l57 -4 0 45 0 44 -42 7 c-101 16 -187 79 -236 171 -37 69 -38 187 -4 257 30 60 90 120 150 150 70 34 188 33 258 -4 89 -47 153 -136 169 -235 l7 -43 50 0 51 0 -6 59 c-13 147 -124 285 -268 334 -60 20 -152 28 -211 17z M1940 2417 c-172 -39 -302 -181 -317 -347 l-6 -60 51 0 50 0 12 52 c14 70 49 126 110 181 118 106 284 100 399 -14 64 -64 86 -120 86 -214 0 -67 -5 -88 -27 -130 -49 -92 -135 -155 -236 -171 l-42 -7 0 -49 0 -50 58 4 c115 8 242 91 306 200 36 61 59 177 51 248 -30 244 -260 410 -495 357z M506 2038 c-9 -12 -16 -41 -16 -64 0 -39 11 -56 158 -240 87 -110 161 -205 166 -212 5 -9 10 -382 6 -494 0 -3 -74 -97 -165 -208 l-165 -202 0 -52 c0 -68 18 -86 86 -86 40 0 55 5 80 28 17 15 112 89 211 166 l180 138 239 0 239 -1 209 -165 c203 -162 210 -166 256 -166 60 0 80 20 80 81 0 43 -8 55 -170 264 l-170 220 0 230 c0 202 2 233 18 257 9 15 86 108 170 208 l152 180 0 54 c0 65 -19 86 -76 86 -36 0 -58 -15 -234 -151 -107 -83 -205 -158 -217 -166 -19 -12 -67 -15 -260 -15 l-238 1 -209 165 -209 166 -53 0 c-43 0 -56 -4 -68 -22z M415 926 c-199 -63 -321 -258 -286 -457 31 -179 161 -309 340 -340 75 -14 171 1 248 37 116 55 209 188 220 314 l6 60 -49 0 -49 0 -17 -70 c-20 -84 -62 -147 -123 -188 -154 -102 -363 -44 -446 124 -35 72 -34 189 3 259 49 92 135 155 236 171 l42 7 0 48 0 49 -42 -1 c-24 0 -61 -6 -83 -13z M2020 882 l0 -50 43 -7 c99 -16 188 -80 235 -169 22 -43 27 -64 27 -131 0 -98 -23 -155 -90 -219 -177 -172 -471 -67 -511 183 l-7 41 -50 0 -50 0 6 -60 c11 -126 102 -257 218 -314 251 -123 542 26 590 303 39 221 -132 448 -351 468 l-60 6 0 -51z"""
    )
    smiley.vertices -= smiley.vertices.mean(axis=0)

    # for robot in robots: plt.plot(
    #    robot.sp[0], robot.sp[1], '^', color='blue',
    #    markersize=10, zorder=15) # robots poses

    for target_i in range(0, 4):
        if target_i == params.victim_index_1:
            plt.plot(robots[target_i].sp[0],
                     robots[target_i].sp[1],
                     marker=smiley,
                     color='orange',
                     markersize=10,
                     zorder=15)  # targetted robots poses
            # print("params.victim_index_1 in visualize2D: " +
            #       str(params.victim_index_1))
        elif target_i == params.victim_index_2:
            plt.plot(robots[target_i].sp[0],
                     robots[target_i].sp[1],
                     marker=smiley,
                     color='purple',
                     markersize=10,
                     zorder=15)  # targetted robots poses
        # elif target_i == params.victim_index_2:
        # elif target_i == params.victim_index_3:
        else:
            plt.plot(robots[target_i].sp[0],
                     robots[target_i].sp[1],
                     marker=smiley,
                     color='blue',
                     markersize=10,
                     zorder=15)  # robots poses

    plt.plot(obs[-3][0][0],
             obs[-3][0][1],
             marker=smiley,
             color='red',
             markersize=10,
             zorder=15)  # attacker drone poses

    plt.plot(obs[-2][0][0],
             obs[-2][0][1],
             marker=smiley,
             color='cyan',
             markersize=10,
             zorder=15)  # attacker drone poses

    robots_poses = []

    for robot in robots:
        robots_poses.append(robot.sp)

    robots_poses.sort(
        key=lambda p: atan2(p[1] - centroid[1], p[0] - centroid[0]))
    plt.gca().add_patch(Polygon(robots_poses, color='yellow'))
    plt.plot(centroid[0],
             centroid[1],
             '*',
             color='b',
             markersize=10,
             label='Centroid position')
    plt.plot(robot1.route[:, 0],
             robot1.route[:, 1],
             linewidth=2,
             color='green',
             label="Leader's path",
             zorder=10)

    # for robot in robots[1:]:
    #    plt.plot(
    #    robot.route[:, 0], robot.route[:, 1], '--', linewidth=2,
    #    color='green', zorder=10)

    # if params.mode_replay is False:
    #     plt.plot(
    #         P[:, 0], P[:, 1], linewidth=3, color='orange',
    #         label='Global planner path')

    # if params.mode_replay is False:
    #     plt.plot(
    #         traj_global[sp_ind, 0], traj_global[sp_ind, 1], 'ro',
    #         color='blue', markersize=7, label='Global planner setpoint')

    # plt.plot(
    #     xy_start[-1][0], xy_start[-1][1], 'bo', color='red', markersize=20,
    #     label='start')
    # plt.plot(
    #     xy_goal[0], xy_goal[1], 'bo', color='green', markersize=20,
    #     label='goal')
    time = tick
    plt.text(-2.2,
             2.2,
             'Time = ' + str(time),
             bbox=dict(facecolor='red', alpha=0.2))
    plt.text(-2.2,
             1.8,
             'l = r, f1 = bl, f2 = br, f3 = or',
             bbox=dict(facecolor='blue', alpha=0.2))
Exemplo n.º 20
0
def get_bounding_box(path):

    minx, miny, maxx, maxy = Polygon(parse_path(path).to_polygons()[0]).bounds
    # As the coordinates of the polygon will be rounded, the bounding box is stretched to the next integer-coordinates bounding box
    minx, miny, maxx, maxy = floor(minx), floor(miny), ceil(maxx), ceil(maxy)
    return BoundingBox(minx, miny, maxx - minx, maxy - miny)
Exemplo n.º 21
0
def plot_vehicle_routes_wrapper(vehicle_routes, place_coords, item_coords,
                                colors, starts, ends, zoom_out):
    # Plotting of the routes in matplotlib.
    figsize = (10, 8)

    fig = plt.figure(figsize=figsize)

    graph.set_plot_font()

    ax = fig.add_subplot(111)

    icon_path = "iconmonstr-location-1.svg"
    doc = minidom.parse(icon_path)  # parseString also exists
    path_strings = [
        path.getAttribute('d') for path in doc.getElementsByTagName('path')
    ]

    smiley = parse_path(
        """m 739.01202,391.98936 c 13,26 13,57 9,85 -6,27 -18,52 -35,68 -21,20 -50,23 -77,18 -15,-4 -28,-12 -39,-23 -18,-17 -30,-40 -36,-67 -4,-20 -4,-41 0,-60 l 6,-21 z m -302,-1 c 2,3 6,20 7,29 5,28 1,57 -11,83 -15,30 -41,52 -72,60 -29,7 -57,0 -82,-15 -26,-17 -45,-49 -50,-82 -2,-12 -2,-33 0,-45 1,-10 5,-26 8,-30 z M 487.15488,66.132209 c 121,21 194,115.000001 212,233.000001 l 0,8 25,1 1,18 -481,0 c -6,-13 -10,-27 -13,-41 -13,-94 38,-146 114,-193.000001 45,-23 93,-29 142,-26 z m -47,18 c -52,6 -98,28.000001 -138,62.000001 -28,25 -46,56 -51,87 -4,20 -1,57 5,70 l 423,1 c 2,-56 -39,-118 -74,-157 -31,-34 -72,-54.000001 -116,-63.000001 -11,-2 -38,-2 -49,0 z m 138,324.000001 c -5,6 -6,40 -2,58 3,16 4,16 10,10 14,-14 38,-14 52,0 15,18 12,41 -6,55 -3,3 -5,5 -5,6 1,4 22,8 34,7 42,-4 57.6,-40 66.2,-77 3,-17 1,-53 -4,-59 l -145.2,0 z m -331,-1 c -4,5 -5,34 -4,50 2,14 6,24 8,24 1,0 3,-2 6,-5 17,-17 47,-13 58,9 7,16 4,31 -8,43 -4,4 -7,8 -7,9 0,0 4,2 8,3 51,17 105,-20 115,-80 3,-15 0,-43 -3,-53 z m 61,-266 c 0,0 46,-40 105,-53.000001 66,-15 114,7 114,7 0,0 -14,76.000001 -93,95.000001 -76,18 -126,-49 -126,-49 z"""
    )
    smiley = parse_path(path_strings[0])
    smiley.vertices -= smiley.vertices.mean(axis=0)

    marker = smiley
    marker = marker.transformed(mpl.transforms.Affine2D().rotate_deg(180))

    markerface = ['y.', 'g.', 'b.']
    for i, item in enumerate(item_coords):
        clat, clon = zip(*[c for c in item_coords[item]])
        # markerface[i % len(colors)]
        ax.plot(clon, clat, '.', color=colors[i], markersize=10)

    # Plot all the nodes as black dots.
    clat, clon = zip(*[c for c in place_coords])
    ax.plot(clon,
            clat,
            'm.',
            color=colors[len(colors) - 1],
            marker=marker,
            markersize=10)
    # ax.plot(clon, clat, 'b.', markersize=20)

    # ax.plot(clon, clat, 'b.', markersize=20)
    # plot the routes as arrows

    ax.legend(["T", "C", "S", "M", "P"])

    if vehicle_routes is not None:
        plot_vehicle_routes(vehicle_routes, ax, place_coords, starts, ends,
                            True)

    xlim = ax.get_xlim()
    ylim = ax.get_ylim()
    # example of how to zoomout by a factor of 0.1
    factor = zoom_out
    new_xlim = (xlim[0] + xlim[1])/2 + np.array((-0.5, 0.5)) * \
        (xlim[1] - xlim[0]) * (1 + factor)
    ax.set_xlim(new_xlim)
    new_ylim = (ylim[0] + ylim[1])/2 + np.array((-0.5, 0.5)) * \
        (ylim[1] - ylim[0]) * (1 + factor)
    ax.set_ylim(new_ylim)

    plt.grid(zorder=0)
    graph.set_disp("DMS fill", "longitude", "latitude")

    plt.show()
    return fig
Exemplo n.º 22
0
from svgpath2mpl import parse_path

import matplotlib.pyplot as plt      
import numpy as np                   
# Use Inkscape to edit SVG, 
# Path -> Combine to convert multiple paths into a single path
# Use Path -> Object to path to convert objects to SVG path
smiley = parse_path("""m 739.01202,391.98936 c 13,26 13,57 9,85 -6,27 -18,52 -35,68 -21,20 -50,23 -77,18 -15,-4 -28,-12 -39,-23 -18,-17 -30,-40 -36,-67 -4,-20 -4,-41 0,-60 l 6,-21 z m -302,-1 c 2,3 6,20 7,29 5,28 1,57 -11,83 -15,30 -41,52 -72,60 -29,7 -57,0 -82,-15 -26,-17 -45,-49 -50,-82 -2,-12 -2,-33 0,-45 1,-10 5,-26 8,-30 z M 487.15488,66.132209 c 121,21 194,115.000001 212,233.000001 l 0,8 25,1 1,18 -481,0 c -6,-13 -10,-27 -13,-41 -13,-94 38,-146 114,-193.000001 45,-23 93,-29 142,-26 z m -47,18 c -52,6 -98,28.000001 -138,62.000001 -28,25 -46,56 -51,87 -4,20 -1,57 5,70 l 423,1 c 2,-56 -39,-118 -74,-157 -31,-34 -72,-54.000001 -116,-63.000001 -11,-2 -38,-2 -49,0 z m 138,324.000001 c -5,6 -6,40 -2,58 3,16 4,16 10,10 14,-14 38,-14 52,0 15,18 12,41 -6,55 -3,3 -5,5 -5,6 1,4 22,8 34,7 42,-4 57.6,-40 66.2,-77 3,-17 1,-53 -4,-59 l -145.2,0 z m -331,-1 c -4,5 -5,34 -4,50 2,14 6,24 8,24 1,0 3,-2 6,-5 17,-17 47,-13 58,9 7,16 4,31 -8,43 -4,4 -7,8 -7,9 0,0 4,2 8,3 51,17 105,-20 115,-80 3,-15 0,-43 -3,-53 z m 61,-266 c 0,0 46,-40 105,-53.000001 66,-15 114,7 114,7 0,0 -14,76.000001 -93,95.000001 -76,18 -126,-49 -126,-49 z""")
smiley.vertices -= smiley.vertices.mean(axis=0)
x = np.linspace(-3, 3, 20)          
plt.plot(x, np.sin(x), marker=smiley, markersize=20, color='c')
plt.show()


#%%
# -*- coding: utf-8 -*-
"""
Spyder Editor

This is a temporary script file.
"""

import numpy as np, os, re
import matplotlib.pyplot as plt

os.chdir('C:/corina/states')

xmin, xmax = -3, 3 
ymin, ymax = -3, 3 

Ef = [-3.77, -2.99]
Exemplo n.º 23
0
def plot_shell(date=dt.date(2017, 12, 31),
               pace_d=0.0,
               joe_d=0.0,
               holly_d=0.0,
               plot_file='output/jolly_miles_0.png'):
    """
    Plot a rowing shell by importing an svg and turning it into a matplotlib path.
    """

    with open('shell.svg', 'r') as svg_file:
        svg_tree = etree.parse(svg_file)

    svg_root = svg_tree.getroot()
    svg_width = int(svg_root.attrib['width'][:-2])
    svg_height = int(svg_root.attrib['height'][:-2])
    svg_aspect_ratio = svg_height / svg_width

    pace_boat = []
    for svg_elem in svg_tree.iter():
        if svg_elem.tag.split('}')[1] == 'path':
            pace_boat.append(parse_path(svg_elem.get('d')))

    holly_boat = pace_boat.copy()
    joe_boat = pace_boat.copy()

    boat_width = 250.0
    scale_factor = boat_width / svg_width
    boat_height = svg_height * scale_factor

    # Get course in miles
    plot_width = 1009.0 + boat_width * 2.0
    plot_height = svg_aspect_ratio * plot_width

    lane_height = plot_height / 3.0
    lane_padding = (lane_height - boat_height) / 2.0

    joe_y = lane_padding
    holly_y = lane_height + lane_padding
    pace_y = lane_height * 2.0 + lane_padding

    fig, ax = plt.subplots(1, 1, figsize=(15, 5))
    tf = ax.transData  # Note: the plot transform should be the last transform!

    ax.plot([0, 0], [0, plot_height], '-', color='seagreen', lw=5, zorder=1)
    ax.plot([1009, 1009], [0, plot_height],
            '-',
            color='darkslategrey',
            lw=5,
            zorder=1)

    lane_buoys_x = np.linspace(-boat_width, plot_width - boat_width, 37)
    lane_buoys_y = np.ones(lane_buoys_x.shape)

    ax.scatter(lane_buoys_x,
               lane_buoys_y * 0.0,
               25,
               marker='o',
               color='orange',
               zorder=2)
    ax.scatter(lane_buoys_x,
               lane_buoys_y * lane_height,
               25,
               marker='o',
               color='orange',
               zorder=2)
    ax.scatter(lane_buoys_x,
               lane_buoys_y * lane_height * 2.0,
               25,
               marker='o',
               color='orange',
               zorder=2)
    ax.scatter(lane_buoys_x,
               lane_buoys_y * lane_height * 3.0,
               25,
               marker='o',
               color='orange',
               zorder=2)

    for part in pace_boat:
        part_patch = patches.PathPatch(part,
                                       lw=2,
                                       color='darkslategrey',
                                       zorder=3)
        ti = transforms.Affine2D().scale(scale_factor)
        ti += transforms.Affine2D().translate(-boat_width + pace_d, pace_y)
        part_patch.set_transform(ti + tf)
        ax.add_patch(part_patch)

    for part in holly_boat:
        part_patch = patches.PathPatch(part, lw=2, color='darkcyan', zorder=3)
        ti = transforms.Affine2D().scale(scale_factor)
        ti += transforms.Affine2D().translate(-boat_width + holly_d, holly_y)
        part_patch.set_transform(ti + tf)
        ax.add_patch(part_patch)

    for part in joe_boat:
        part_patch = patches.PathPatch(part, lw=2, color='crimson', zorder=3)
        ti = transforms.Affine2D().scale(scale_factor)
        ti += transforms.Affine2D().translate(-boat_width + joe_d, joe_y)
        part_patch.set_transform(ti + tf)
        ax.add_patch(part_patch)

    ax.set_xlim(-boat_width, plot_width - boat_width)
    ax.set_ylim(-10, plot_height + 10)

    plot_x_ticks = np.append(np.arange(0, 1000, 50), 1009)
    ax.set_xticks(plot_x_ticks)
    ax.tick_params(axis='y', which='both', left='off', labelleft='off')

    ax.set_title(f'{(holly_d+joe_d):.1f} Jolly miles for 2018 so far')
    ax.set_title(f'{date}', loc='right')

    fig.tight_layout()
    plt.savefig(plot_file)
    plt.close()
Exemplo n.º 24
0
import pandas as pd
import mplcursors
import tkinter.messagebox as mb
import re
from tkinter import simpledialog
from scipy import spatial
import ast

# #

ng = pd.read_csv('NGC.csv', low_memory=False)
ms = pd.read_csv('messier_objects.csv', low_memory=False)
cb = pd.read_csv('constellation_borders.csv', low_memory=False)
ty = pd.read_csv('tycho-1.csv', low_memory=False)

ell = parse_path(
    """M 490.60742,303.18917 A 276.31408,119.52378 28.9 0 1 190.94051,274.29027 276.31408,119.52378 28.9 0 1 6.8010582,36.113705 276.31408,119.52378 28.9 0 1 306.46799,65.012613 276.31408,119.52378 28.9 0 1 490.60742,303.18917 Z""")
ell.vertices -= ell.vertices.mean(axis=0)

# #

mag = 6  # limiting the magnitude for Tycho-1 stars;
mag_ty = ty[(ty['V'] <= mag)]  # Tycho

dup_ng = ng.copy(deep=True)  # NGC
dup_ms = ms.copy(deep=True)  # Messier
dup_ty = mag_ty.copy(deep=True)  # Tycho
dup_cb = cb.copy(deep=True)  # Constellation borders
dup_ng['RAJ2000'] -= 360  # NGC transform
dup_ms['RAJ2000'] -= 360  # Messier transform
dup_ty['RAJ2000'] -= 360  # Tycho transform
dup_cb['RAJ2000'] -= 360  # Constellation borders transform
Exemplo n.º 25
0
    video_dir = os.path.join(result_dir, 'videos')

    # create dirs
    os.makedirs(result_dir, exist_ok=True)
    os.makedirs(train_dir, exist_ok=True)
    os.makedirs(test_dir, exist_ok=True)
    os.makedirs(video_dir, exist_ok=True)

    return result_dir, train_dir, test_dir, video_dir


# custom symbols for rendering based on SVG paths
# base station icon from noun project: https://thenounproject.com/search/?q=base+station&i=1286474
station_path = "M31.5,19c0-4.1-3.4-7.5-7.5-7.5s-7.5,3.4-7.5,7.5c0,2.9,1.6,5.4,4,6.7l0.9-1.8c-1.7-0.9-2.9-2.8-2.9-4.9 " \
               "c0-3,2.5-5.5,5.5-5.5s5.5,2.5,5.5,5.5c0,2.1-1.2,3.9-2.9,4.9l0.9,1.8C29.9,24.4,31.5,21.9,31.5,19z " \
               "M37,19c0-7.2-5.8-13-13-13s-13,5.8-13,13c0,5.1,2.9,9.4,7.1,11.6l0.9-1.8c-3.6-1.8-6-5.5-6-9.8   " \
               "c0-6.1,4.9-11,11-11s11,4.9,11,11c0,4.3-2.5,8-6,9.8l0.9,1.8C34.1,28.4,37,24.1,37,19z " \
               "M42,19c0-9.9-8.1-18-18-18S6,9.1,6,19c0,7,4.1,13.1,10,16.1l0.9-1.8C11.6,30.7,8,25.2,8,19   " \
               "c0-8.8,7.2-16,16-16s16,7.2,16,16c0,6.2-3.6,11.7-8.8,14.3l0.9,1.8C37.9,32.1,42,26,42,19z " \
               "M24,22c-1.7,0-3-1.3-3-3s1.3-3,3-3s3,1.3,3,3S25.7,22,24,22z M24,18c-0.6,0-1,0.4-1,1s0.4,1,1,1     " \
               "s1-0.4,1-1S24.6,18,24,18z " \
               "M34.2,44.1L24,23.1l-10.2,21c-0.3,0.6-0.3,1.3,0.1,1.9c0.4,0.6,1,0.9,1.7,0.9h16.8c0.7,0,1.3-0.4,1.7-0.9 "\
               "C34.5,45.5,34.5,44.7,34.2,44.1z M25,29.8l2.2,4.4L25,36V29.8z M23,36l-2.2-1.8l2.2-4.4V36z " \
               "M22.5,38.2l-6,5.1l3.5-7.3L22.5,38.2z " \
               "M23,40.4V45h-5.5L23,40.4z M25,40.3l5.5,4.7H25V40.3z M25.6,38.2l2.5-2.1l3.5,7.2L25.6,38.2z"
station_symbol = svgpath2mpl.parse_path(station_path)
station_symbol.vertices -= station_symbol.vertices.mean(axis=0)
# rotate (otherwise up side down): https://stackoverflow.com/a/48231144/2745116
station_symbol = station_symbol.transformed(
    matplotlib.transforms.Affine2D().rotate_deg(180))
Exemplo n.º 26
0
    def char(self, ch):
        def tuple_to_imag(t):
            return t[0] + t[1] * 1j

        #face = Face('/usr/share/fonts/truetype/dejavu/DejaVuSerif.ttf')
        face = Face(ddd.DATA_DIR + '/fonts/OpenSansEmoji.ttf')
        face.set_char_size(self.char_size)
        face.load_char(ch)

        #kerning = face.get_kerning(ch, 'x')  # or from previous, actually?
        #print(kerning)

        outline = face.glyph.outline
        y = [t[1] for t in outline.points]
        # flip the points
        outline_points = [(p[0], max(y) - p[1]) for p in outline.points]

        start, end = 0, 0
        paths = []

        for i in range(len(outline.contours)):
            end = outline.contours[i]
            points = outline_points[start:end + 1]
            points.append(points[0])
            tags = outline.tags[start:end + 1]
            tags.append(tags[0])

            segments = [
                [
                    points[0],
                ],
            ]
            for j in range(1, len(points)):
                segments[-1].append(points[j])
                if tags[j] and j < (len(points) - 1):
                    segments.append([
                        points[j],
                    ])

            for segment in segments:
                if len(segment) == 2:
                    paths.append(
                        Line(start=tuple_to_imag(segment[0]),
                             end=tuple_to_imag(segment[1])))
                elif len(segment) == 3:
                    paths.append(
                        QuadraticBezier(start=tuple_to_imag(segment[0]),
                                        control=tuple_to_imag(segment[1]),
                                        end=tuple_to_imag(segment[2])))
                elif len(segment) == 4:
                    paths.append(
                        CubicBezier(start=tuple_to_imag(segment[0]),
                                    control1=tuple_to_imag(segment[1]),
                                    control2=tuple_to_imag(segment[2]),
                                    end=tuple_to_imag(segment[3])))
                    #C = ((segment[1][0] + segment[2][0]) / 2.0,
                    #     (segment[1][1] + segment[2][1]) / 2.0)
                    #paths.append(QuadraticBezier(start=tuple_to_imag(segment[0]),
                    #                             control=tuple_to_imag(segment[1]),
                    #                             end=tuple_to_imag(C)))
                    #paths.append(QuadraticBezier(start=tuple_to_imag(C),
                    #                             control=tuple_to_imag(segment[2]),
                    #                             end=tuple_to_imag(segment[3])))

            start = end + 1

        path = Path(*paths)
        #wsvg(path, filename="/tmp/test.svg")
        path_d = path.d()

        # https://gis.stackexchange.com/questions/301605/how-to-create-shape-in-shapely-from-an-svg-path-element
        # This page also has info about SVG reading!

        #svgpath = 'M10 10 C 20 20, 40 20, 50 10Z'
        mpl_path = parse_path(path_d)

        coords = mpl_path.to_polygons(closed_only=True)

        item = None
        for c in coords:  # coords[1:]:
            if len(c) < 3: continue
            ng = ddd.polygon(c)  #.clean(eps=char_size / 100)  #.convex_hull()
            #ng.show()
            if item is None:
                item = ng
            elif item.contains(ng):
                item = item.subtract(ng)
            else:
                item = item.union(ng)
            item = item.clean(
                eps=self.char_size /
                200)  # Note that this is effectively limiting resolution

        #result = ddd.group([ddd.polygon(c) for c in coords], empty=2)
        result = item
        result = result.scale([1.0 / self.char_size, -1.0 / self.char_size])
        result = result.simplify(
            0.005)  # Note that this is effectively limiting resolution

        return (result, face)
Exemplo n.º 27
0
def path_to_polygon(path):
    return Polygon(parse_path(path).to_polygons()[0])