Exemplo n.º 1
0
 def __init__(self, horizontal_n, vertical_m, function, value, segment_endpoints=None):
     n = self.n = horizontal_n
     m = self.m = vertical_m
     D = self.D = cartesian_svg.doodle(0, 0, m, n)
     D.rect(None, 0, 0, n, m, "cornsilk")
     D.show()
     G = self.G = triangulated.Grid2DContour(n, m, function, value, segment_endpoints, self.callback)
     self.contours = G.get_contour_sequences()
 def display_spot_canvas(self, width=None, height=None):
     (minx, miny) = self.mins
     (maxx, maxy) = self.maxes
     if width is not None and height is not None:
         maxx = minx + width
         maxy = miny + height
     result = cartesian_svg.doodle(minx, miny, maxx, maxy, margin=0)
     result.buffered = True
     #add_image(result.target, self.image_href)
     return result
Exemplo n.º 3
0
 def __init__(self, xmin, ymin, xmax, ymax, dx, dy, function, value, segment_endpoints=None):
     self.driver = triangulated.DxDy2DContour(xmin, ymin, xmax, ymax, dx, dy, function, value, segment_endpoints)
     self.contours = self.driver.get_contour_sequences()
     D = self.D = cartesian_svg.doodle(xmin, ymin, xmax, ymax)
     D.show()
     radius = (xmax - xmin) * 0.1
     for (closed, points) in self.contours:
         previous = None
         if closed:
             previous = points[-1]
         for current in points:
             if previous is not None:
                 (x0, y0) = current
                 (x1, y1) = previous
                 D.line(None, x0, y0, x1, y1)
             previous = current
Exemplo n.º 4
0
 def get_drawing(self):
     drawing = self.drawing
     if drawing is None:
         (mx, my) = self.mins
         (sx, sy) = self.maxes - self.mins
         self.point_radius = 1.0
         if sx > 0:
             self.point_radius = sx * 0.03
         margin = max(sx * 0.1, sy * 0.1, 1.0)
         margin2 = 2 * margin
         drawing = cartesian_svg.doodle(mx - margin,
                                        my - margin,
                                        sx + margin2,
                                        sy + margin2,
                                        html_width=500)
         self.drawing = drawing
         drawing.show()
     return drawing
Exemplo n.º 5
0
 def __init__(self, xmin, ymin, xmax, ymax, dx, dy, function):
     self.driver = self.get_driver(xmin, ymin, xmax, ymax, dx, dy, function)
     self.dictionary = self.driver.get_contours_dictionary()
     D = self.D = cartesian_svg.doodle(xmin, ymin, xmax, ymax)
     D.show()
     #for ((x0, y0), (x1, y1)) in segment_endpoints:
     #    D.line(None, x0, y0, x1, y1)
     for (value, color) in zip(self.driver.values, self.colors):
         contours = self.dictionary[value]
         for (closed, points) in contours:
             previous = None
             if closed:
                 previous = points[-1]
             for current in points:
                 if previous is not None:
                     (x0, y0) = current
                     (x1, y1) = previous
                     D.line(None, x0, y0, x1, y1, color)
                 previous = current
Exemplo n.º 6
0
 def __init__(self, *pargs, **kwargs):
     self.drawing = True
     self.last_draw_time = 0
     self.draw_lock = threading.Lock()
     super(Locations, self).__init__(*pargs, **kwargs)
     self.diagram = D = cartesian_svg.doodle(-3, -6, 6, 2, html_width=700)
     self.moving = None
     a_slider = widgets.FloatSlider(value=3.0, min=0.2, max=10.0, step=0.2,
         width="150px", description="Kim/Bob")
     b_slider = widgets.FloatSlider(value=4.0, min=0.2, max=10.0, step=0.2,
         width="150px", description="Jack/Janet")
     traitlets.directional_link((a_slider, "value"), (self, "a"))
     traitlets.directional_link((b_slider, "value"), (self, "b"))
     self.on_trait_change(self.redraw, "a")
     self.on_trait_change(self.redraw, "b")
     assembly = widgets.VBox(children = [a_slider, b_slider, D.target])
     display(assembly)
     #D.show()
     D.enable_events("click mousemove", self.event_callback)
     self.redraw()
Exemplo n.º 7
0
def visual_test():
    from jp_svg_canvas import canvas, cartesian_svg
    import time
    mins = (minx, miny) = (-2, -5)
    maxes = (maxx, maxy) = (8, 5)
    C = cartesian_svg.doodle(minx, miny, maxx, maxy)
    C.show()
    attractor_weight = [((0, 3), 0.2), ((5, 0), 0.1)]
    delta = 0.5
    W = Walker(mins, maxes, delta, attractor_weight)
    for ((x, y), r) in attractor_weight:
        C.circle(None, x, y, r, "pink")
    C.flush()
    C.axes()
    last = None
    for i in range(1000):
        next = (x, y) = W.next()
        if last is not None:
            C.line(None, x, y, last[0], last[1], "magenta")
        C.circle(None, x, y, 0.05, "red")
        last = next
        C.flush()
Exemplo n.º 8
0
 def __init__(self, xmin, ymin, xmax, ymax, dx, dy, function, valueToColor, segment_endpoints=()):
     values = valueToColor.keys()
     self.driver = multiple_2d_contour.Multiple2DContour(
         xmin, ymin, xmax, ymax, dx, dy, function, values, segment_endpoints
     )
     self.dictionary = self.driver.get_contours_dictionary()
     D = self.D = cartesian_svg.doodle(xmin, ymin, xmax, ymax)
     D.show()
     for ((x0, y0), (x1, y1)) in segment_endpoints:
         D.line(None, x0, y0, x1, y1)
     for value in valueToColor:
         color = valueToColor[value]
         contours = self.dictionary[value]
         for (closed, points) in contours:
             previous = None
             if closed:
                 previous = points[-1]
             for current in points:
                 if previous is not None:
                     (x0, y0) = current
                     (x1, y1) = previous
                     D.line(None, x0, y0, x1, y1, color)
                 previous = current
def canvas_doodle(xmin, ymin, xmax, ymax, html_width=500, html_height=None, margin=50):
    canvas = proxy_html5_canvas.HTML5CanvasProxy()
    result = cartesian_svg.doodle(xmin, ymin, xmax, ymax, html_width, html_height, margin, svg=canvas)
    result.buffered = True
    return result