File:Ulam spiral 10x.svg

From testwiki
Jump to navigation Jump to search
    Original file (SVG file, nominally 2,680 × 2,680 pixels, file size: 245 KB)

    This file is from Wikimedia Commons and may be used by other projects. The description on its file description page there is shown below.

    Summary

    Description
    English: Plot of the Ulam spiral on a 201x201 grid. This SVG version of File:Ulam spiral 10x.png has been vectorized with potrace.
    Date
    Source Own work
    Author Morn
    SVG development
    InfoField
     The SVG code is valid.
     This vector image was created with Potrace.

    Python source code

    # Create image of Ulam spiral
    
    SIZE = 201    # image size (must be odd)
    
    P = [0] * (SIZE * SIZE + 1)
    
    for C in range(2, len(P)):
        if P[C] == 0:
            #print(C)
            for x in range(2, len(P)):
                z = x * C
                if z >= len(P):
                    break
                P[z] = 1
    
    cdir = 0
    dirs = [(1,0), (0,-1), (-1,0), (0,1)]
    out = [["0"] * SIZE for y in range(SIZE)]
    px, py = SIZE//2, SIZE//2
    nstep = []
    cstep = 1
    for x in range(SIZE * SIZE):
        nstep.append(cstep)
        nstep.append(cstep)
        cstep += 1
    
    cstep = nstep.pop(0)
    for p in range(SIZE * SIZE):
        if p > 0 and P[p+1] == 0:
            out[py][px] = "1"
        px += dirs[cdir % 4][0]
        py += dirs[cdir % 4][1]
        cstep -= 1
        if cstep == 0:    
            cdir += 1
            cstep = nstep.pop(0)
    
    # Save image in NetPBM bitmap format
    f = open("ulam.pbm", "w")
    f.write(f"P1\n{SIZE} {SIZE}\n")
    for y in range(SIZE):
        f.write(''.join(out[y]) + "\n")
    f.close()
    
    # Convert PBM to PNG with ImageMagick (and increase resolution 10x):
    #  mogrify -format png -interpolate Nearest -filter point -resize 1000% ulam.pbm
    

    Licensing

    I, the copyright holder of this work, hereby publish it under the following license:
    Creative Commons CC-Zero This file is made available under the Creative Commons CC0 1.0 Universal Public Domain Dedication.
    The person who associated a work with this deed has dedicated the work to the public domain by waiving all of their rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission.

    Captions

    Add a one-line explanation of what this file represents

    Items portrayed in this file

    depicts

    15 February 2026

    250,722 byte

    image/svg+xml

    3a0d076445bb253c9af17362b5be1dac9cbad79d

    File history

    Click on a date/time to view the file as it appeared at that time.

    Date/TimeThumbnailDimensionsUserComment
    current14:12, 15 February 2026Thumbnail for version as of 14:12, 15 February 20262,680 × 2,680 (245 KB)wikimediacommons>MornUploaded own work with UploadWizard

    There are no pages that use this file.