- Author:
- Philip Wagner
- Twitter:
- @
- GitHub:
- Facebook:
- Google+:
- +
- Reddit:
- /r/
- Pouet:
- Website:
- think-jeckel.de
- Compo:
- classic
- Demo link:
- https://js1k.com/2010-first/demo/543
- Shortlink:
- https://js1k.com/543
- Blog post:
- please update here!
- Bytes:
- 864
- Chars:
- 864
- Submission
M=Math;r=M.random;s=[];n=function(){for(i=8;i--;)s[i]=[~~(r()*3)-1,~~(r()*3)-1]};n();u=[];for(i=256;i--;)u[i]=~~(r()*256);function z(g,f,k){F=0.5-f*f-k*k;return F<0?0:M.pow(F,4)*(s[g%8][0]*f+s[g%8][1]*k)}function q(g,f){e=(3-M.sqrt(3))/6;a=(g+f)*0.5*(M.sqrt(3)-1);m=~~(g+a);b=~~(f+a);a=(m+b)*e;c=g-(m-a);j=f-(b-a);C=c>j;return 70*(z(u[m+u[b]],c,j)+z(u[m+C+u[b+!C]],c-C+e,j-!C+e)+z(u[m+1+u[b+1]],c-1+2*e,j-1+2*e))}c=document.body.children[0];c.width=w=innerWidth;c.height=h=innerHeight;document.body.style.overflow="hidden";d=c.getContext("2d");x=[];for(i=w;i--;)x[i]={x:r()*w,y:r()*h};setInterval(function(){d.fillStyle="rgba(255,255,255,.05)";d.fillRect(0,0,w,h);d.fillStyle="#000";for(i=w;i--;){X=x[i];a=q(X.x/300,X.y/300)*9;X.x+=M.cos(a);X.y+=M.sin(a);if(X.x<0||X.x>w||X.y<0||X.y>h){X.x=r()*w;X.y=r()*h}d.fillRect(X.x,X.y,1,1)}},33);c.onclick=function(){n()};
- Description
- Implemented the perlin noise algorithm. Click the canvas to generate a new seed.
1.3: The noise algorithm works properly now.
- Base64 encoded
TT1NYXRoO3I9TS5yYW5kb207cz1bXTtuPWZ1bmN0aW9uKCl7Zm9yKGk9ODtpLS07KXNbaV09W35+KHIoKSozKS0xLH5+KHIoKSozKS0xXX07bigpO3U9W107Zm9yKGk9MjU2O2ktLTspdVtpXT1+fihyKCkqMjU2KTtmdW5jdGlvbiB6KGcsZixrKXtGPTAuNS1mKmYtayprO3JldHVybiBGPDA/MDpNLnBvdyhGLDQpKihzW2clOF1bMF0qZitzW2clOF1bMV0qayl9ZnVuY3Rpb24gcShnLGYpe2U9KDMtTS5zcXJ0KDMpKS82O2E9KGcrZikqMC41KihNLnNxcnQoMyktMSk7bT1+fihnK2EpO2I9fn4oZithKTthPShtK2IpKmU7Yz1nLShtLWEpO2o9Zi0oYi1hKTtDPWM+ajtyZXR1cm4gNzAqKHoodVttK3VbYl1dLGMsaikreih1W20rQyt1W2IrIUNdXSxjLUMrZSxqLSFDK2UpK3oodVttKzErdVtiKzFdXSxjLTErMiplLGotMSsyKmUpKX1jPWRvY3VtZW50LmJvZHkuY2hpbGRyZW5bMF07Yy53aWR0aD13PWlubmVyV2lkdGg7Yy5oZWlnaHQ9aD1pbm5lckhlaWdodDtkb2N1bWVudC5ib2R5LnN0eWxlLm92ZXJmbG93PSJoaWRkZW4iO2Q9Yy5nZXRDb250ZXh0KCIyZCIpO3g9W107Zm9yKGk9dztpLS07KXhbaV09e3g6cigpKncseTpyKCkqaH07c2V0SW50ZXJ2YWwoZnVuY3Rpb24oKXtkLmZpbGxTdHlsZT0icmdiYSgyNTUsMjU1LDI1NSwuMDUpIjtkLmZpbGxSZWN0KDAsMCx3LGgpO2QuZmlsbFN0eWxlPSIjMDAwIjtmb3IoaT13O2ktLTspe1g9eFtpXTthPXEoWC54LzMwMCxYLnkvMzAwKSo5O1gueCs9TS5jb3MoYSk7WC55Kz1NLnNpbihhKTtpZihYLng8MHx8WC54Pnd8fFgueTwwfHxYLnk+aCl7WC54PXIoKSp3O1gueT1yKCkqaH1kLmZpbGxSZWN0KFgueCxYLnksMSwxKX19LDMzKTtjLm9uY2xpY2s9ZnVuY3Rpb24oKXtuKCl9Ow0K
- Original source
M = Math;
r = M.random;
s = [];
n = function(){
for (i = 8; i--;) {
s[i] = [~~(r()*3)-1, ~~(r()*3)-1]
}
}
n();
u = [];
for (i = 256; i--;) {
u[i] = ~~(r() * 256);
}
function z(k, t, l) {
F = .5 - t * t - l * l;
return (F < 0) ? 0 : M.pow(F, 4) * (s[k%8][0] * t + s[k%8][1] * l)
}
function q(k, t) {
e = (3-M.sqrt(3))/6;
a = (k + t) * .5*(M.sqrt(3)-1); // .36
m = ~~(k + a);
b = ~~(t + a);
a = (m + b) * e; // .2
c = k - (m - a);
j = t - (b - a);
C = c > j;
return 70 * (z(u[m + u[b]], c, j) +
z(u[m + C + u[b + !C]], c - C + e, j - !C + e) +
z(u[m + 1 + u[b + 1]], c - 1 + 2 * e, j - 1 + 2 * e))
};
c = document.body.children[0];
c.width = w = innerWidth;
c.height = h = innerHeight;
document.body.style.overflow = 'hidden';
d = c.getContext('2d');
x = [];
for(i = w; i--;) {
x[i] = {x:r()*w,y:r()*h};
}
setInterval(function() {
d.fillStyle = 'rgba(255,255,255,.05)';
d.fillRect(0,0,w,h);
d.fillStyle = '#000';
for (i = w; i--;){
X = x[i];
a = q(X.x/300, X.y/300) * 9;
X.x += M.cos(a);
X.y += M.sin(a);
if (X.x < 0 || X.x > w || X.y < 0 || X.y > h) {
X.x = r()*w;
X.y = r()*h;
}
d.fillRect(X.x, X.y, 1, 1);
}
}, 33);
c.onclick=function(){n()};