Created
December 31, 2013 01:30
-
-
Save KevinGreene/8190995 to your computer and use it in GitHub Desktop.
Python Prime Number Viewer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from PIL import Image | |
| height = 1039 | |
| width = 1039 | |
| im = Image.new("RGB", (width,height), "white") | |
| pixels = im.load() | |
| f = open('prime_colors', 'r') | |
| for x in range(width): | |
| for y in range(height): | |
| colors = f.readline() | |
| if len(colors) == 0: | |
| break | |
| colors = colors.split(',') | |
| pixels[x,y] = (int(colors[0]), int(colors[1]), int(colors[2])) | |
| im.save("primes.png") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def primes_sieve1(limit): | |
| limitn = limit+1 | |
| primes = dict() | |
| for i in range(2, limitn): primes[i] = True | |
| for i in primes: | |
| factors = range(i,limitn, i) | |
| for f in factors[1:]: | |
| primes[f] = False | |
| return [i for i in primes if primes[i]==True] | |
| def convert_to_base_256(n): | |
| if n > 256**3: | |
| print("number is too large: " + str(n)) | |
| squared = n // (256**2) | |
| base = n // 256 % 256 | |
| single = n % 256 | |
| return [squared, base, single] | |
| if __name__ == "__main__": | |
| primes = primes_sieve1(256**3) | |
| for i in primes: | |
| base256 = convert_to_base_256(i) | |
| print("(" + str(base256[0])+"," + str(base256[1])+ "," + str(base256[2]) + ")") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment