Created
March 27, 2022 03:51
-
-
Save vhxs/4cf0e7def3f287268b8978ca6a9f879e to your computer and use it in GitHub Desktop.
This is code that I used to generate and post an award-winning piece of art on DeviantArt over a decade ago...
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 tkinter import * | |
import time | |
root = Tk() | |
def n2color(n): | |
p = 1.1 | |
def f(x): | |
return p**-x | |
color = '' | |
for i in range(1): | |
bit1 = hex(int(255*f(n)))[2:] | |
bit2 = hex(int(255*(1-f(n))))[2:] | |
if len(bit1) == 1: | |
bit1 = '0' + bit1 | |
if len(bit2) == 1: | |
bit2 = '0' + bit2 | |
color = '#' + '00' + bit1 + '00' | |
return color | |
w = 2500 | |
h = 2500 | |
canvas1 = Canvas(root, width = w, height = h) | |
canvas1.pack() | |
n = 100. | |
k = 1. | |
while k <= n: | |
print("k = " + str(int(k)), "color = " + n2color(k)) | |
dx = w/(4*k**1.5) | |
dy = h/(4*k**1.5) | |
for i in range(int(k) + 1): | |
xc = (i/k)*w | |
for j in range(int(k) + 1): | |
yc = (j/k)*h | |
canvas1.create_rectangle(xc - dx, yc - dy, xc + dx, yc + dy, fill = n2color(k), outline = n2color(k)) | |
k += 1 | |
canvas1.update() | |
canvas1.postscript(file="rationals.ps", width=w, height=h) | |
root.mainloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment