Contact Us!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: sagemathinc/cocalc-example-files
Path: blob/master/sage/interact/Fractals/sierpinskiTri.sagews
Views: 1215
def sierpinski(N): '''Generates the Sierpinski triangle by taking the modulo-2 of each element in Pascal's triangle''' return [([0] * (N // 2 - a // 2)) + [binomial(a, b) % 2 for b in range(a + 1)] + ([0] * (N // 2 - a // 2)) for a in range(0, N, 2)] @interact def _(N=slider([2 ** a for a in range(12)], label='Number of iterations', default=64), size=slider(1, 20, label='Size', step_size=1, default=9)): M = sierpinski(2 * N) matrix_plot(M, cmap='binary').show(figsize=[size, size])
Interact: please open in CoCalc