mirror of
https://github.com/Rezmason/matrix.git
synced 2026-04-14 12:29:30 -07:00
288 lines
11 KiB
HTML
288 lines
11 KiB
HTML
<html>
|
|
<head>
|
|
<title>Matrix digital rain</title>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
|
|
</head>
|
|
<body style="height: 100vh; margin: 0; overflow: hidden; position: fixed; padding: 0; width: 100vw;">
|
|
<script src="./lib/three.js"></script>
|
|
|
|
<script src="./js/CopyShader.js"></script>
|
|
|
|
<script src="./js/EffectComposer.js"></script>
|
|
<script src="./js/RenderPass.js"></script>
|
|
<script src="./js/ShaderPass.js"></script>
|
|
|
|
<script src="./js/ColorMapPass.js"></script>
|
|
<script src="./js/HorizontalColorationPass.js"></script>
|
|
<script src="./js/LuminosityHighPassShader.js"></script>
|
|
<script src="./js/UnrealBloomPass.js"></script>
|
|
<script src="./js/ImageOverlayPass.js"></script>
|
|
<script src="./js/GPUComputationRenderer.js"></script>
|
|
|
|
<script src="./js/MatrixRenderer.js"></script>
|
|
|
|
<script>
|
|
|
|
const versions = {
|
|
paradise: {
|
|
fontTexture: "./coptic_msdf.png",
|
|
raindropLength: 0.5,
|
|
glyphSequenceLength: 32,
|
|
bloom: {
|
|
strength: 4,
|
|
radius: 1,
|
|
threshold: 0
|
|
},
|
|
palette: [
|
|
{r: 0.00, g: 0.00, b: 0.00, at: 0.0},
|
|
{r: 0.52, g: 0.17, b: 0.05, at: 0.4},
|
|
{r: 0.82, g: 0.37, b: 0.12, at: 0.7},
|
|
{r: 1.00, g: 0.74, b: 0.29, at: 0.9},
|
|
{r: 1.00, g: 1.00, b: 1.00, at: 1.0},
|
|
],
|
|
fallSpeed: 0.05,
|
|
cycleSpeed: 0.05,
|
|
hasThunder: false,
|
|
hasSun: true,
|
|
slant: 0,
|
|
glyphEdgeCrop: 0.0,
|
|
glyphHeightToWidth:1,
|
|
isPolar: true,
|
|
numColumns: 50,
|
|
fade: true,
|
|
cycleStyle: "cycleFasterWhenDimmed"
|
|
},
|
|
nightmare: {
|
|
fontTexture: "./gothic_msdf.png",
|
|
raindropLength: 0.6,
|
|
glyphSequenceLength: 27,
|
|
bloom: {
|
|
strength: 2,
|
|
radius: 0.8,
|
|
threshold: 0.5
|
|
},
|
|
palette: [
|
|
{r: 0.00, g: 0.00, b: 0.00, at: 0.0},
|
|
{r: 0.52, g: 0.00, b: 0.00, at: 0.2},
|
|
{r: 0.82, g: 0.05, b: 0.05, at: 0.4},
|
|
{r: 1.00, g: 0.60, b: 0.30, at: 0.8},
|
|
{r: 1.00, g: 1.00, b: 0.90, at: 1.0},
|
|
],
|
|
fallSpeed: 2.0,
|
|
cycleSpeed: 0.02,
|
|
hasThunder: true,
|
|
hasSun: false,
|
|
slant: 360 / 16,
|
|
glyphEdgeCrop: 0.0,
|
|
glyphHeightToWidth:1,
|
|
isPolar: false,
|
|
numColumns: 60,
|
|
fade: true,
|
|
cycleStyle: "cycleFasterWhenDimmed"
|
|
},
|
|
["1999"]: {
|
|
fontTexture: "./matrixcode_msdf.png",
|
|
raindropLength: 1,
|
|
glyphSequenceLength: 57,
|
|
bloom: {
|
|
strength: 2,
|
|
radius: 0.5,
|
|
threshold: 0.3
|
|
},
|
|
palette: [
|
|
{r: 0/255, g: 0/255, b: 0/255, at: 0/16},
|
|
{r: 6/255, g: 16/255, b: 8/255, at: 1/16},
|
|
{r: 11/255, g: 28/255, b: 15/255, at: 2/16},
|
|
{r: 17/255, g: 41/255, b: 23/255, at: 3/16},
|
|
{r: 20/255, g: 58/255, b: 31/255, at: 4/16},
|
|
{r: 23/255, g: 84/255, b: 39/255, at: 5/16},
|
|
{r: 30/255, g: 113/255, b: 48/255, at: 6/16},
|
|
{r: 43/255, g: 142/255, b: 60/255, at: 7/16},
|
|
{r: 57/255, g: 160/255, b: 72/255, at: 8/16},
|
|
{r: 70/255, g: 175/255, b: 81/255, at: 9/16},
|
|
{r: 75/255, g: 187/255, b: 85/255, at: 10/16},
|
|
{r: 78/255, g: 196/255, b: 91/255, at: 11/16},
|
|
{r: 83/255, g: 203/255, b: 102/255, at: 12/16},
|
|
{r: 92/255, g: 212/255, b: 114/255, at: 13/16},
|
|
{r: 109/255, g: 223/255, b: 130/255, at: 14/16},
|
|
{r: 129/255, g: 232/255, b: 148/255, at: 15/16},
|
|
{r: 140/255, g: 235/255, b: 157/255, at: 16/16},
|
|
],
|
|
fallSpeed: 1,
|
|
cycleSpeed: 1,
|
|
hasThunder: false,
|
|
hasSun: false,
|
|
slant: 0,
|
|
glyphEdgeCrop: 0.0,
|
|
glyphHeightToWidth:1,
|
|
isPolar: false,
|
|
numColumns: 80,
|
|
fade: true,
|
|
cycleStyle: "cycleFasterWhenDimmed"
|
|
},
|
|
throwback: {
|
|
fontTexture: "./matrixcode_msdf.png",
|
|
raindropLength: 2,
|
|
glyphSequenceLength: 57,
|
|
bloom: {
|
|
strength: 0.3,
|
|
radius: 1.5,
|
|
threshold: 0.0
|
|
},
|
|
palette: [
|
|
{r: ( 0 * 1.3)/255, g: ( 0 * 1.2)/255, b: ( 0 * 1.3)/255, at: 0/48},
|
|
{r: ( 6 * 1.3)/255, g: ( 16 * 1.2)/255, b: ( 8 * 1.3)/255, at: 1/48},
|
|
{r: ( 11 * 1.3)/255, g: ( 28 * 1.2)/255, b: ( 15 * 1.3)/255, at: 2/48},
|
|
{r: ( 17 * 1.3)/255, g: ( 41 * 1.2)/255, b: ( 23 * 1.3)/255, at: 3/48},
|
|
{r: ( 20 * 1.3)/255, g: ( 58 * 1.2)/255, b: ( 31 * 1.3)/255, at: 4/48},
|
|
{r: ( 23 * 1.3)/255, g: ( 84 * 1.2)/255, b: ( 39 * 1.3)/255, at: 5/48},
|
|
{r: ( 30 * 1.3)/255, g: (113 * 1.2)/255, b: ( 48 * 1.3)/255, at: 6/48},
|
|
{r: ( 43 * 1.3)/255, g: (142 * 1.2)/255, b: ( 60 * 1.3)/255, at: 7/48},
|
|
{r: ( 57 * 1.3)/255, g: (160 * 1.2)/255, b: ( 72 * 1.3)/255, at: 8/48},
|
|
{r: ( 70 * 1.3)/255, g: (175 * 1.2)/255, b: ( 81 * 1.3)/255, at: 9/48},
|
|
{r: ( 75 * 1.3)/255, g: (187 * 1.2)/255, b: ( 85 * 1.3)/255, at: 10/48},
|
|
{r: ( 78 * 1.3)/255, g: (196 * 1.2)/255, b: ( 91 * 1.3)/255, at: 11/48},
|
|
{r: ( 83 * 1.3)/255, g: (203 * 1.2)/255, b: (102 * 1.3)/255, at: 12/48},
|
|
{r: ( 92 * 1.3)/255, g: (212 * 1.2)/255, b: (114 * 1.3)/255, at: 13/48},
|
|
{r: (109 * 1.0)/255, g: (255 * 1.0)/255, b: (130 * 1.0)/255, at: 14/48},
|
|
{r: (129 * 1.0)/255, g: (255 * 1.0)/255, b: (148 * 1.0)/255, at: 15/48},
|
|
{r: (140 * 1.0)/255, g: (255 * 1.0)/255, b: (157 * 1.0)/255, at: 16/48},
|
|
{r: (255 * 1.0)/255, g: (255 * 1.0)/255, b: (255 * 1.0)/255, at: 36/48},
|
|
],
|
|
fallSpeed: 0.6,
|
|
cycleSpeed: 0.4,
|
|
hasThunder: false,
|
|
hasSun: false,
|
|
slant: 0,
|
|
glyphEdgeCrop: 0.15,
|
|
glyphHeightToWidth:1.5,
|
|
isPolar: false,
|
|
numColumns: 90,
|
|
fade: false,
|
|
cycleStyle: "cycleRandomly"
|
|
}
|
|
};
|
|
|
|
const urlParams = new Map(window.location.href.replace(/^[^\?]+\?/, "").split("&").map(pair => pair.split("=")));
|
|
const getParam = (keyOrKeys, defaultValue) => {
|
|
if (Array.isArray(keyOrKeys)) {
|
|
const keys = keyOrKeys;
|
|
const key = keys.find(key => urlParams.has(key));
|
|
return key != null ? urlParams.get(key) : defaultValue;
|
|
} else {
|
|
const key = keyOrKeys;
|
|
return urlParams.has(key) ? urlParams.get(key) : defaultValue;
|
|
}
|
|
};
|
|
|
|
const version = versions[getParam("version", "1999")] || versions["1999"];
|
|
|
|
const sharpness = parseFloat(getParam("sharpness", 0.5));
|
|
const animationSpeed = parseFloat(getParam("animationSpeed", 1));
|
|
const fallSpeed = parseFloat(getParam("fallSpeed", 1)) * version.fallSpeed;
|
|
const cycleSpeed = parseFloat(getParam("cycleSpeed", 1)) * version.cycleSpeed;
|
|
const numColumns = parseInt(getParam("width", version.numColumns));
|
|
const raindropLength = parseFloat(getParam(["raindropLength", "dropLength"], version.raindropLength));
|
|
const numFontColumns = 8;
|
|
const glyphSequenceLength = version.glyphSequenceLength;
|
|
const slant = parseFloat(getParam(["slant", "angle"], version.slant)) * Math.PI / 180;
|
|
const glyphEdgeCrop = parseFloat(getParam("encroach", version.glyphEdgeCrop));
|
|
const glyphHeightToWidth = parseFloat(getParam("stretch", version.glyphHeightToWidth));
|
|
const fade = getParam("fade", version.fade).toString() == "true";
|
|
|
|
const effect = getParam("effect", "plain");
|
|
|
|
document.ontouchmove = (e) => e.preventDefault();
|
|
const element = document.createElement("matrixcode");
|
|
document.body.appendChild(element);
|
|
const renderer = new THREE.WebGLRenderer({ stencil: false, depth: false, precision: "lowp" });
|
|
renderer.sortObjects = true;
|
|
renderer.setSize( window.innerWidth, window.innerHeight );
|
|
renderer.setPixelRatio(window.devicePixelRatio);
|
|
element.appendChild(renderer.domElement);
|
|
const composer = new THREE.EffectComposer( renderer );
|
|
|
|
const fontTexture = new THREE.TextureLoader().load( version.fontTexture );
|
|
|
|
const matrixRenderer = makeMatrixRenderer(renderer, fontTexture, {
|
|
sharpness,
|
|
numColumns,
|
|
animationSpeed, fallSpeed, cycleSpeed,
|
|
glyphSequenceLength,
|
|
numFontColumns,
|
|
hasThunder: version.hasThunder,
|
|
hasSun: version.hasSun,
|
|
isPolar: version.isPolar,
|
|
slant,
|
|
glyphEdgeCrop,
|
|
glyphHeightToWidth,
|
|
fade,
|
|
showComputationTexture: effect === "none",
|
|
raindropLength,
|
|
cycleStyle: version.cycleStyle
|
|
});
|
|
|
|
matrixRenderer.pass.renderToScreen = false;
|
|
composer.addPass( matrixRenderer.pass );
|
|
|
|
const bloomPass = new THREE.UnrealBloomPass( new THREE.Vector2( window.innerWidth, window.innerHeight ), version.bloom.strength, version.bloom.radius, version.bloom.threshold );
|
|
if (effect !== "none") {
|
|
composer.addPass( bloomPass );
|
|
}
|
|
|
|
switch (effect) {
|
|
case "plain":
|
|
composer.addPass(new THREE.ColorMapPass(version.palette, 0.05, 100));
|
|
break;
|
|
case "pride":
|
|
composer.addPass(new THREE.HorizontalColorationPass([
|
|
new THREE.Vector3(1, 0, 0),
|
|
new THREE.Vector3(1, 0.5, 0),
|
|
new THREE.Vector3(1, 1, 0),
|
|
new THREE.Vector3(0, 1, 0),
|
|
new THREE.Vector3(0, 0, 1),
|
|
new THREE.Vector3(0.8, 0, 1),
|
|
], 0.1));
|
|
break;
|
|
case "customStripes":
|
|
const flagColorData = getParam("colors", "0.4,0.15,0.1,0.4,0.15,0.1,0.8,0.8,0.6,0.8,0.8,0.6,1.0,0.7,0.8,1.0,0.7,0.8,").split(",").map(parseFloat);
|
|
const numFlagColors = Math.floor(flagColorData.length / 3);
|
|
const colors = [];
|
|
for (let i = 0; i < numFlagColors; i++) {
|
|
colors.push(new THREE.Vector3(flagColorData[i * 3 + 0], flagColorData[i * 3 + 1], flagColorData[i * 3 + 2]));
|
|
}
|
|
composer.addPass(new THREE.HorizontalColorationPass(colors, 0.1));
|
|
break;
|
|
case "none":
|
|
break;
|
|
case "image":
|
|
const imageURL = getParam("url", "https://upload.wikimedia.org/wikipedia/commons/0/0a/Flammarion_Colored.jpg");
|
|
window.texture2 = new THREE.TextureLoader().load( imageURL );
|
|
composer.addPass(new THREE.ImageOverlayPass(texture2));
|
|
break;
|
|
}
|
|
|
|
composer.passes[composer.passes.length - 1].renderToScreen = true;
|
|
|
|
const windowResize = () => {
|
|
const [width, height] = [window.innerWidth, window.innerHeight];
|
|
matrixRenderer.resize(width, height);
|
|
renderer.setSize(width, height);
|
|
composer.setSize(width, height);
|
|
bloomPass.setSize( window.innerWidth, window.innerHeight );
|
|
}
|
|
window.addEventListener("resize", windowResize, false);
|
|
window.addEventListener("orientationchange", windowResize, false);
|
|
windowResize();
|
|
|
|
const render = () => {
|
|
requestAnimationFrame(render);
|
|
matrixRenderer.render();
|
|
composer.render();
|
|
}
|
|
render();
|
|
|
|
</script>
|
|
</body></html>
|