Created
August 17, 2014 12:46
-
-
Save boronine/bc6f846c65f03c55bcdb to your computer and use it in GitHub Desktop.
Colorful display pic with HUSL
This file contains 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
import math | |
import png | |
from husl import * | |
def mix(h1, h2, t): | |
return h1 * t + h2 * (1 - t) | |
def spiral(radius, degree, number): | |
n = 1.0 / number | |
curvy_radius = (radius + degree) % 1 | |
return ((curvy_radius % n) / n) | |
def spiral_cart(cx, cy, number): | |
radius = math.sqrt(cx ** 2 + cy ** 2) | |
degree_rad = math.atan2(cy, cx) | |
degree = degree_rad / 2.0 / math.pi + 0.5 | |
return spiral(radius, degree, number) | |
def get_color(x, y): | |
cx = x - 0.5 | |
cy = y - 0.5 | |
criss = (x + y) / 2 | |
cross = ((1 - x) + y) / 2 | |
radius = math.sqrt(cx ** 2 + cy ** 2) | |
degree_rad = math.atan2(cy, cx) | |
degree = degree_rad / 2.0 / math.pi | |
spiral1 = spiral_cart(cx, cy, 10) | |
spiral2 = spiral_cart(cx, cy, 9) | |
color1 = criss | |
color2 = cross | |
color3 = degree | |
s = 1 | |
l = mix(0.5, criss, spiral2) | |
h = mix(color2, color3, spiral1) | |
h = (h + color1) % 1 | |
return (360 * h, 100 * s, 100 * l) | |
def write_png(func, height, width): | |
p = [] | |
for i in range(height): | |
row = [] | |
for j in range(width): | |
row.extend(rgb_prepare(husl_to_rgb(*func( | |
float(j) / width, | |
float(i) / height)))) | |
p.append(row) | |
f = open('avatar.png', 'wb') | |
w = png.Writer(width, height) | |
w.write(f, p) | |
f.close() | |
if __name__ == "__main__": | |
write_png(get_color, 300, 300) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment