某音上很火的圣誕樹分享

前些天發現了一個巨牛的人工智能學習網站,通俗易懂,風趣幽默,忍不住分享一下給大家。點擊跳轉到網站。

效果截圖(這里不給動態了,某音到處都是了):
在這里插入圖片描述
源代碼:

<script src="https://cdn.jsdelivr.net/npm/three@0.115.0/build/three.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/three@0.115.0/examples/js/postprocessing/EffectComposer.js"></script>
<script src="https://cdn.jsdelivr.net/npm/three@0.115.0/examples/js/postprocessing/RenderPass.js"></script>
<script src="https://cdn.jsdelivr.net/npm/three@0.115.0/examples/js/postprocessing/ShaderPass.js"></script>
<script src="https://cdn.jsdelivr.net/npm/three@0.115.0/examples/js/shaders/CopyShader.js"></script>
<script src="https://cdn.jsdelivr.net/npm/three@0.115.0/examples/js/shaders/LuminosityHighPassShader.js"></script>
<script src="https://cdn.jsdelivr.net/npm/three@0.115.0/examples/js/postprocessing/UnrealBloomPass.js"></script><div id="overlay"><ul><li class="title">Select Music</li><li><button class="btn" id="btnA" type="button">Snowflakes Falling Down by Simon Panrucker</button></li><li><button class="btn" id="btnB" type="button">This Christmas by Dott</button></li><li><button class="btn" id="btnC" type="button">No room at the inn by TRG Banks</button></li><li><button class="btn" id="btnD" type="button">Jingle Bell Swing by Mark Smeby</button></li><li class="separator">OR</li><li><input type="file" id="upload" hidden /><label for="upload">Upload File</label></li></ul>
</div>
const { PI, sin, cos } = Math;
const TAU = 2 * PI;const map = (value, sMin, sMax, dMin, dMax) => {return dMin + ((value - sMin) / (sMax - sMin)) * (dMax - dMin);
};const range = (n, m = 0) =>Array(n).fill(m).map((i, j) => i + j);const rand = (max, min = 0) => min + Math.random() * (max - min);
const randInt = (max, min = 0) => Math.floor(min + Math.random() * (max - min));
const randChoise = (arr) => arr[randInt(arr.length)];
const polar = (ang, r = 1) => [r * cos(ang), r * sin(ang)];let scene, camera, renderer, analyser;
let step = 0;
const uniforms = {time: { type: "f", value: 0.0 },step: { type: "f", value: 0.0 },
};
const params = {exposure: 1,bloomStrength: 0.9,bloomThreshold: 0,bloomRadius: 0.5,
};
let composer;const fftSize = 2048;
const totalPoints = 4000;const listener = new THREE.AudioListener();const audio = new THREE.Audio(listener);document.querySelector("input").addEventListener("change", uploadAudio, false);const buttons = document.querySelectorAll(".btn");
buttons.forEach((button, index) =>button.addEventListener("click", () => loadAudio(index))
);function init() {const overlay = document.getElementById("overlay");overlay.remove();scene = new THREE.Scene();renderer = new THREE.WebGLRenderer({ antialias: true });renderer.setPixelRatio(window.devicePixelRatio);renderer.setSize(window.innerWidth, window.innerHeight);document.body.appendChild(renderer.domElement);camera = new THREE.PerspectiveCamera(60,window.innerWidth / window.innerHeight,1,1000);camera.position.set(-0.09397456774197047,-2.5597086635726947,24.420789670889008)camera.rotation.set(0.10443543723052419,-0.003827152981119352,0.0004011488708739715)const format = renderer.capabilities.isWebGL2? THREE.RedFormat: THREE.LuminanceFormat;uniforms.tAudioData = {value: new THREE.DataTexture(analyser.data, fftSize / 2, 1, format),};addPlane(scene, uniforms, 3000);addSnow(scene, uniforms);range(10).map((i) => {addTree(scene, uniforms, totalPoints, [20, 0, -20 * i]);addTree(scene, uniforms, totalPoints, [-20, 0, -20 * i]);});const renderScene = new THREE.RenderPass(scene, camera);const bloomPass = new THREE.UnrealBloomPass(new THREE.Vector2(window.innerWidth, window.innerHeight),1.5,0.4,0.85);bloomPass.threshold = params.bloomThreshold;bloomPass.strength = params.bloomStrength;bloomPass.radius = params.bloomRadius;composer = new THREE.EffectComposer(renderer);composer.addPass(renderScene);composer.addPass(bloomPass);addListners(camera, renderer, composer);animate();
}function animate(time) {analyser.getFrequencyData();uniforms.tAudioData.value.needsUpdate = true;step = (step + 1) % 1000;uniforms.time.value = time;uniforms.step.value = step;composer.render();requestAnimationFrame(animate);
}function loadAudio(i) {document.getElementById("overlay").innerHTML ='<div class="text-loading">Please Wait...</div>';const files = ["https://files.freemusicarchive.org/storage-freemusicarchive-org/music/no_curator/Simon_Panrucker/Happy_Christmas_You_Guys/Simon_Panrucker_-_01_-_Snowflakes_Falling_Down.mp3","https://files.freemusicarchive.org/storage-freemusicarchive-org/music/no_curator/Dott/This_Christmas/Dott_-_01_-_This_Christmas.mp3","https://files.freemusicarchive.org/storage-freemusicarchive-org/music/ccCommunity/TRG_Banks/TRG_Banks_Christmas_Album/TRG_Banks_-_12_-_No_room_at_the_inn.mp3","https://files.freemusicarchive.org/storage-freemusicarchive-org/music/ccCommunity/Mark_Smeby/En_attendant_Nol/Mark_Smeby_-_07_-_Jingle_Bell_Swing.mp3",];const file = files[i];const loader = new THREE.AudioLoader();loader.load(file, function (buffer) {audio.setBuffer(buffer);audio.play();analyser = new THREE.AudioAnalyser(audio, fftSize);init();});}function uploadAudio(event) {document.getElementById("overlay").innerHTML ='<div class="text-loading">Please Wait...</div>';const files = event.target.files;const reader = new FileReader();reader.onload = function (file) {var arrayBuffer = file.target.result;listener.context.decodeAudioData(arrayBuffer, function (audioBuffer) {audio.setBuffer(audioBuffer);audio.play();analyser = new THREE.AudioAnalyser(audio, fftSize);init();});};reader.readAsArrayBuffer(files[0]);
}function addTree(scene, uniforms, totalPoints, treePosition) {const vertexShader = `attribute float mIndex;varying vec3 vColor;varying float opacity;uniform sampler2D tAudioData;float norm(float value, float min, float max ){return (value - min) / (max - min);}float lerp(float norm, float min, float max){return (max - min) * norm + min;}float map(float value, float sourceMin, float sourceMax, float destMin, float destMax){return lerp(norm(value, sourceMin, sourceMax), destMin, destMax);}void main() {vColor = color;vec3 p = position;vec4 mvPosition = modelViewMatrix * vec4( p, 1.0 );float amplitude = texture2D( tAudioData, vec2( mIndex, 0.1 ) ).r;float amplitudeClamped = clamp(amplitude-0.4,0.0, 0.6 );float sizeMapped = map(amplitudeClamped, 0.0, 0.6, 1.0, 20.0);opacity = map(mvPosition.z , -200.0, 15.0, 0.0, 1.0);gl_PointSize = sizeMapped * ( 100.0 / -mvPosition.z );gl_Position = projectionMatrix * mvPosition;}
`;const fragmentShader = `varying vec3 vColor;varying float opacity;uniform sampler2D pointTexture;void main() {gl_FragColor = vec4( vColor, opacity );gl_FragColor = gl_FragColor * texture2D( pointTexture, gl_PointCoord ); }`;const shaderMaterial = new THREE.ShaderMaterial({uniforms: {...uniforms,pointTexture: {value: new THREE.TextureLoader().load(`https://assets.codepen.io/3685267/spark1.png`),},},vertexShader,fragmentShader,blending: THREE.AdditiveBlending,depthTest: false,transparent: true,vertexColors: true,});const geometry = new THREE.BufferGeometry();const positions = [];const colors = [];const sizes = [];const phases = [];const mIndexs = [];const color = new THREE.Color();for (let i = 0; i < totalPoints; i++) {const t = Math.random();const y = map(t, 0, 1, -8, 10);const ang = map(t, 0, 1, 0, 6 * TAU) + (TAU / 2) * (i % 2);const [z, x] = polar(ang, map(t, 0, 1, 5, 0));const modifier = map(t, 0, 1, 1, 0);positions.push(x + rand(-0.3 * modifier, 0.3 * modifier));positions.push(y + rand(-0.3 * modifier, 0.3 * modifier));positions.push(z + rand(-0.3 * modifier, 0.3 * modifier));color.setHSL(map(i, 0, totalPoints, 1.0, 0.0), 1.0, 0.5);colors.push(color.r, color.g, color.b);phases.push(rand(1000));sizes.push(1);const mIndex = map(i, 0, totalPoints, 1.0, 0.0);mIndexs.push(mIndex);}geometry.setAttribute("position",new THREE.Float32BufferAttribute(positions, 3).setUsage(THREE.DynamicDrawUsage));geometry.setAttribute("color", new THREE.Float32BufferAttribute(colors, 3));geometry.setAttribute("size", new THREE.Float32BufferAttribute(sizes, 1));geometry.setAttribute("phase", new THREE.Float32BufferAttribute(phases, 1));geometry.setAttribute("mIndex", new THREE.Float32BufferAttribute(mIndexs, 1));const tree = new THREE.Points(geometry, shaderMaterial);const [px, py, pz] = treePosition;tree.position.x = px;tree.position.y = py;tree.position.z = pz;scene.add(tree);
}function addSnow(scene, uniforms) {const vertexShader = `attribute float size;attribute float phase;attribute float phaseSecondary;varying vec3 vColor;varying float opacity;uniform float time;uniform float step;float norm(float value, float min, float max ){return (value - min) / (max - min);}float lerp(float norm, float min, float max){return (max - min) * norm + min;}float map(float value, float sourceMin, float sourceMax, float destMin, float destMax){return lerp(norm(value, sourceMin, sourceMax), destMin, destMax);}void main() {float t = time* 0.0006;vColor = color;vec3 p = position;p.y = map(mod(phase+step, 1000.0), 0.0, 1000.0, 25.0, -8.0);p.x += sin(t+phase);p.z += sin(t+phaseSecondary);opacity = map(p.z, -150.0, 15.0, 0.0, 1.0);vec4 mvPosition = modelViewMatrix * vec4( p, 1.0 );gl_PointSize = size * ( 100.0 / -mvPosition.z );gl_Position = projectionMatrix * mvPosition;}`;const fragmentShader = `uniform sampler2D pointTexture;varying vec3 vColor;varying float opacity;void main() {gl_FragColor = vec4( vColor, opacity );gl_FragColor = gl_FragColor * texture2D( pointTexture, gl_PointCoord ); }`;function createSnowSet(sprite) {const totalPoints = 300;const shaderMaterial = new THREE.ShaderMaterial({uniforms: {...uniforms,pointTexture: {value: new THREE.TextureLoader().load(sprite),},},vertexShader,fragmentShader,blending: THREE.AdditiveBlending,depthTest: false,transparent: true,vertexColors: true,});const geometry = new THREE.BufferGeometry();const positions = [];const colors = [];const sizes = [];const phases = [];const phaseSecondaries = [];const color = new THREE.Color();for (let i = 0; i < totalPoints; i++) {const [x, y, z] = [rand(25, -25), 0, rand(15, -150)];positions.push(x);positions.push(y);positions.push(z);color.set(randChoise(["#f1d4d4", "#f1f6f9", "#eeeeee", "#f1f1e8"]));colors.push(color.r, color.g, color.b);phases.push(rand(1000));phaseSecondaries.push(rand(1000));sizes.push(rand(4, 2));}geometry.setAttribute("position",new THREE.Float32BufferAttribute(positions, 3));geometry.setAttribute("color", new THREE.Float32BufferAttribute(colors, 3));geometry.setAttribute("size", new THREE.Float32BufferAttribute(sizes, 1));geometry.setAttribute("phase", new THREE.Float32BufferAttribute(phases, 1));geometry.setAttribute("phaseSecondary",new THREE.Float32BufferAttribute(phaseSecondaries, 1));const mesh = new THREE.Points(geometry, shaderMaterial);scene.add(mesh);}const sprites = ["https://assets.codepen.io/3685267/snowflake1.png","https://assets.codepen.io/3685267/snowflake2.png","https://assets.codepen.io/3685267/snowflake3.png","https://assets.codepen.io/3685267/snowflake4.png","https://assets.codepen.io/3685267/snowflake5.png",];sprites.forEach((sprite) => {createSnowSet(sprite);});
}function addPlane(scene, uniforms, totalPoints) {const vertexShader = `attribute float size;attribute vec3 customColor;varying vec3 vColor;void main() {vColor = customColor;vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );gl_PointSize = size * ( 300.0 / -mvPosition.z );gl_Position = projectionMatrix * mvPosition;}`;const fragmentShader = `uniform vec3 color;uniform sampler2D pointTexture;varying vec3 vColor;void main() {gl_FragColor = vec4( vColor, 1.0 );gl_FragColor = gl_FragColor * texture2D( pointTexture, gl_PointCoord );}`;const shaderMaterial = new THREE.ShaderMaterial({uniforms: {...uniforms,pointTexture: {value: new THREE.TextureLoader().load(`https://assets.codepen.io/3685267/spark1.png`),},},vertexShader,fragmentShader,blending: THREE.AdditiveBlending,depthTest: false,transparent: true,vertexColors: true,});const geometry = new THREE.BufferGeometry();const positions = [];const colors = [];const sizes = [];const color = new THREE.Color();for (let i = 0; i < totalPoints; i++) {const [x, y, z] = [rand(-25, 25), 0, rand(-150, 15)];positions.push(x);positions.push(y);positions.push(z);color.set(randChoise(["#93abd3", "#f2f4c0", "#9ddfd3"]));colors.push(color.r, color.g, color.b);sizes.push(1);}geometry.setAttribute("position",new THREE.Float32BufferAttribute(positions, 3).setUsage(THREE.DynamicDrawUsage));geometry.setAttribute("customColor",new THREE.Float32BufferAttribute(colors, 3));geometry.setAttribute("size", new THREE.Float32BufferAttribute(sizes, 1));const plane = new THREE.Points(geometry, shaderMaterial);plane.position.y = -8;scene.add(plane);
}function addListners(camera, renderer, composer) {document.addEventListener("keydown", (e) => {const { x, y, z } = camera.position;console.log(`camera.position.set(${x},${y},${z})`);const { x: a, y: b, z: c } = camera.rotation;console.log(`camera.rotation.set(${a},${b},${c})`);});window.addEventListener("resize",() => {const width = window.innerWidth;const height = window.innerHeight;camera.aspect = width / height;camera.updateProjectionMatrix();renderer.setSize(width, height);composer.setSize(width, height);},false);
}
* {box-sizing: border-box;
}body {margin: 0;height: 100vh;overflow: hidden;display: flex;align-items: center;justify-content: center;background: #161616;color: #c5a880;font-family: sans-serif;
}label {display: inline-block;background-color: #161616;padding: 16px;border-radius: 0.3rem;cursor: pointer;margin-top: 1rem;width: 300px;border-radius: 10px;border: 1px solid #c5a880;text-align: center;
}ul {list-style-type: none;padding: 0;margin: 0;
}.btn {background-color: #161616;border-radius: 10px;color: #c5a880;border: 1px solid #c5a880;padding: 16px;width: 300px;margin-bottom: 16px;line-height: 1.5;cursor: pointer;
}
.separator {font-weight: bold;text-align: center;width: 300px;margin: 16px 0px;color: #a07676;
}.title {color: #a07676;font-weight: bold;font-size: 1.25rem;margin-bottom: 16px;
}.text-loading {font-size: 2rem;
}

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/212557.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/212557.shtml
英文地址,請注明出處:http://en.pswp.cn/news/212557.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Spring Boot 3 集成 MyBatis詳解

MyBatis是一款開源的持久層框架&#xff0c;它極大地簡化了與數據庫的交互流程。與類似Hibernate的ORM框架不同&#xff0c;MyBatis更具靈活性&#xff0c;允許開發者直接使用SQL語句與數據庫進行交互。Spring Boot和MyBatis分別是兩個功能強大的框架&#xff0c;它們的協同使用…

Linux shell編程學習筆記34:eval 命令

0 前言 在JavaScript語言中&#xff0c;有一個很特別的函數eval&#xff0c;eval函數可以將字符串當做 JavaScript 代碼執行&#xff0c;返回表達式或值。 在Linux Shell 中也提供了內建命令eval&#xff0c;它是否具有JavaScript語言中eval函數的功能呢&#xff1f; 1 eval命…

GPIO的使用--USART串口通信--傳感器控制數據

目錄 一、串口通信 1、概念 2、原理圖 3、使用步驟 &#xff08;1&#xff09;尋找串口位置 &#xff08;2&#xff09;確定引腳編號 &#xff08;3&#xff09;編寫代碼 4、實驗結果 實驗代碼 main.c usart.c usart.h 一、串口通信 1、概念 串行接口是一種可以將…

DiffiT

本文首發于AIWalker&#xff0c;歡迎關注。 https://arxiv.org/abs/2312.02139 https://github.com/NVlabs/DiffiT 擴散模型以其強大的表達能力和高樣本質量在許多領域得到了新的應用。對于樣本生成&#xff0c;這些模型依賴于通過迭代去噪生成圖像的去噪神經網絡。然而&#x…

SAP UI5 walkthrough step8 Translatable Texts

在這個章節&#xff0c;我們會將一些文本常量獨立出一個資源文件 這樣的話&#xff0c;可以方便這些文本常量被翻譯成任意的語言 這種國際化的操作&#xff0c;我們一般命名為i18n 新建一個文件i18n.properties webapp/i18n/i18n.properties (New) showHelloButtonTextSay …

vue3項目實現文檔 JSON 格式和 Excel 表格的在線預覽,(智能搜索,未驗證)

若要實現文檔 JSON 格式和 Excel 表格的在線預覽&#xff0c;你可以使用第三方庫來實現。對于文檔 JSON 格式&#xff0c;你可以使用 vue-json-pretty 庫來展示美觀的 JSON 數據&#xff1b;對于 Excel 表格&#xff0c;你可以使用 vue-excel-viewer 庫來完成在線預覽。下面是一…

Java、Spring Boot和事務管理

引言 在現代應用程序開發中&#xff0c;確保數據的一致性和可靠性是至關重要的。Java作為一種強大的編程語言&#xff0c;通過其廣泛的生態系統和強大的庫支持&#xff0c;為開發人員提供了構建高性能應用程序的豐富工具。Spring Boot是一個基于Spring框架的項目&#xff0c;它…

圖像的均方差和信噪比計算

圖像的均方差和信噪比計算 一、均方差1、公式2、代碼 二、信噪比1、公式2、代碼 圖像的均方差和信噪比公式及代碼&#xff0c;代碼基于opencv和C實現。 一、均方差 均方誤差&#xff0c;英文簡稱&#xff1a;MSE&#xff0c;英文全稱&#xff1a;“Mean Square Error”。 衡量…

接口測試-Jmeter使用

一、線程組 1.1 作用 線程組就是控制Jmeter用于執行測試的一組用戶 1.2 位置 右鍵點擊‘測試計劃’-->添加-->線程(用戶)-->線程組 1.3 特點 模擬多人操作線程組可以添加多個&#xff0c;多個線程組可以并行或者串行取樣器(請求)和邏輯控制器必須依賴線程組才能…

「Verilog學習筆記」多bit MUX同步器

專欄前言 本專欄的內容主要是記錄本人學習Verilog過程中的一些知識點&#xff0c;刷題網站用的是牛客網 輸入數據暫存在data_reg中&#xff0c;使能信號data_en用打兩拍的方式跨時鐘域傳輸到時鐘域B&#xff0c;最后data_out根據使能信號更新數據。data_en信號在A時鐘域用一個D…

Redis | Redis入門學習介紹及常見原理剖析

關注wx&#xff1a;CodingTechWork Redis介紹 概述 Redis是NoSQL&#xff0c;是key-value分布式內存數據庫。 緩存 緩存是將數據從慢的介質換到快的介質上&#xff0c;提高讀寫效率和性能&#xff0c;并降低數據庫的讀寫成本。內存的速度一般都遠遠大于硬盤的速度&#xf…

三個臭皮匠(ctr,nerdctl,crictl)頂一個諸葛亮(docker)

文章目錄 containerd簡介 nerdctl簡介安裝精簡 Minimal 安裝完整Full 安裝啟動服務 命令參數容器運行容器列出容器詳情容器日志容器進入容器停止容器刪除鏡像列表鏡像拉取鏡像標簽鏡像導出鏡像導入鏡像刪除鏡像構建配置tab鍵配置加速配置倉庫http方式https方式 ctr簡介命令參數…

12、虛函數的應用、虛析構函數

12、虛函數的應用、虛析構函數 運行時類型信息(RTTI)動態類型轉換(dynamic_cast)typeid操作符 虛 析構函數空虛析構函數 一個類中&#xff0c;除了構造函數和靜態成員函數外&#xff0c;任何函數都可以被聲明為虛函數 運行時類型信息(RTTI) 動態類型轉換(dynamic_cast) 用于…

AMC8美國數學競賽歷年真題集在線練習操作指南和2024年備考建議

今天是2023年12月10日&#xff0c;距離2024年的AMC8美國數學競賽的舉辦還有40天時間。據六分成長了解&#xff0c;有一些孩子報名參加了AMC8的機構培訓班系統學習&#xff0c;也有一些孩子選擇了自己自學備考。 有家長問AMC8的培訓是否一定要參加機構的培訓班學習&#xff1f;…

基于SpringBoot+thymeleaf協同過濾算法山河旅游推薦系統(Java畢業設計)

大家好&#xff0c;我是DeBug&#xff0c;很高興你能來閱讀&#xff01;作為一名熱愛編程的程序員&#xff0c;我希望通過這些教學筆記與大家分享我的編程經驗和知識。在這里&#xff0c;我將會結合實際項目經驗&#xff0c;分享編程技巧、最佳實踐以及解決問題的方法。無論你是…

windows端口被占用怎么辦 怎么關閉那個占用的端口

目錄 這是出現的情況怎么解決了1.請打開這玩意2.輸入下面---查詢 先關端口的信息根據id獲得服務 上圖的8888 對應的ip 上圖就是134243.殺死進程134244.重啟服務 這是出現的情況 怎么解決了 1.請打開這玩意 2.輸入下面—查詢 先關端口的信息 netstat -ano過濾信息查詢想要的端…

JavaScript將函數作為參數傳入

其他函數中&#xff0c;是一種常見的編程技巧&#xff0c;稱為回調函數。在 JavaScript 中&#xff0c;函數被視為一等公民&#xff0c;也就是說&#xff0c;它們可以像任何其他類型的值一樣被傳遞、分配和操作。 示例&#xff1a; function greet(name) {console.log(Hello …

央企國企相關

文章目錄&#xff1a; 一&#xff1a;央企國企的區別 二&#xff1a;分類 三&#xff1a;相關 1.考什么 2.有什么崗位 3.什么時候考 4.去哪里報名和查看信息 5.喜歡招聘什么專業 6.其他疑問 一&#xff1a;央企國企的區別 央企國企一共有47萬多個&#xff08;央企131個…

【8.0.34-0 ubuntu 安裝Mysql 后無法鏈接是什么情況】

8.0.34-0 ubuntu 安裝Mysql 后無法鏈接是什么情況 檢查日志解決辦法 檢查日志 如果檢查一下帳號密碼沒問題看一下日志&#xff1a; Plugin mysql_native_password reported: mysql_native_password is deprecated and will be removed in a future release. Please use cachi…

java中的context對象?

java中的context對象&#xff1f; 大家好&#xff0c;我是微賺淘客系統的小編&#xff0c;也是冬天不穿秋褲&#xff0c;天冷也要風度的程序猿&#xff01;今天&#xff0c;我們將深入研究Java中的神秘利器——Context對象。在Java開發中&#xff0c;Context對象扮演著重要的角…