| KevinPluck.net | InvisiCalc | SuDoku Helper | Kakuro Combinations | rotxd.com |
|
Introduction Part 1 Part 2 Part 3 Part 4 Part 5 Part 6 More to come... Please add the factorbothering sub-reddit to your frontpage. |
Factor bothering - Part 5Please be aware that from now on I will be using the term "divisor" instead of "factor".In Part 4 I plotted numbers with divisor pair counts of 29 and 31 (Divisor counts of 58 and 62). Here I will be plotting out numbers that share the same number of divisors on different graphs. This is the code I will use: plotDivisorAnim.py
import Image, ImageDraw
import os,sys
size = 547,547
numOfDivisors=100
images=[]
#Create images
for anImage in range(numOfDivisors):
images.append(Image.new("1",size))
#Set all their backgrounds to white
for anImage in range(numOfDivisors):
ImageDraw.Draw(images[anImage]).rectangle(((0,0),size),1)
divisorFile=open('..\\Part4\\factors15Mill.txt','r')
theInteger=0
#As the max integer we can plot is the square of the size
#of the image then we'll stop when we get to that value
theIntegerMax=size[1]*size[1]
for line in divisorFile:
theInteger+=1
if theInteger>=theIntegerMax: break
divisors=line.split()
divisorCount=len(divisors)
if divisorCount<=numOfDivisors and divisorCount>0:
for pointxy in range(0,divisorCount,2):
x=int(divisors[pointxy])
y=int(divisors[pointxy+1])
if x<size[0] and y<size[1]:
images[divisorCount].putpixel((x,y),0)
#Plot the other half of the graph as well, it looks nicer
images[divisorCount].putpixel((y,x),0)
divisorFile.close()
for anImage in range(2,numOfDivisors,2):
images[anImage].save('%(#)02ddivisors.png'%{"#":anImage},"PNG")
This generates one image for each divisor count, in this case 49 images.
After grantisu suggested to make a combined greyscale image of the above, here it is:
I highly recommend downloading it and zoom around in your favourite image editor. Here's the code: plotDivisorGreyScale.py
import Image, ImageDraw
import os,sys
size = 600,600
im1=Image.new("RGB",size)
draw1=ImageDraw.Draw(im1)
draw1.rectangle(((0,0),size),(255,255,255)) #set background to white
divisorFile=open('..\\Part4\\factors15Mill.txt','r')
theInteger=0
#As the max integer we can plot is the square of the size
#of the image then we'll stop when we get to that value
theIntegerMax=size[1]*size[1]
for line in divisorFile:
theInteger+=1
if theInteger>=theIntegerMax: break
divisors=line.split()
divisorCount=len(divisors)
for pointxy in range(0,divisorCount,2):
x=int(divisors[pointxy])
y=int(divisors[pointxy+1])
if x<size[0] and y<size[1]:
greyscale=255-divisorCount
greyscaleTup=(greyscale,greyscale,greyscale)
im1.putpixel((x,y),greyscaleTup)
#Plot the other half of the graph as well, it looks nicer
im1.putpixel((y,x),greyscaleTup)
divisorFile.close()
im1.save('GreyScaleDivisors.png',"PNG")
|