three+webgl实现点击生长的荷花盛开动画效果代码
代码语言:html
所属分类:动画
代码描述:three+webgl实现点击生长的荷花盛开动画效果代码,任意位置点击,荷花会生长到指定位置绽放。
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<style>
html, body {
overflow: hidden;
padding: 0;
margin: 0;
}
.container {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100vh;
display: flex;
flex-direction: column-reverse;
align-items: start;
}
.clean-btn {
z-index: 1;
font-family: sans-serif;
font-size: 15px;
color: white;
text-shadow: 0 0 10px #000000;
user-select: none;
padding: 0 0 15px 25px;
cursor: pointer;
text-decoration: underline;
opacity: .5;
}
canvas {
position: absolute;
top: 0;
left: 0;
display: block;
}
.name {
position: fixed;
top: 50%;
left: 50%;
width: 100%;
transform: translate(-50%, -50%);
color: white;
text-align: center;
font-size: 4vw;
text-shadow: 0 0 5px #000000;
user-select: none;
pointer-events: none;
}
@media all and (min-width: 640px) {
.name {
font-size: 45px
}
}
</style>
</head>
<body>
<div class="container">
<canvas id="canvas"></canvas>
<div class="clean-btn">
clean the screen
</div>
</div>
<div class="name">
Click To Add Flowers
</div>
<script type="x-shader/x-fragment" id="fragmentShader">
#define PI 3.14159265359
uniform float u_ratio;
uniform vec2 u_cursor;
uniform float u_stop_time;
uniform float u_clean;
uniform vec2 u_stop_randomizer;
uniform sampler2D u_texture;
varying vec2 vUv;
// --------------------------------
// 2D noise
vec3 mod289(vec3 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }
vec2 mod289(vec2 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }
vec3 permute(vec3 x) { return mod289(((x*34.0)+1.0)*x); }
float snoise(vec2 v) {
const vec4 C = vec4(0.211324865405187, 0.366025403784439, -0.577350269189626, 0.024390243902439);
vec2 i = floor(v + dot(v, C.yy));
vec2 x0 = v - i + dot(i, C.xx);
vec2 i1;
i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
vec4 x12 = x0.xyxy + C.xxzz;
x12.xy -= i1;
i = mod289(i);
vec3 p = permute(permute(i.y + vec3(0.0, i1.y, 1.0)) + i.x + vec3(0.0, i1.x, 1.0));
vec3 m = max(0.5 - vec3(dot(x0, x0), dot(x12.xy, x12.xy), dot(x12.zw, x12.zw)), 0.0);
m = m*m;
m = m*m;
vec3 x = 2.0 * fract(p * C.www) - 1.0;
vec3 h = abs(x) - 0.5;
vec3 ox = floor(x + 0.5);
vec3 a0 = x - ox;
m *= 1.79284291400159 - 0.85373472095314 * (a0*a0 + h*h);
vec3 g;
g.x = a0.x * x0.x + h.x * x0.y;
g.yz = a0.yz * x12.xz + h.yz * x12.yw;
return 130.0 * dot(m, g);
}
float get_flower_shape(vec2 _p, float _pet_n, float _angle, float _outline) {
_angle *= 3.;
_p = vec2(_p.x * cos(_angle) - _p.y * sin(_angle),
_p.x * sin(_angle) + _p.y * cos(_angle));
float a = atan(_p.y, _p.x);
float flower_sectoral_shape = pow(abs(sin(a * _pet_n)), .4) + .25;
vec2 flower_size_range = vec2(.03, .1);
float size = flower_size_range[0] + u_stop_randomizer[0] * flower_size_range[1];
float flower_radial_shape = pow(length(_p) / size, 2.);
flower_radial_shape -= .1 * sin(8. * a); // add noise
flower_radial_shape = max(.1, flower_radial_shape);
flower_radial_shape += smoothstep(0., 0.........完整代码请登录后点击上方下载按钮下载查看
网友评论0