- Author:
- Tim Smith
- Twitter:
- @
- GitHub:
- Facebook:
- Google+:
- +
- Reddit:
- /r/
- Pouet:
- Website:
- timsmith.co.za
- Compo:
- classic
- Demo link:
- https://js1k.com/2010-first/demo/781
- Shortlink:
- https://js1k.com/781
- Blog post:
- please update here!
- Bytes:
- 1024
- Chars:
- 1024
- Submission
function A(x,y,z,w,c){with(G){lineWidth=4;strokeStyle='rgb('+F(c[0]*h)+','+F(c[1]*h)+','+F(c[2]*h)+')';beginPath();moveTo(x,y);lineTo(z,w);stroke();}}function B(){a=y/h;return [.2+a,.3+a,.6+a*.7];}function C(x,y){s=M.log(d+20)/.7-1;b=s-(s=F(s));c=q=0;for(i=s;i<s+8;i++){t=E(2,i);X=x/t;Y=y/t;u=X-F(X);v=Y-F(Y);X-=u;Y=(Y-v)*I;Z=Y+I;a=[Y%J+X++%I,Y%J+X%I,Z%J+X--%I,Z%J+X%I];l=[];for(j=0;j<4;j++)l[j]=N[(F(i)*I+a[j])%L];t*=i==s?1-b:i==s+7?b:1;c+=(((1-u)*l[0]+u*l[1])*(1-v)+((1-u)*l[3]+u*l[2])*v)*t;q+=t};c=E(M.abs(c/q*2-1),1.5);return y<400?c*y/399:c}function D(){d=4+z/I;for(x=0;x<w;x++){o=C(P=(x-w/2)*d+w,z);y=h-o*2200/(d+20)-(d-6)*5;if(x){H=C(P+d,z)-o;$=C(P,z+d)-o;m=M.sqrt(H*H+9/J+$*$);l=1-M.max(0,H/m*.1+$/m*.9);for(i=0,c=[],b=z/L/2.1;i<3;i++){c[i]=(1-b)*(l+o)/5+b*B()[i];}A(x-1,ly,x,y,c);}ly=y;}z-=d;if(z>0)setTimeout(D,1);}M=Math;E=M.pow;F=M.floor;I=1000;J=I*I;L=9*I;N=[];for(i=0;i<L;N[i++]=M.random());with(document.getElementById('c')){width=w=I;height=h=255;G=getContext('2d')};for(y=0;y<h;A(0,y,w,y++,B()));z=L*2.1;D()
- Description
- Renders a random 3D landscape with lighting & aerial perspective.
Terrain is rendered by sampling over an infinite Perlinesque noise field and tracing contours over it.
- Base64 encoded
ZnVuY3Rpb24gQSh4LHkseix3LGMpe3dpdGgoRyl7bGluZVdpZHRoPTQ7c3Ryb2tlU3R5bGU9J3JnYignK0YoY1swXSpoKSsnLCcrRihjWzFdKmgpKycsJytGKGNbMl0qaCkrJyknO2JlZ2luUGF0aCgpO21vdmVUbyh4LHkpO2xpbmVUbyh6LHcpO3N0cm9rZSgpO319ZnVuY3Rpb24gQigpe2E9eS9oO3JldHVybiBbLjIrYSwuMythLC42K2EqLjddO31mdW5jdGlvbiBDKHgseSl7cz1NLmxvZyhkKzIwKS8uNy0xO2I9cy0ocz1GKHMpKTtjPXE9MDtmb3IoaT1zO2k8cys4O2krKyl7dD1FKDIsaSk7WD14L3Q7WT15L3Q7dT1YLUYoWCk7dj1ZLUYoWSk7WC09dTtZPShZLXYpKkk7Wj1ZK0k7YT1bWSVKK1grKyVJLFklSitYJUksWiVKK1gtLSVJLFolSitYJUldO2w9W107Zm9yKGo9MDtqPDQ7aisrKWxbal09TlsoRihpKSpJK2Fbal0pJUxdO3QqPWk9PXM/MS1iOmk9PXMrNz9iOjE7Yys9KCgoMS11KSpsWzBdK3UqbFsxXSkqKDEtdikrKCgxLXUpKmxbM10rdSpsWzJdKSp2KSp0O3ErPXR9O2M9RShNLmFicyhjL3EqMi0xKSwxLjUpO3JldHVybiB5PDQwMD9jKnkvMzk5OmN9ZnVuY3Rpb24gRCgpe2Q9NCt6L0k7Zm9yKHg9MDt4PHc7eCsrKXtvPUMoUD0oeC13LzIpKmQrdyx6KTt5PWgtbyoyMjAwLyhkKzIwKS0oZC02KSo1O2lmKHgpe0g9QyhQK2QseiktbzskPUMoUCx6K2QpLW87bT1NLnNxcnQoSCpIKzkvSiskKiQpO2w9MS1NLm1heCgwLEgvbSouMSskL20qLjkpO2ZvcihpPTAsYz1bXSxiPXovTC8yLjE7aTwzO2krKyl7Y1tpXT0oMS1iKSoobCtvKS81K2IqQigpW2ldO31BKHgtMSxseSx4LHksYyk7fWx5PXk7fXotPWQ7aWYoej4wKXNldFRpbWVvdXQoRCwxKTt9TT1NYXRoO0U9TS5wb3c7Rj1NLmZsb29yO0k9MTAwMDtKPUkqSTtMPTkqSTtOPVtdO2ZvcihpPTA7aTxMO05baSsrXT1NLnJhbmRvbSgpKTt3aXRoKGRvY3VtZW50LmdldEVsZW1lbnRCeUlkKCdjJykpe3dpZHRoPXc9STtoZWlnaHQ9aD0yNTU7Rz1nZXRDb250ZXh0KCcyZCcpfTtmb3IoeT0wO3k8aDtBKDAseSx3LHkrKyxCKCkpKTt6PUwqMi4xO0QoKQ==
- Original source
// line
function A(x,y,z,w,c)
{
with (G)
{
lineWidth = 4;
strokeStyle = 'rgb(' + F(c[0]*h) + ',' + F(c[1]*h) + ',' + F(c[2]*h) + ')';
beginPath();
moveTo(x, y);
lineTo(z, w);
stroke();
}
}
// sky
function B()
{
a = y / h;
return [.2 + a, .3 + a,.6 + a * .7];
}
// noise
function C(x, y)
{
s = M.log(d + 20) / .7 - 1;
b = s - (s = F(s));
c = q = 0;
for (i = s; i < s + 8; i++)
{
t = E(2, i);
X = x / t;
Y = y / t;
u = X - F(X);
v = Y - F(Y);
X -= u;
Y = (Y - v) * I;
Z = Y + I;
a=[
Y % J + X++ % I,
Y % J + X % I,
Z % J + X-- % I,
Z % J + X % I
];
l = [];
for (j = 0; j < 4; j++)
l[j] = N[(F(i) * I + a[j]) % L];
t *= i == s ? 1 - b : i == s + 7 ? b : 1;
c += ( ((1 - u) * l[0] + u * l[1]) * (1 - v) + ((1 - u) * l[3] + u * l[2]) * v ) * t;
q += t
};
c = E(M.abs(c / q * 2 - 1), 1.5);
return y < 400 ? c * y / 399 : c
}
// contour
function D()
{
d = 4 + z / I;
for (x = 0; x < w; x++)
{
o = C(P = (x - w/2) * d + w, z);
y = h - o * 2200 / (d + 20) - (d - 6) * 5;
if (x)
{
H = C(P + d, z) - o;
$ = C(P, z + d) - o;
m = M.sqrt(H * H + 9/J + $ * $);
l = 1 - M.max(0, H / m * .1 + $ / m * .9);
for (i=0, c=[], b = z / L / 2.1; i<3; i++)
{
c[i] =
(1 - b) * (l + o) / 5 +
b * B()[i];
}
A(x-1,ly,x,y,c);
}
ly = y;
}
z -= d;
if (z > 0)
setTimeout(D, 1);
}
M = Math;
E = M.pow;
F = M.floor;
I = 1000;
J = I * I;
L = 9 * I;
N = [];
for (i = 0; i < L; N[i++] = M.random());
with (document.getElementById('c'))
{
width = w = I;
height = h = 255;
G = getContext('2d')
};
for (y = 0; y < h; A(0,y,w,y++,B()));
z = L * 2.1;
D()