File:Ulam spiral 10x.png
Original file (2,010 × 2,010 pixels, file size: 8 KB, MIME type: image/png)
Captions
Summary
[edit]DescriptionUlam spiral 10x.png |
English: Plot of the Ulam spiral on a 201x201 grid. The image has been upscaled 10x so that it will not be too tiny on modern displays. |
Date | |
Source | Own work |
Author | Morn |
Python source code
[edit]# 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
[edit]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.
http://creativecommons.org/publicdomain/zero/1.0/deed.enCC0Creative Commons Zero, Public Domain Dedicationfalsefalse |
File history
Click on a date/time to view the file as it appeared at that time.
Date/Time | Thumbnail | Dimensions | User | Comment | |
---|---|---|---|---|---|
current | 10:38, 17 April 2023 | 2,010 × 2,010 (8 KB) | Morn (talk | contribs) | Uploaded own work with UploadWizard |
You cannot overwrite this file.
File usage on Commons
There are no pages that use this file.
File usage on other wikis
The following other wikis use this file:
- Usage on ary.wikipedia.org
- Usage on en.wikipedia.org
- Usage on en.wiktionary.org
Metadata
This file contains additional information such as Exif metadata which may have been added by the digital camera, scanner, or software program used to create or digitize it. If the file has been modified from its original state, some details such as the timestamp may not fully reflect those of the original file. The timestamp is only as accurate as the clock in the camera, and it may be completely wrong.
File change date and time | 10:08, 17 April 2023 |
---|