three实现三维粒子组成的圣诞树带音乐旋转拉伸动画效果代码

代码语言:html

所属分类:三维

代码描述:three实现三维粒子组成的圣诞树带音乐旋转拉伸动画效果代码,音乐祥和温暖。

代码标签: three 圣诞树 粒子 旋转 音乐

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

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

<head>

  <meta charset="UTF-8">

  <meta name="viewport" content="width=device-width, initial-scale=1">

  
  
<style>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  overflow: hidden;
  background: #00101a;
}
body {
  font-family: fino-sans, sans-serif;
  -webkit-font-smoothing: antialiased;
  font-weight: 700;
  font-style: normal;
}
.webgl {
  position: fixed;
  width: 100vw;
  height: 100vh;
}

button {
  position: absolute;
  bottom: 3rem;
  left: 50%;
  transform: translateX(-50%);
  -webkit-appearance: none;
  background: crimson;
  color: white;
  font: inherit;
  font-size: 1.5rem;
  padding: 0.75rem 2.5rem;
  border: none;
  border-radius: 1.75rem;
  cursor: pointer;
}

h1 {
  position: absolute;
  color: white;
  top: 3rem;
  left: 3rem;
  right: 3rem;
  text-align: center;
  font-size: 3rem;
}

footer {
  position: absolute;
  left: 0.5rem;
  bottom: 0.5rem;
  color: white;
  font-family: monospace;
  font-size: 14px;
  font-weight: 400;
}

a {
  color: inherit;
}
</style>


</head>

<body >
  <canvas class="webgl"></canvas>
<h1></h1>
<button id="play-music" type="button">Play music</button>

<script type="x-shader/x-vertex" id="vertexShader">
  uniform float uTime;
uniform float uSize;
attribute float aScale;
attribute vec3 aColor;
attribute float phi;
attribute float random;
//attribute float random1;
varying vec2 vUv;
varying vec3 vColor;

void main() {
  float angle = phi;
  angle += uTime * random;
  angle = mod(angle, 39.3);
  float radius = 0.065 * angle;
  float rand = (random - 0.5) * 0.05 * pow(angle, .75);
  vec3 myOffset =
      vec3(radius * cos(angle) + rand,
           2.9 - 2.7 * radius + rand +
               0.1 * (random - .5) * pow(angle, .25) * sin(2.0 * uTime),
           radius * sin(angle) + rand);
  vec3 myPosition = myOffset;
  vec4 modelPosition = modelMatrix * vec4(myPosition, 1.0);

  vec4 viewPosition = viewMatrix * modelPosition;
  viewPosition.xyz += position * aScale * uSize;
  gl_Position = projectionMatrix * viewPosition;

  vColor = aColor;
  vUv = uv;
}
</script>

<script type="x-shader/x-fragment" id="fragmentShader">
  varying vec3 vColor;
varying vec2 vUv;

void main() {
  vec2 uv = vUv;
  vec3 color = vColor;
  float strength = distance(uv, vec2(0.5));
  strength *= 2.0;
  strength = 1.0 - strength;
  gl_FragColor = vec4(strength * color, 1.0);
}
</script>

<script type="x-shader/x-vertex" id="vertexShaderExt">
  #define M_PI 3.1415926535897932384626433832795
varying.........完整代码请登录后点击上方下载按钮下载查看

网友评论0