HW music (Copy 14739)
✨ Orang Utan
<html> <head> <!--เปลี่ยนเสียงดนตรี โดยการเลือกเพลง และกดปุ่มให้มันเล่น--> <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous"> <title>music</title> <meta name='viewport' content='width=device-width, initial-scale=1'> <script src='https://kit.fontawesome.com/a076d05399.js' crossorigin='anonymous'></script> <style> body{ --color:#48C9B0; --pic0:linear-gradient(#FF5A93 50%,#5A78FF); --pic1:url(https://cdn.discordapp.com/attachments/946646413926891540/948077496346230854/IMG_7910.png) no-repeat center -5px; --pic2:url(https://cdn.discordapp.com/attachments/946646413926891540/948077496673382491/IMG_7911.png) no-repeat center 0px; --pic3: url(https://cdn.discordapp.com/attachments/946646413926891540/948091911992926228/IMG_7915.png) no-repeat fixed center -5px; background:var(--color); margin: 0; justify-content: center; align-items: center; display: flex; background-size: cover; } .plays{ height:40px; width:500px; margin: auto; position:absolute; top:480px; } .sing{ height: 380px; width:380px; border-radius: 200px; margin:auto; top:40px; position:absolute; transform-style:preserve-3d; transform: rotatex(0deg) rotatey(0deg) rotatez(360deg); animation: cycle 3s infinite linear; } #sing{ background:var(--pic0); background-size:740px; background-position:center; background-repeat:no-repeat; } #singcenter{ background:var(--color); height:50px; width:50px; border-radius:40px; margin-bottom:200px; position:absolute; } @keyframes cycle { from {transform:rotateZ(0deg);} to{transform:rotatZ(180deg);} } #box{ background:white; height:70px; width:500px; position:absolute; margin: auto; top:530px; } p{ font-size:1em; color:#111; position:absolute; margin:auto; } #order1 { top:500; } #dis1{ position:relative; margin-left:100px; top:30px; } #dis2{ position:relative; margin-left:30px;; top:33px; width:200px; } #dis3{ position:relative; margin-left:30px; top:30px; } #playStart{ margin:auto; z-index:1; margin-top:430px; width:100px; height:30px; } #name{ margin-left:170px; font-family:; margin-top:20px; } </style> </head> <body> <div class="sing" id="sing"></div> <div id="singcenter"> </div> <select value="play0" id="plays" name="playlist" class="plays"> <option value="play0">โปรดเลือกเพลง</option> <option value="play1">play1</option> <option value="play2">play2</option> <option value="play3">play3</option> </select> <button id="playStart" onclick="selectPLAY()" ><i class="fas fa-play" ></i></button> <div id="box"> <p id="name"> คุณยังไม่ได้เลือกเพลง</p> <!--<p id="order1"> โปรด ปรับเสียง ก่อน play </p> <a id="dis1"><i class="fas fa-volume-down"></i></a> <input id="dis2"id="sound"type="range" min="0" max="10" value="5" > <a id="dis3"><i class="fas fa-volume-up"></i></a>--> </div> <script> let [C4,D4b,D4,E4b,E4,F4,G4b,G4,A4b,A4,B4b,B4] = [3,4,5,6,7,8,9,10,11,12,13,14]; let [C5,D5b,D5,E5b,E5,F5,G5b,G5,A5b,A5,B5b,B5] = [15,16,17,18,19,20,21,22,23,24,25,26]; let [C6,D6b,D6,E6b,E6,F6,G6b,G6,A6b,A6,B6b,B6] = [27,28,29,30,31,32,33,34,35,36,37,38]; let [C7,D7b,D7,E7b,E7,F7,G7b,G7,A7b,A7,B7b,B7] = [39,40,41,42,43,44,45,46,47,48,49,50]; <!--เพลงที่ 1------------------------------------------------------------start--------> let melody1 =[C6,-1,D6,-1,-1,C6,-1,A5,-1,-1,G5,-1,A5,-1,-1,G5,-1,E5,-1,-1,-1,-1, //เมื่อคิดให้ดีโลกนี้ประหลาด D5,-1,E5,-1,-1,G5,-1,A5,-1,-1,G5,-1,C5,-1,-1,-1, //บุพเพสันนิวาส E5,-1,-1,G5,-1,A5,-1,-1,C6,-1,D6,-1,-1,C6,-1,A5,-1,-1,-1,-1,-1,-1, //ที่ประสาทความรักภิรมย์ C6,-1,-1,-1,D6,-1,-1,C6,-1,-1,E6,-1,-1,-1,-1, //คู่ใครคู่เขา C6,-1,A5,-1,G5,-1,-1,E5,-1,A5,-1,-1,-1, //รักยังคอยเฝ้าชม G5,-1,E5,-1,D5,-1,-1,C5,-1,D5,E5,-1,-1,-1,-1,-1, //คอยภิรมย์เรื่อยไป C6,-1,D6,-1,-1,C6,-1,A5,-1,-1,G5,-1,A5,-1,-1,G5,-1,E5,-1,-1,-1,-1, //ขอบน้ำขวางหน้าขอบฟ้าขวางกั้น D5,-1,E5,-1,-1,G5,-1,A5,-1,-1,G5,-1,C5,-1,-1,-1, //บุพเพยังสรรค์ประสบ E5,-1,-1,G5,-1,A5,-1,-1,C6,-1,D6,-1,-1,C6,-1,A5,-1,-1,-1,-1,-1,-1, //ให้ได้พบสบรักกันได้ C6,-1,-1,-1,D6,-1,-1,-1,C6,-1,-1,E6,-1,-1,-1,-1, //ห่างกันแค่ไหน C6,-1,A5,-1,G5,-1,-1,E5,-1,-1,A5,-1,-1,-1, //เขาสูงบังกั้นไว้ G5,-1,E5,-1,D5,-1,-1,-1,C5,-1,-1,C5,C5 //รักยังได้บูชา ] <!--เพลงที่ 2------------------------------------------------------------start--------> let melody2 = [E5,-1,D5,-1,E5,-1,D5,-1,C5,-1,-1,-1, //แม้ชีวิตได้ผ่าน E5,-1,-1,E5,-1,D5,-1,E5,-1,G5,-1,-1,-1,-1,-1,-1,-1, //เลยวัยแห่งความฝัน A5,-1,G5,-1,F5,-1,G5,-1,-1,-1,G5,-1,F5,-1,G5,-1,-1,-1,-1,-1,-1,-1, //วันที่ผ่านมาไร้จุดหมาย E5,-1,D5,-1,E5,-1,D5,-1,C5,-1,-1,-1, //ฉันเรียนรู้เพื่ออยู่ E5,-1,-1,-1,E5,-1,D5,-1,E5,-1,G5,-1,-1,-1,-1,-1,-1, //เพียงตัวและจิตใจ F5,-1,F5,-1,F5,-1,D5,-1,E5,-1,D5,-1,C5,-1,-1,-1,-1,-1,-1, //เป็นมิตรแท้ที่ดีต่อกัน E5,-1,D5,-1,E5,-1,D5,-1,C5,-1,-1,-1, //เหมือนชีวิตผันผ่าน E5,-1,-1,E5,-1,D5,-1,E5,-1,G5,-1,-1,-1,-1,-1,-1, //คืนวันอันเปลี่ยวเหงา A5,-1,G5,-1,F5,-1,G5,-1,-1,-1,G5,-1,A5,-1,G5,-1,-1,-1,-1,-1,-1,-1, //ตัวเป็นของเราใจของใคร E5,-1,D5,-1,E5,-1,D5,-1,C5,-1,-1,-1, //มีชีวิตเพื่อสู้ E5,-1,-1,-1,E5,-1,D5,-1,E5,-1,G5,-1,-1,-1,-1,-1,-1, //คืนวันอันโหดร้าย F5,-1,F5,-1,F5,-1,E5,-1,D5,-1,E5,-1,D5,-1,C5,-1,-1,-1 //คืนที่ตัวกับใจไม่ตรงกัน ] <!--เพลงที่ 3------------------------------------------------------------start--------> let melody3 = [E4,-1,-1,G4,-1,G4,-1,-1,-1,E4,-1,G4,-1,-1,-1,D4,-1,E4,-1,-1,-1,-1,-1,-1,-1,-1,-1, E4,-1,-1,G4,-1,G4,-1,-1,-1,G4,-1,C5,-1,-1,-1,B4,-1,A4,-1,-1,-1,-1,-1,-1,-1,-1,-1, E4,-1,-1,G4,-1,G4,-1,-1,-1,E4,-1,G4,-1,-1,D4,-1,-1,E4,-1,-1,-1,-1,-1,G4,-1,-1,C4, -1,-1,-1,-1,-1,-1,-1,-1,C4,-1,D4,-1,E4,-1,-1,-1,-1,E4,-1,D4,-1,-1,-1,C4,-1,C4,-1,] <!--เพลงที่ 4------------------------------------------------------------start--------> function selectPLAY() { var play = document.getElementById("plays").value; if (play == "play1"){ playNotes(melody1, 1/6); document.getElementById("name").innerHTML = "เพลงแรกเลย"; document.getElementById("sing").style.background = "var(--pic1)"; document.body.style.background = "#F4D03F"; document.getElementById("singcenter").style.background = "#F4D03F"; } else if (play == "play2"){ playNotes(melody2, 1/5); document.getElementById("name").innerHTML = "เพลงอะไรน้าาา"; document.getElementById("sing").style.background = "var(--pic2)"; document.body.style.background = "#5499C7"; document.getElementById("singcenter").style.background = "#5499C7"; } else if (play == "play3"){ playNotes(melody3, 1/6); document.getElementById("name").innerHTML = "คุ้นบ้าไหม"; document.getElementById("sing").style.background = "var(--pic3)"; document.body.style.background = "#F5B041"; document.getElementById("singcenter").style.background = "#F5B041"; } else if (play == "play0"){ document.getElementById("name").innerHTML = "คุณยังไม่ได้เลือกเพลงนะ"; document.getElementById("sing").style.background = "var(--pic0)"; document.body.style.background = "#48C9B0"; document.getElementById("singcenter").style.background = "#48C9B0"; } } let playTone = (frequqncy, timeToPlay) => { let audioContext = new (window.AudioContext || window.webkitAudioContext)() let startTime = audioContext.currentTime let oscillator = audioContext.createOscillator() let gain = audioContext.createGain() let noteLenght = .5 /*v = document.getElementById("sound").value; v = v/10;*/ oscillator.frequency.value = frequqncy oscillator.connect(gain) gain.connect(audioContext.destination) gain.gain.setValueAtTime(0.5, startTime + timeToPlay) gain.gain.linearRampToValueAtTime(0, startTime +timeToPlay + noteLenght) oscillator.start(startTime + timeToPlay) oscillator.stop(startTime + timeToPlay+noteLenght) } const playNotes = (notes, secoundsperBeat) => { notes.forEach((noteNumber, index) => { if (noteNumber !== -1) { let frequency = 220 * 2 ** (noteNumber /12) let beatToplay = index + (index % 2) / 6 let timeToPlay = beatToplay * secoundsperBeat playTone(frequency, timeToPlay) } } )} </script></body></html>