def sampleWriter(pathPrefix, x, y): plotter = svgPlot(x, y) def sample(fh, order, x0, y0): plotter.plotStart(fh) dragonCurve(plotter, order, x0, y0) plotter.plotEnd() def writer(order, x0, y0): with open("{0}{1}.svg".format(pathPrefix, order), "w") as fh: sample(fh, order, x0, y0) return writer
def sampleWriter(pathPrefix, n, offset): plotter = svgPlot(n + offset, n + offset) def sample(fh, order): plotter.plotStart(fh) sierpinski(plotter, order, n) plotter.plotEnd(True) def writer(order): with open("{0}{1}.svg".format(pathPrefix, order), "w") as fh: sample(fh, order) return writer
def sampleWriter(pathPrefix): plotter = svgPlot(400, 350) def sample(fh, order): plotter.plotStart(fh) plotter.move(200, 0) treecurve(plotter, order, 100, 0, 0.7, 0.5) plotter.plotEnd() def writer(order): with open("{0}{1}.svg".format(pathPrefix, order), "w") as fh: sample(fh, order) return writer
def sampleWriter(path): plotter = svgPlot(1200, 360) def sample(fh): plotter.plotStart(fh) plotter.move(0, 0) koch(plotter, 1200, 0, 3) plotter.plotEnd() def writer(): with open(path, "w") as fh: sample(fh) return writer
def sampleFunction(x, z): t = x * x + z * z return exp(-t) * cos(10 * sqrt(t)) def sampleWriter(path, plotter, parameters): with open(path, "w") as fh: plotter.plotStart(fh) tdGraph(plotter, sampleFunction, parameters) plotter.plotEnd() # m, n, t, u = 200, 20, 30, 5 plotter = svgPlot(m * 2 + n * 4, m + n * 3) parameters = parametersTDGraph(m, n, t, u, -1, -1, -1, 1, 1, 1) sampleWriter("results/3dgraphA-py.svg", plotter, parameters) m, n, t, u = 300, 50, 30, 5 plotter = svgPlot(m * 2 + n * 4, m + n * 5) parameters = parametersTDGraph(m, n, t, u, -1.8, -1.8, -1.8, 1.8, 1.8, 1.8) sampleWriter("results/3dgraphB-py.svg", plotter, parameters) m, n, t, u = 300, 50, 30, 2 plotter = svgPlot(m * 2 + n * 4, m - n * 1)
# # from src/lorenz.c # # a part of main to lorenzAttractor # from svgplot import svgPlot from lorenz import lorenzAttractor sigma, rho, beta, n = 10, 28, 8 / 3, 4000 x, y, a1, a2, a3, a4 = 400, 460, 0.01, 10, 200, 40 plotter = svgPlot(x, y) with open("results/lorenz-py.svg", "w") as fh: plotter.plotStart(fh) lorenzAttractor(plotter, sigma, rho, beta, n, a1, a2, a3, a4) plotter.plotEnd()
# # from src/svgplot.c # # void plot_start(int, int) to svgPlot; .plotStart # void plot_end(int) to svgPlot; .plotEnd # void move(double, double) to svgPlot; .move # void move_rel(double, double) to svgPlot; .moveRel # void draw(double, double) to svgPlot; .draw # void draw_rel(double, double) to svgPlot; .drawRel # from svgplot import svgPlot import math def sample(plotter, fh): plotter.plotStart(fh) # .plotStart() write to io.stdout for i in range(5): theta = 2 * math.pi * i / 5 x, y = 150 + 140 * math.cos(theta), 150 + 140 * math.sin(theta) if i == 0: plotter.move(x, y) else: plotter.draw(x, y) plotter.plotEnd(True) plotter = svgPlot(300, 300) with open("results/svgplot-py.svg", "w") as fh: sample(plotter, fh)