Esempio n. 1
0
    def to_asy(self):
        # l = self.style.get_line_width(face_element=False)
        pen = create_pens(edge_color=self.edge_color, stroke_width=1)

        return ''.join('draw({0}, {1});'.format(
            '--'.join('({0},{1},{2})'.format(*coords.pos()[0])
                      for coords in line), pen) for line in self.lines)
Esempio n. 2
0
    def to_asy(self):
        # l = self.style.get_line_width(face_element=False)
        pen = create_pens(edge_color=self.edge_color, stroke_width=1)

        return ''.join('draw({0}, {1});'.format(
            '--'.join('({0},{1},{2})'.format(*coords.pos()[0])
                      for coords in line), pen) for line in self.lines)
Esempio n. 3
0
 def to_asy(self):
     #l = self.style.get_line_width(face_element=False)
     pen = create_pens(edge_color=self.edge_color, stroke_width=1)
     asy = ''
     for line in self.lines:
         path = '--'.join(['(%s,%s,%s)' % coords.pos()[0] for coords in line])
         asy += 'draw(%s, %s);' % (path, pen)
     return asy
Esempio n. 4
0
    def to_asy(self):
        face_color = self.face_color

        # Tempoary bug fix: default Point color should be black not white
        if list(face_color.to_rgba()[:3]) == [1, 1, 1]:
            face_color = RGBColor(
                components=(0, 0, 0, face_color.to_rgba()[3]))

        pen = create_pens(face_color=face_color, is_face_element=False)

        return ''.join('path3 g={0}--cycle;dot(g, {1});'.format(
            '--'.join('({0},{1},{2})'.format(*coords.pos()[0])
                      for coords in line), pen) for line in self.lines)
Esempio n. 5
0
    def to_asy(self):
        face_color = self.face_color

        # Tempoary bug fix: default Point color should be black not white
        if list(face_color.to_rgba()[:3]) == [1, 1, 1]:
            face_color = RGBColor(components=(0, 0, 0,
                                              face_color.to_rgba()[3]))

        pen = create_pens(face_color=face_color, is_face_element=False)

        return ''.join('path3 g={0}--cycle;dot(g, {1});'.format(
            '--'.join('({0},{1},{2})'.format(*coords.pos()[0])
                      for coords in line), pen) for line in self.lines)
Esempio n. 6
0
    def to_asy(self):
        l = self.style.get_line_width(face_element=True)
        if self.vertex_colors is None:
            face_color = self.face_color
        else:
            face_color = None
        pen = create_pens(edge_color=self.edge_color, face_color=face_color, stroke_width=l, is_face_element=True)

        asy = ''
        for line in self.lines:
            asy += 'path3 g=' + '--'.join(['(%s,%s,%s)' % coords.pos()[0] for coords in line]) + '--cycle;'
            asy += 'draw(surface(g), %s);' % (pen)
        return asy
Esempio n. 7
0
    def to_asy(self):
        face_color = self.face_color
        
        # Tempoary bug fix: default Point color should be black not white
        if list(face_color.to_rgba()[:3]) == [1,1,1]:
            face_color = RGBColor(components=(0,0,0,face_color.to_rgba()[3]))
        pen = create_pens(face_color=face_color, is_face_element=False)

        asy = ''
        for line in self.lines:
            asy += 'path3 g=' + '--'.join(['(%s,%s,%s)' % coords.pos()[0] for coords in line]) + '--cycle;'
            asy += 'dot(g, %s);' % (pen)
        return asy
Esempio n. 8
0
    def boxes_to_tex(self, leaves, **options):
        elements, axes, ticks, calc_dimensions, boxscale = \
            self._prepare_elements(leaves, options, max_width=450)

        elements._apply_boxscaling(boxscale)

        asy = elements.to_asy()

        xmin, xmax, ymin, ymax, zmin, zmax, boxscale = calc_dimensions()

        # TODO: Intelligently place the axes on the longest non-middle edge.
        # See algorithm used by web graphics in mathics/web/media/graphics.js
        # for details of this. (Projection to sceen etc).

        # Choose axes placement (boundbox edge vertices)
        axes_indices = []
        if axes[0]:
            axes_indices.append(0)
        if axes[1]:
            axes_indices.append(6)
        if axes[2]:
            axes_indices.append(8)

        # Draw boundbox and axes
        boundbox_asy = ''
        boundbox_lines = self.get_boundbox_lines(
            xmin, xmax, ymin, ymax, zmin, zmax)

        for i, line in enumerate(boundbox_lines):
            if i in axes_indices:
                pen = create_pens(edge_color=RGBColor(
                    components=(0, 0, 0, 1)), stroke_width=1.5)
            else:
                pen = create_pens(edge_color=RGBColor(
                    components=(0.4, 0.4, 0.4, 1)), stroke_width=1)

            path = '--'.join(['(%s,%s,%s)' % coords for coords in line])
            boundbox_asy += 'draw((%s), %s);\n' % (path, pen)

        # TODO: Intelligently draw the axis ticks such that they are always
        # directed inward and choose the coordinate direction which makes the
        # ticks the longest. Again, details in mathics/web/media/graphics.js

        # Draw axes ticks
        ticklength = 0.05 * max([xmax - xmin, ymax - ymin, zmax - zmin])
        pen = create_pens(edge_color=RGBColor(
            components=(0, 0, 0, 1)), stroke_width=1.2)
        for xi in axes_indices:
            if xi < 4:          # x axis
                for i, tick in enumerate(ticks[0][0]):
                    line = [
                        (tick, boundbox_lines[xi][0][1],
                         boundbox_lines[xi][0][2]),
                        (tick, boundbox_lines[xi][0][1],
                         boundbox_lines[xi][0][2] + ticklength)]

                    path = '--'.join(
                        ['({0},{1},{2})'.format(*coords) for coords in line])

                    boundbox_asy += 'draw(({0}), {1});\n'.format(path, pen)
                    boundbox_asy += 'label("{0}",{1},{2});\n'.format(
                        ticks[0][2][i], (tick, boundbox_lines[xi][0][1],
                                         boundbox_lines[xi][0][2]),
                        'S')

                for small_tick in ticks[0][1]:
                    line = [
                        (small_tick, boundbox_lines[xi][0][1],
                         boundbox_lines[xi][0][2]),
                        (small_tick, boundbox_lines[xi][0][1],
                         boundbox_lines[xi][0][2] + 0.5 * ticklength)]

                    path = '--'.join(
                        ['({0},{1},{2})'.format(*coords) for coords in line])

                    boundbox_asy += 'draw(({0}), {1});\n'.format(path, pen)

            if 4 <= xi < 8:     # y axis
                for i, tick in enumerate(ticks[1][0]):
                    line = [
                        (boundbox_lines[xi][0][0], tick,
                         boundbox_lines[xi][0][2]),
                        (boundbox_lines[xi][0][0], tick,
                         boundbox_lines[xi][0][2] - ticklength)]
                    path = '--'.join(
                        ['({0},{1},{2})'.format(*coords) for coords in line])

                    boundbox_asy += 'draw(({0}), {1});\n'.format(path, pen)

                    boundbox_asy += 'label("{0}",{1},{2});\n'.format(
                        ticks[1][2][i], (boundbox_lines[xi][0][0], tick,
                                         boundbox_lines[xi][0][2]),
                        'NW')

                for small_tick in ticks[1][1]:
                    line = [
                        (boundbox_lines[xi][0][0], small_tick,
                         boundbox_lines[xi][0][2]),
                        (boundbox_lines[xi][0][0], small_tick,
                         boundbox_lines[xi][0][2] - 0.5 * ticklength)]
                    path = '--'.join(
                        ['({0},{1},{2})'.format(*coords) for coords in line])
                    boundbox_asy += 'draw(({0}), {1});\n'.format(path, pen)
            if 8 <= xi:         # z axis
                for i, tick in enumerate(ticks[2][0]):
                    line = [
                        (boundbox_lines[xi][0][0], boundbox_lines[xi][0][1],
                         tick),
                        (boundbox_lines[xi][0][0],
                         boundbox_lines[xi][0][1] + ticklength, tick)]
                    path = '--'.join(
                        ['({0},{1},{2})'.format(*coords) for coords in line])
                    boundbox_asy += 'draw(({0}), {1});\n'.format(path, pen)
                    boundbox_asy += 'label("{0}",{1},{2});\n'.format(
                        ticks[2][2][i],
                        (boundbox_lines[xi][0][0], boundbox_lines[xi][0][1],
                         tick),
                        'W')
                for small_tick in ticks[2][1]:
                    line = [
                        (boundbox_lines[xi][0][0],
                         boundbox_lines[xi][0][1],
                         small_tick),
                        (boundbox_lines[xi][0][0],
                         boundbox_lines[xi][0][1] + 0.5 * ticklength,
                         small_tick)
                    ]
                    path = '--'.join(
                        ['({0},{1},{2})'.format(*coords) for coords in line])
                    boundbox_asy += 'draw(({0}), {1});\n'.format(path, pen)

        (height, width) = (400, 400)  # TODO: Proper size
        tex = r"""
\begin{{asy}}
import three;
import solids;
size({0}cm, {1}cm);
currentprojection=perspective({2[0]},{2[1]},{2[2]});
currentlight=light(rgb(0.5,0.5,1), specular=red, (2,0,2), (2,2,2), (0,2,2));
{3}
{4}
\end{{asy}}
""".format(asy_number(width / 60), asy_number(height / 60), self.viewpoint,
           asy, boundbox_asy)
        return tex
Esempio n. 9
0
    def boxes_to_tex(self, leaves, **options):
        elements, axes, ticks, calc_dimensions, boxscale = \
            self._prepare_elements(leaves, options, max_width=450)

        elements._apply_boxscaling(boxscale)

        asy = elements.to_asy()

        xmin, xmax, ymin, ymax, zmin, zmax, boxscale = calc_dimensions()

        # TODO: Intelligently place the axes on the longest non-middle edge.
        # See algorithm used by web graphics in mathics/web/media/graphics.js
        # for details of this. (Projection to sceen etc).

        # Choose axes placement (boundbox edge vertices)
        axes_indices = []
        if axes[0]:
            axes_indices.append(0)
        if axes[1]:
            axes_indices.append(6)
        if axes[2]:
            axes_indices.append(8)

        # Draw boundbox and axes
        boundbox_asy = ''
        boundbox_lines = self.get_boundbox_lines(xmin, xmax, ymin, ymax, zmin,
                                                 zmax)

        for i, line in enumerate(boundbox_lines):
            if i in axes_indices:
                pen = create_pens(edge_color=RGBColor(components=(0, 0, 0, 1)),
                                  stroke_width=1.5)
            else:
                pen = create_pens(edge_color=RGBColor(components=(0.4, 0.4,
                                                                  0.4, 1)),
                                  stroke_width=1)

            path = '--'.join(['(%s,%s,%s)' % coords for coords in line])
            boundbox_asy += 'draw((%s), %s);\n' % (path, pen)

        # TODO: Intelligently draw the axis ticks such that they are always
        # directed inward and choose the coordinate direction which makes the
        # ticks the longest. Again, details in mathics/web/media/graphics.js

        # Draw axes ticks
        ticklength = 0.05 * max([xmax - xmin, ymax - ymin, zmax - zmin])
        pen = create_pens(edge_color=RGBColor(components=(0, 0, 0, 1)),
                          stroke_width=1.2)
        for xi in axes_indices:
            if xi < 4:  # x axis
                for i, tick in enumerate(ticks[0][0]):
                    line = [(tick, boundbox_lines[xi][0][1],
                             boundbox_lines[xi][0][2]),
                            (tick, boundbox_lines[xi][0][1],
                             boundbox_lines[xi][0][2] + ticklength)]

                    path = '--'.join(
                        ['({0},{1},{2})'.format(*coords) for coords in line])

                    boundbox_asy += 'draw(({0}), {1});\n'.format(path, pen)
                    boundbox_asy += 'label("{0}",{1},{2});\n'.format(
                        ticks[0][2][i], (tick, boundbox_lines[xi][0][1],
                                         boundbox_lines[xi][0][2]), 'S')

                for small_tick in ticks[0][1]:
                    line = [(small_tick, boundbox_lines[xi][0][1],
                             boundbox_lines[xi][0][2]),
                            (small_tick, boundbox_lines[xi][0][1],
                             boundbox_lines[xi][0][2] + 0.5 * ticklength)]

                    path = '--'.join(
                        ['({0},{1},{2})'.format(*coords) for coords in line])

                    boundbox_asy += 'draw(({0}), {1});\n'.format(path, pen)

            if 4 <= xi < 8:  # y axis
                for i, tick in enumerate(ticks[1][0]):
                    line = [(boundbox_lines[xi][0][0], tick,
                             boundbox_lines[xi][0][2]),
                            (boundbox_lines[xi][0][0], tick,
                             boundbox_lines[xi][0][2] - ticklength)]
                    path = '--'.join(
                        ['({0},{1},{2})'.format(*coords) for coords in line])

                    boundbox_asy += 'draw(({0}), {1});\n'.format(path, pen)

                    boundbox_asy += 'label("{0}",{1},{2});\n'.format(
                        ticks[1][2][i], (boundbox_lines[xi][0][0], tick,
                                         boundbox_lines[xi][0][2]), 'NW')

                for small_tick in ticks[1][1]:
                    line = [(boundbox_lines[xi][0][0], small_tick,
                             boundbox_lines[xi][0][2]),
                            (boundbox_lines[xi][0][0], small_tick,
                             boundbox_lines[xi][0][2] - 0.5 * ticklength)]
                    path = '--'.join(
                        ['({0},{1},{2})'.format(*coords) for coords in line])
                    boundbox_asy += 'draw(({0}), {1});\n'.format(path, pen)
            if 8 <= xi:  # z axis
                for i, tick in enumerate(ticks[2][0]):
                    line = [(boundbox_lines[xi][0][0],
                             boundbox_lines[xi][0][1], tick),
                            (boundbox_lines[xi][0][0],
                             boundbox_lines[xi][0][1] + ticklength, tick)]
                    path = '--'.join(
                        ['({0},{1},{2})'.format(*coords) for coords in line])
                    boundbox_asy += 'draw(({0}), {1});\n'.format(path, pen)
                    boundbox_asy += 'label("{0}",{1},{2});\n'.format(
                        ticks[2][2][i], (boundbox_lines[xi][0][0],
                                         boundbox_lines[xi][0][1], tick), 'W')
                for small_tick in ticks[2][1]:
                    line = [(boundbox_lines[xi][0][0],
                             boundbox_lines[xi][0][1], small_tick),
                            (boundbox_lines[xi][0][0],
                             boundbox_lines[xi][0][1] + 0.5 * ticklength,
                             small_tick)]
                    path = '--'.join(
                        ['({0},{1},{2})'.format(*coords) for coords in line])
                    boundbox_asy += 'draw(({0}), {1});\n'.format(path, pen)

        (height, width) = (400, 400)  # TODO: Proper size
        tex = r"""
\begin{{asy}}
import three;
import solids;
size({0}cm, {1}cm);
currentprojection=perspective({2[0]},{2[1]},{2[2]});
currentlight=light(rgb(0.5,0.5,1), specular=red, (2,0,2), (2,2,2), (0,2,2));
{3}
{4}
\end{{asy}}
""".format(asy_number(width / 60), asy_number(height / 60), self.viewpoint,
           asy, boundbox_asy)
        return tex