tone实现可视化多节奏声音输出效果代码

代码语言:html

所属分类:多媒体

代码描述:tone实现可视化多节奏声音输出效果代码,点击左侧音乐图标开始演奏,右侧色板可调颜色。

代码标签: tone 可视化 节奏 声音 输出

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  


  
  
<style>
@charset "UTF-8";
body,
.scene, .container::after, .container::before,
.element::after,
.element::before, .container,
.element, .sound {
  position: absolute;
  transform-style: preserve-3d;
}

.container::after, .container::before,
.element::after,
.element::before, .container,
.element, .sound {
  display: flex;
  align-items: center;
  justify-content: center;
}

body,
.scene {
  display: grid;
  place-self: center;
}
body > *,
.scene > * {
  place-self: center;
}

:root {
  --perspective: 400vmin;
}

*,
*::after,
*::before {
  margin: 0;
  border: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  perspective: var(--perspective);
  background: var(--background, #000);
}

@media screen and (orientation: portrait) {
  .themes {
    --test: portrait;
  }
}
@media screen and (orientation: landscape) {
  .themes {
    --test: landscape;
  }
}
.themes.horizontal {
  width: 100vw;
}
.themes.vertical {
  height: 100vh;
}
.themes-trigger, .themes-menu {
  position: absolute;
}
.themes-trigger, .themes-select {
  height: 48px;
  width: 48px;
  -webkit-appearance: none;
     -moz-appearance: none;
          appearance: none;
  border-radius: 50%;
  cursor: pointer;
}
.themes-menu {
  display: flex;
  overflow: hidden;
  will-change: transform;
  transition: transform 0.5s ease-in-out;
  /* width */
  /* Track */
  /* Handle */
  /* Handle on hover */
}
.themes-menu::-webkit-scrollbar-track {
  background: transparent;
}
.themes-menu::-webkit-scrollbar-thumb {
  background: var(--stroke, gray);
  border-radius: 10px;
}
.themes-menu::-webkit-scrollbar-thumb:hover {
  background: var(--hover, darkgray);
}
.themes.horizontal .themes-menu {
  flex-wrap: nowrap;
  overflow-x: scroll;
  height: 78px;
  width: calc(100% - 48px - 20px);
  bottom: -78px;
  /* width */
}
.themes.horizontal .themes-menu::-webkit-scrollbar {
  height: 10px;
}
.themes.vertical .themes-menu {
  flex-wrap: wrap;
  overflow-y: scroll;
  height: calc(100% - 48px - 20px);
  width: 78px;
  right: -78px;
  /* width */
}
.themes.vertical .themes-menu::-webkit-scrollbar {
  width: 10px;
}
.themes-select {
  flex: 0 0 48px;
  border: 2.5px solid var(--stroke);
  background: linear-gradient(var(--background) 0% 25%, var(--stroke) 25% 50%, var(--fill) 50% 75%, var(--hover) 75% 100%);
}
.themes.horizontal .themes-select {
  margin: 10px 5px;
}
.themes.vertical .themes-select {
  margin: 5px 10px;
}
.themes-trigger {
  right: 20px;
  bottom: 10px;
  background: conic-gradient(red, orange, yellow, green, blue, indigo, violet, red);
}
.themes-trigger, .themes-trigger::after {
  display: flex;
  justify-content: center;
  align-items: center;
}
.themes-trigger::after {
  content: "X";
  opacity: 0;
  border-radius: 50%;
  height: 48px;
  width: 48px;
  font-size: 32px;
  font-weight: bold;
  color: #000;
  transition: 0.35s ease-in-out;
  transition-property: opacity, color;
}
.themes-trigger:hover::after {
  color: #fff;
}
.themes-trigger:checked::after {
  opacity: 1;
}
.themes.horizontal .themes-trigger {
  right: 10px;
  bottom: 20px;
}
.themes.horizontal .themes-trigger:checked + .themes-menu {
  transform: translatey(-78px);
}
.themes.vertical .themes-trigger {
  right: 20px;
  bottom: 10px;
}
.themes.vertical .themes-trigger:checked + .themes-menu {
  transform: translatex(-78px);
}

:root {
  --time: 1s;
  --delay: 0.0204081633s;
  --elements: 7;
  --animation: paused;
}

.sound {
  -webkit-appearance: none;
     -moz-appearance: none;
          appearance: none;
  bottom: 10px;
  left: 10px;
  background: none;
  cursor: pointer;
  font-size: 2.5em;
}
.sound::after {
  content: "🎵";
  color: transparent;
  text-shadow: 0 0 0 var(--fill);
}

.container::after, .container::before,
.element::after,
.element::before {
  content: "";
}

.element::after {
  background: var(--fill);
  left: var(--position-element);
  border-radius: 50%;
  border: 0.25vmin solid var(--stroke);
  height: 2vmin;
  width: 2vmin;
  -webkit-animation: rotate var(--time, 1s) var(--delay, 0s) linear infinite;
          animation: rotate var(--time, 1s) var(--delay, 0s) linear infinite;
  -webkit-animation-play-state: var(--animation);
          animation-play-state: var(--animation);
  transform-origin: calc(-1 * var(--position-element)) center;
}
.element::before {
  border-radius: 50%;
  border: 0.25vmin solid var(--hover);
  height: var(--diameter-circle);
  width: var(--diameter-circle);
  opacity: 0.5;
}
.element:nth-child(1) {
  --position-element: 3.875vmin;
  --diameter-circle: 10vmin;
  --time: 1s;
}
.element:nth-child(2) {
  --position-element: 6.125vmin;
  --diameter-circle: 14.5vmin;
  --time: 1.0204081633s;
}
.element:nth-child(3) {
  --position-element: 8.375vmin;
  --diameter-circle: 19vmin;
  --time: 1.0408163265s;
}
.element:nth-child(4) {
  --position-element: 10.625vmin;
  --diameter-circle: 23.5vmin;
  --time: 1.0612244898s;
}
.element:nth-child(5) {
  --position-element: 12.875vmin;
  --diameter-circle: 28vmin;
  --time: 1.0816326531s;
}
.element:nth-child(6) {
  --position-element: 15.125vmin;
  --diameter-circle: 32.5vmin;
  --time: 1.1020408163s;
}
.element:nth-child(7) {
  --position-element: 17.375vmin;
  --diameter-circle: 37vmin;
  --time: 1.1224489796s;
}

@-webkit-keyframes rotate {
  100% {
    transform: rotate3d(0, 0, -1, 1turn);
  }
}

@keyframes rotate {
  100% {
    transform: rotate3d(0, 0, -1, 1turn);
  }
}
</style>


  
  
</head>

<body translate="no">
  
  <script >
      function getVariableCSS(name, source = document.documentElement) {
	return getComputedStyle(source).getPropertyValue(`--${name}`);
}

function setVariableCSS(name, value, source = document.documentElement) {
	return source.style.setProperty(`--${name}`, value);
}

function appendChildren(children, parent = document.body) {
	if (Array.isArray(children)) parent.append(...children);
	else parent.append(children);

	return parent;
}

function createElements(
	length,
	clone = document.createElement("div"),
	deep = true
) {
	return Array.from({ length }, () => clone.cloneNode(deep));
}

function createElement(className, tag = "div") {
	const element = document.createElement(tag);

	if (className) element.className = className;

	return element;
}

function setupScene(node) {
	const scene = appendChildren(node, createElement("scene"));

	appendChildren(scene);

	return scene;
}

function createCube() {
	return appendChildren(
		createElements(6, createElement("face")),
		createElement("cube")
	);
}

function createCubes(cubes = 0, cube = createCube()) {
	return appendChildren(
		createElements(cubes > 0 ? cubes : getVariableCSS("cubes"), cube),
		createElement("cubes")
	);
}
  </script>
<script>
    const CSS_VARIABLES = ["background", "stroke", "fill", "hover"];

const OTHER_THEMES = createThemes([
	["222831", "393E46", "00ADB5", "EEEEEE"],
	["071952", "0B666A", "35A29F", "97FEED"],
	["8C3333", "557A46", "7A9D54", "F2EE9D"],
	["1D5D9B", "F4D160", "75C2F6", "FBEEAC"],
	["331D2C", "3F2E3E", "A78295", "EFE1D1"],
	["1D5B79", "468B97", "EF6262", "F3AA60"],
	["6527BE", "9681EB", "45CFDD", "A7EDE7"],
	["4C4B16", "898121", "E7B10A", "F7F1E5"],
	["3F2305", "61481c", "e6b325", "ffd95a"],
	["6A2C70", "B83B5E", "F08A5D", "F9ED69"],
	["252A34", "FF2E63", "08D9D6", "EAEAEA"],
	["252A34", "08D9D6", "FF2E63", "EAEAEA"],
	["252A34", "EAEAEA", "FF2E63", "08D9D6"],
	["424874", "DCD6F7", "A6B1E1", "F4EEFF"],
	["1B262C", "0F4C75", "3282B8", "BBE1FA"],
	["364F6B", "FC5185", "F5F5F5", "3FC1C9"],
	["364F6B", "3FC1C9", "F5F5F5", "FC5185"],
	["364F6B", "F5F5F5", "3FC1C9", "FC5185"],
	["212121", "323232", "0D7377", "14FFEC"],
	["2C3639", "3F4E4F", "A27B5C", "DCD7C9"],
	["2D4059", "EA5455", "F07B3F", "FFD460"],
	["3E4149", "444F5A", "FF9999", "FFC8C8"],
	["48466D", "3D84A8", "46CDCF", "ABEDD8"],
	["1E212D", "B68973", "EABF9F", "FAF3E0"],
	["850E35", "EE6983", "FFC4C4", "FFF5E4"],
	["40513B", "609966", "9DC08B", "EDF1D6"],
	["322653", "8062D6", "9288F8", "FFD2D7"],
	["461959", "7A316F", "CD6688", "AED8CC"],
	["3E001F", "982176", "F11A7B", "FFE5AD"]
]);

const THEMES = createThemes([
	["142d4c", "385170", "9fd3c7", "ececec"],
	.........完整代码请登录后点击上方下载按钮下载查看

网友评论0