Created
January 22, 2013 05:24
-
-
Save graue/4592307 to your computer and use it in GitHub Desktop.
a kinda cool thing (generative art) that I put into http://jelv.is/draw/
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
function (x, y, d, a) { | |
function surface(x, y) { return (x-sin(y))*(sin(x)-y)*(sin(x)-sin(y)); } | |
function safer(func) { | |
return function(x) { | |
if (x === 0) return 0; | |
else if (x < 0) return -func(-x); | |
else return func(x); | |
} | |
} | |
var pi = 3.14159265; | |
// scale x and y | |
var width = 400, height = 400; | |
x = x*4*pi/width; | |
y = y*4*pi/height; | |
var h = surface(x, y); | |
var s = 0.5; //surface(0.23*sin(24*pi*safer(log, x)), y); | |
var l = 0.5; //surface(x, 0.01*y + 0.46*sin(24*pi*y*safer(sqrt, y) + pi/2)); | |
// I get a black image if i use the s and l constructions commented out :( | |
function hslToRgb(h, s, l){ | |
// this function is from http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript | |
// modified to return a Color object | |
var r, g, b; | |
if(s == 0){ | |
r = g = b = l; // achromatic | |
}else{ | |
function hue2rgb(p, q, t){ | |
if(t < 0) t += 1; | |
if(t > 1) t -= 1; | |
if(t < 1/6) return p + (q - p) * 6 * t; | |
if(t < 1/2) return q; | |
if(t < 2/3) return p + (q - p) * (2/3 - t) * 6; | |
return p; | |
} | |
var q = l < 0.5 ? l * (1 + s) : l + s - l * s; | |
var p = 2 * l - q; | |
r = hue2rgb(p, q, h + 1/3); | |
g = hue2rgb(p, q, h); | |
b = hue2rgb(p, q, h - 1/3); | |
} | |
return new Color(r * 255, g * 255, b * 255); | |
} | |
return hslToRgb(h, s, l); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment