Ask Your Question

Luther13's profile - activity

2018-04-08 22:09:45 -0600 commented answer Graphics not plotted in same plot?

Thanks! Very insightful. I hope to become proficient in Sage, soon. I'll have to spend time going through lots of documentation, since I didn't even know about polygons! I appreciate the advice, especially the perspective about splitting up tasks. I imagine then that graphic_arrays aren't terribly useful?

2018-04-08 22:06:25 -0600 received badge  Supporter (source)
2018-04-08 20:21:10 -0600 received badge  Editor (source)
2018-04-08 20:11:12 -0600 received badge  Student (source)
2018-04-08 20:10:42 -0600 asked a question Graphics not plotted in same plot?

I'm trying to make a sierpinsky triangle recursively, and i can generate all the triangles (via 3 line segments), however when i go to show my list, the graphics print separately. I saw on the documentation there's a graphics_array, which seems useful, but there weren't many examples and my tinkering with it was pretty much useless, especially since the "adjoin" feature is not yet implemented.

Also tried passing the graphics object "some_lines" to get filled by the function, but it doesn't seem like it accesses the reference. Code attached, maybe you can see a way I can plot all the lines within one sum of graphics, as was my initial attempt:

def draw_tri(some_lines, endpts):
    some_lines+=line([endpts[0], endpts[1]], color='blue')
    some_lines+=line([endpts[0], endpts[2]], color='blue')
    some_lines+=line([endpts[1], endpts[2]], color='blue')
    return

def get_mid(x,y):
    return (x+y)/2

def recurse_SG(some_lines, n, endpts):
    #graphics_sum = graphics_array([line([endpts[0], endpts[1]], color='blue')],3, 1)
    if(n==1):
        #graphics_sum[i]=draw_tri(endpts)
        draw_tri(some_lines, endpts)
    else:
        recurse_SG(some_lines, n-1, [endpts[0], (get_mid(endpts[0][0], endpts[1][0]), get_mid(endpts[0][1], endpts[1][1])), (get_mid(endpts[0][0], endpts[2][0]), get_mid(endpts[0][1], endpts[2][1]))])
        recurse_SG(some_lines, n-1, [endpts[1], (get_mid(endpts[1][0], endpts[0][0]), get_mid(endpts[1][1], endpts[0][1])), (get_mid(endpts[1][0], endpts[2][0]), get_mid(endpts[1][1], endpts[2][1]))])
        recurse_SG(some_lines, n-1, [endpts[2], (get_mid(endpts[2][0], endpts[0][0]), get_mid(endpts[2][1], endpts[0][1])), (get_mid(endpts[2][0], endpts[1][0]), get_mid(endpts[2][1], endpts[1][1]))])

    show(some_lines, axes=false)