예제 #1
0
파일: json.py 프로젝트: skirpichev/Mathics

def graphics_3D_elements(self, **options) -> list:
    """Iterates over self.elements to convert each item.
    The list of converted items is returned.
    """
    result = []
    for element in self.elements:
        format_fn = lookup_method(element, "json")
        result += format_fn(element)

    # print("### json Graphics3DElements", result)
    return result


add_conversion_fn(Graphics3DElements, graphics_3D_elements)


def arrow_3d_box(self):
    """
    Compact (lower-level) JSON formatting of a Arrow3DBox.
    """
    # TODO: account for arrow widths and style
    color = self.edge_color.to_rgba()
    data = convert_coord_collection(self.lines, "arrow", color)
    # print("### json Arrow3DBox", data)
    return data


add_conversion_fn(Arrow3DBox, arrow_3d_box)
예제 #2
0
            yield "--cycle"

    l = self.style.get_line_width(face_element=self.face_element)
    pen = asy_create_pens(
        edge_color=self.edge_color,
        face_color=self.face_color,
        stroke_width=l,
        is_face_element=self.face_element,
    )
    command = "filldraw" if self.face_element else "draw"
    asy = "%s(%s, %s);" % (command, "".join(path(self.face_element)), pen)
    # print("### arcbox", asy)
    return asy


add_conversion_fn(_ArcBox, arcbox)


def arrow_box(self, **options) -> str:
    width = self.style.get_line_width(face_element=False)
    pen = asy_create_pens(edge_color=self.edge_color, stroke_width=width)
    polyline = self.curve.make_draw_asy(pen)

    arrow_pen = asy_create_pens(face_color=self.edge_color, stroke_width=width)

    def polygon(points):
        yield "filldraw("
        yield "--".join(["(%.5g,%5g)" % xy for xy in points])
        yield "--cycle, % s);" % arrow_pen

    extent = self.graphics.view_width or 0
예제 #3
0

def graphics_3D_elements(self, **options):
    result = []
    for element in self.elements:
        format_fn = lookup_method(element, "json")
        if format_fn is None:
            result += element.to_json()
        else:
            result += format_fn(element)

    # print("### json Graphics3DElements", result)
    return result


add_conversion_fn(Graphics3DElements, graphics_3D_elements)


def cylinder_3d_box(self):
    face_color = self.face_color
    if face_color is not None:
        face_color = face_color.to_js()
    return [{
        "type": "cylinder",
        "coords": [coords.pos() for coords in self.points],
        "radius": self.radius,
        "faceColor": face_color,
    }]


add_conversion_fn(Cylinder3DBox, cylinder_3d_box)