2 ms·
I made something that compiles it to Javascript: https://gist.github.com/Matheus28/ce76f1f7f5e2b046b1fd https://gist.github.com/Matheus28/ce76f1f7f5e2b046b1fd
by Matheus28 11y ago
I made something that compiles it to Javascript: https://gist.github.com/Matheus28/ce76f1f7f5e2b046b1fd https://gist.github.com/Matheus28/ce76f1f7f5e2b046b1fd
The original idea was compiling it to GLSL, but I got lazy. But it should be pretty easy to make it generate GLSL.
It doesn't do constant folding or any smart optimizations, but it should be pretty easy to code that in.
Example:
This:
x12/-y12/-a6+8*x12/-d*y12/-d*+qq82**p112/x-d*-112/y-d*-*d*d*d**dd*+dd*+dd*+
Generates:
var tmp0 = (x - (1 / 2))
var tmp1 = (y - (1 / 2))
var tmp2 = ((1 / 2) - x)
var tmp3 = ((1 / 2) - y)
var tmp4 = ((1 - (tmp2 * tmp2)) * (1 - (tmp3 * tmp3)))
var tmp5 = (tmp4 * tmp4)
var tmp6 = (tmp5 * tmp5)
var tmp7 = (perlin(((Math.atan2((x - (1 / 2)), (y - (1 / 2))) + 6) * 8), (Math.sqrt(Math.sqrt(((tmp0 * tmp0) + (tmp1 * tmp1)))) * (8 * 2))) * (tmp6 * tmp6))
var tmp9 = (tmp7 + (tmp7 * tmp7))
var tmp11 = (tmp9 + (tmp9 * tmp9))
return (tmp11 + (tmp11 * tmp11))
function perlin(b,c){function g(b,c,a){a=a*a*a*(a*(6*a-15)+10);return(1-a)*b+a*c}function d(d,e){var a=2*(256*e+d);return(b-d)*gradient[a]+(c-e)*gradient[a+1]}b%=256;c%=256;var e=b&255,f=c&255,h=e+1&255,k=f+1&255,l=b-e,m=c-f;return g(g(d(e,f),d(h,f),l),g(d(e,k),d(h,k),l),m)};
- Lerc 11y agoIf you make a GLSL version you absolutely must add "t" : push(time);