# Support code for 6.009 Lecture 2 # NOT intended to be understandable by students at this point! # Write a string of SVG code into /tmp/test.html. def render(code): f = open("/tmp/test.html", "w") f.write("") f.write(code) f.write("") f.close() # Now do it for several images, to turn into an animation. def render_animation(codes): f = open("/tmp/test.html", "w") f.write("\n"); f.write("\n"); f.write(""); for i in range(len(codes)): f.write("") f.write("") f.close() ## The following methods generate SVG code as strings. # Draw a line segment from (x1, y1) to (x2, y2). def line(x1, y1, x2, y2): return "" # Draw a curve interpolated between three points. def curve(x1, y1, x2, y2, x3, y3): return "" # Draw a circle centered at point (x, y) with a given radius. def circle(x, y, radius): return "" # Draw text at a position. def text(text, x, y): return "" + text + "" # Concatenate a sequence of SVG fragments in order. def group(frags): return "\n".join(list(frags)) # Show a fragment at a particular position. def translate(frag, x=0, y=0): return "" + frag + "" # Scale the size of a fragment. def scale(frag, by): return "" + frag + "" # Set line and fill properties. def brush(frag, stroke=None, fill=None, stroke_width=None): attrs = "" if stroke: attrs += " stroke='" + stroke + "'" if fill: attrs += " fill='" + fill + "'" if stroke_width: attrs += " stroke-width='" + str(stroke_width) + "'" return "" + frag + ""