Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var canvas = document.getElementsByTagName('canvas')[0];
- var context = canvas.getContext('2d');
- document.body.bgColor = X = Y = H = I = J = E = Q = U = V = 0;
- T = [l = 1];
- C = (canvas.width = canvas.height = innerHeight) / 2;
- setInterval(function() {
- for (i = H; i < X + 1400; H = ++i) {
- s = i % 800;
- if (!s) {
- /* Will run every once in a while to change direction and environment */
- changeCounter = i / 800;
- inclineAmount = changeCounter & 1 && -Q + (Q = Math.random() > 0.5); // Centered around 0.
- turnAmount = !inclineAmount && changeCounter && (turnAmount + 2 + (Math.random() > 0.5)) % 3 - 1; //Centered around 0.
- inStalCave = !inclineAmount && changeCounter > 9 && !inStalCave && Math.random() > 0.7; //Boolean.
- W = 1.8 * Math.random() - 1;
- }
- F = (s < 160) - (s > 639);
- E += F;
- T[i % 1400] = [I += J, J += turnAmount, U += V, V = inclineAmount * E, !inclineAmount && Math.exp(-(L = i % 400 - 200) * L / 3000) / 1.5, i % 400, Math.random() > 0.95];
- rectData = T[i % 1400];
- if (!(i % 10)) {
- Z = 9.8 + inStalCave * E / 15;
- y = Z
- z = W * inStalCave * E / 15;
- /*
- Rect info is stored in array rectData in the following order and repeated as many times as needed:
- - X position (relative to centre)
- - Init color (from white to black)
- - Width from x
- - Y position (relative to centre)
- - Height from y
- */
- /* Cave (literally just a circle) */
- for (g = Math.random() / 6; g < 6.3; g += 2 / Z) {
- if (inclineAmount || inStalCave) {
- if (Math.random() > 0.4) {
- rectData.push(1.1 * Z * Math.cos(g + 11));
- rectData.push(7 + inStalCave * 16, 4 - F);
- rectData.push(Z * Math.cos(g) + 2 + z);
- rectData.push(4 - F);
- }
- } else {
- if (Math.random() > (Math.cos(g) > 0.5)) {
- rectData.push(1.1 * Z * Math.cos(g + 11));
- rectData.push(7 + inStalCave * 16);
- rectData.push(4 - F, Z * Math.cos(g) + 2 + z);
- rectData.push(4 - F);
- }
- }
- }
- t = 2 * Z * Math.random() - Z;
- w = t * t * Math.random() / 6;
- /* Stalactites and Stalagmites */
- while (inStalCave * w > 0.2) {
- rectData.push(t);
- rectData.push(7 + inStalCave * 16);
- rectData.push(w);
- rectData.push(--y + z);
- rectData.push(1.1);
- rectData.push(t);
- rectData.push(7 + inStalCave * 16);
- rectData.push(w *= 0.8);
- rectData.push(-y + z);
- rectData.push(1.1);
- }
- /* I have no clue what this is */
- if (!Q && (inStalCave * W > 0.6)) {
- rectData.push(2 * Z * Math.random() - Z);
- rectData.push(12);
- rectData.push(0.2);
- rectData.push(Z * Math.random() - Z / 2 + z);
- rectData.push(1 + Math.random());
- }
- /* */
- if (inStalCave && i % 20) {
- rectData.push(-2);
- rectData.push(22);
- rectData.push(0.5);
- rectData.push(-7);
- rectData.push(Z - 8 - z);
- rectData.push(2);
- rectData.push(22);
- rectData.push(0.5);
- rectData.push(-7);
- rectData.push(Z - 8 - z);
- }
- /* Horizontal bars on tracks */
- if (!(i % 20)) {
- rectData.push(0);
- rectData.push(6);
- rectData.push(6);
- rectData.push(-6.8);
- rectData.push(0.8);
- }
- /* Lamps */
- if (!L) {
- rectData.push(0);
- rectData.push(7 + inStalCave * 16);
- rectData.push(0.2);
- rectData.push(Z + z);
- rectData.push(Z + z - 5);
- rectData.push(0);
- rectData.push(7);
- rectData.push(0.6);
- rectData.push(5);
- rectData.push(0.6);
- }
- /* Doorway thing */
- if (!inclineAmount && !inStalCave) {
- if (!(i % 40)) {
- rectData.push(-6);
- rectData.push(6);
- rectData.push(1.5);
- rectData.push(5);
- rectData.push(14);
- rectData.push(6);
- rectData.push(6);
- rectData.push(1.5);
- rectData.push(5);
- rectData.push(14);
- }
- if (!(i % 20)) {
- rectData.push(0);
- rectData.push(6);
- rectData.push(17);
- rectData.push(8);
- rectData.push(3);
- }
- }
- }
- /* Train track (the metal part) */
- if (!(i % 5)) {
- /* Left */
- rectData.push(-2);
- rectData.push(6);
- rectData.push(0.5);
- rectData.push(-6.5);
- rectData.push(0.6);
- /* Right */
- rectData.push(2);
- rectData.push(6);
- rectData.push(0.5);
- rectData.push(-6.5);
- rectData.push(0.6);
- }
- }
- q = T[X % 1400];
- while (true) {
- d = --i - X;
- if (!d)
- break;
- rectData = T[i % 1400];
- f = C / (d / 10 + 3);
- v = g = 0;
- t = C + f * (rectData[g] - q[g++] - d * q[g++]) / 3000;
- u = C + f * (rectData[g] - q[g++] - d * q[g++]) / 3000;
- /* Light flicker. */
- x = rectData[g++];
- if (rectData[g++])
- l = g++ && l;
- else if (rectData[g++])
- l = Math.random() > 0.3;
- else
- l = 1;
- x *= l;
- y = d / 1800;
- while (true) {
- z = f * rectData[g++];
- w = rectData[g++];
- if (!w)
- break;
- v != w && (v = w, context.fillStyle = 'hsl(0,0%,' + 16 * (w & 7) * (w & 8 || y + x * (w < 16)) + '%)');
- var rectX = t + z - (z = f * rectData[g++]) / 2;
- var rectY = u - f * rectData[g++] + (w == 12 && f * 6 * Math.cos(g + X / 400));
- var rectW = z;
- var rectH = f * rectData[g++];
- context.fillRect(rectX, rectY, rectW, rectH);
- }
- }
- Y += 4 - 3 * Math.exp(-X / 400) + q[2] / 30000;
- X = 0 | Y;
- }, 35);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement