This file is from a shared repository and may be used by other projects.
The description on its file description page there is shown below.
Summary
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:
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.en CC0 Creative Commons Zero, Public Domain Dedication false false
English Add a one-line explanation of what this file represents
File history
Click on a date/time to view the file as it appeared at that time.
Date/Time Thumbnail Dimensions User Comment
current 05:38, 17 April 2023 2,010 × 2,010 (8 KB) imagescommonswiki>Morn Uploaded own work with UploadWizard
File usage
The following file is a duplicate of this file (more details ):
The following page uses this file:
This file contains additional information, probably added from the digital camera or scanner used to create or digitize it.
If the file has been modified from its original state, some details may not fully reflect the modified file.