<!doctype html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HTML5 canvas绚丽雷达扫描光环特效</title>
<link rel='stylesheet' href='css/reset.css'>
<link rel="stylesheet" type="text/css" href="css/default.css">
<script src='js/prefixfree.min.js'></script>
<style type="text/css">
body {
background: #000;
}
canvas {
display: block;
}
#gui {
left: 0;
position: fixed;
top: 0;
}
</style>
<!--[if IE]>
<script src="http://libs.useso.com/js/html5shiv/3.7/html5shiv.min.js"></script>
<![endif]-->
</head>
<body>
<div class="htmleaf-container">
<header class="htmleaf-header">
<h1>HTML5 canvas绚丽雷达扫描光环特效</h1>
<div class="htmleaf-links">
<a class="htmleaf-icon icon-htmleaf-home-outline" href="http://www.jb51.net/" title="脚本之家" target="_blank"><span> 脚本之家</span></a>
<a class="htmleaf-icon icon-htmleaf-arrow-forward-outline" href="http://www.jb51.net/" title="返回下载页" target="_blank"><span> 返回下载页</span></a>
</div>
</header>
<div id="gui"></div>
</div>
<script src='js/stopExecutionOnTimeout.js?t=1'></script>
<script src='http://libs.useso.com/js/jquery/1.11.0/jquery.min.js'></script>
<script src='js/dat.gui.min.js'></script>
<script src='js/sketch.min.js'></script>
<script>
var sketch = Sketch.create(), center = {
x: sketch.width / 2,
y: sketch.height / 2
}, orbs = [], dt = 1, opt = {
total: 0,
count: 100,
spacing: 2,
speed: 65,
scale: 1,
jitterRadius: 0,
jitterHue: 0,
clearAlpha: 10,
toggleOrbitals: true,
orbitalAlpha: 100,
toggleLight: true,
lightAlpha: 5,
clear: function () {
sketch.clearRect(0, 0, sketch.width, sketch.height), orbs.length = 0;
}
};
var Orb = function (x, y) {
var dx = x / opt.scale - center.x / opt.scale, dy = y / opt.scale - center.y / opt.scale;
this.angle = atan2(dy, dx);
this.lastAngle = this.angle;
this.radius = sqrt(dx * dx + dy * dy);
this.size = this.radius / 300 + 1;
this.speed = random(1, 10) / 300000 * this.radius + 0.015;
};
Orb.prototype.update = function () {
this.lastAngle = this.angle;
this.angle += this.speed * (opt.speed / 50) * dt;
this.x = this.radius * cos(this.angle);
this.y = this.radius * sin(this.angle);
};
Orb.prototype.render = function () {
if (opt.toggleOrbitals) {
var radius = opt.jitterRadius === 0 ? this.radius : this.radius + random(-opt.jitterRadius, opt.jitterRadius);
radius = opt.jitterRadius != 0 && radius < 0 ? 0.001 : radius;
sketch.strokeStyle = 'hsla( ' + ((this.angle + 90) / (PI / 180) + random(-opt.jitterHue, opt.jitterHue)) + ', 100%, 50%, ' + opt.orbitalAlpha / 100 + ' )';
sketch.lineWidth = this.size;
sketch.beginPath();
if (opt.speed >= 0) {
sketch.arc(0, 0, radius, this.lastAngle, this.angle + 0.001, false);
} else {
sketch.arc(0, 0, radius, this.angle, this.lastAngle + 0.001, false);
}
;
sketch.stroke();
sketch.closePath();
}
;
if (opt.toggleLight) {
sketch.lineWidth = 0.5;
sketch.strokeStyle = 'hsla( ' + ((this.angle + 90) / (PI / 180) + random(-opt.jitterHue, opt.jitterHue)) + ', 100%, 70%, ' + opt.lightAlpha / 100 + ' )';
sketch.beginPath();
sketch.moveTo(0, 0);
sketch.lineTo(this.x, this.y);
sketch.stroke();
}
;
};
var createOrb = function (config) {
var x = config && config.x ? config.x : sketch.mouse.x, y = config && config.y ? config.y : sketch.mouse.y;
orbs.push(new Orb(x, y));
};
var turnOnMove = function () {
sketch.mousemove = createOrb;
};
var turnOffMove = function () {
sketch.mousemove = null;
};
sketch.mousedown = function () {
createOrb();
turnOnMove();
};
sketch.mouseup = turnOffMove;
sketch.resize = function () {
center.x = sketch.width / 2;
center.y = sketch.height / 2;
sketch.lineCap = 'round';
};
sketch.setup = function () {
while (opt.count--) {
if (window.CP.shouldStopExecution(1)) {
break;
}
createOrb({
x: random(sketch.width / 2 - 300, sketch.width / 2 + 300),
y: random(sketch.height / 2 - 300, sketch.height / 2 + 300)
});
}
;
window.CP.exitedLoop(1);
};
sketch.clear = function () {
sketch.globalCompositeOperation = 'destination-out';
sketch.fillStyle = 'rgba( 0, 0, 0 , ' + opt.clearAlpha / 100 + ' )';
sketch.fillRect(0, 0, sketch.width, sketch.height);
sketch.globalCompositeOperation = 'lighter';
};
sketch.update = function () {
dt = sketch.dt < 0.1 ? 0.1 : sketch.dt / 16;
dt = dt > 5 ? 5 : dt;
var i = orbs.length;
opt.total = i;
while (i--) {
if (window.CP.shouldStopExecution(2)) {
break;
}
orbs[i].update();
}
window.CP.exitedLoop(2);
};
sketch.draw = function () {
sketch.save();
sketch.translate(center.x, center.y);
sketch.scale(opt.scale, opt.scale);
var i = orbs.length;
while (i--) {
if (window.CP.shouldStopExecution(3)) {
break;
}
orbs[i].render();
}
window.CP.exitedLoop(3);
sketch.restore();
};
gui = new dat.GUI({ autoPlace: false });
gui.add(opt, 'total').name('Total Orbitals').listen();
gui.add(opt, 'speed').min(-300).max(300).step(1).name('Speed');
gui.add(opt, 'scale').min(0.5).max(5).step(0.001).name('Scale');
gui.add(opt, 'jitterRadius').min(0).max(5).step(0.001).name('Radius Jitter');
gui.add(opt, 'jitterHue').min(0).max(90).step(1).name('Hue Jitter');
gui.add(opt, 'clearAlpha').min(0).max(100).step(1).name('Clear Alpha');
gui.add(opt, 'toggleOrbitals').name('Toggle Orbitals');
gui.add(opt, 'orbitalAlpha').min(0).max(100).step(1).name('Orbital Alpha');
gui.add(opt, 'toggleLight').name('Toggle Light');
gui.add(opt, 'lightAlpha').min(0).max(100).step(1).name('Light Alpha');
gui.add(opt, 'clear').name('Clear');
customContainer = document.getElementById('gui');
customContainer.appendChild(gui.domElement);
document.onselectstart = function () {
return false;
};
</script>
</body>
</html>
HTML5 canvas绚彩雷达扫描光环特效源码.zip
版权申诉
97 浏览量
2022-11-03
23:37:48
上传
评论
收藏 30KB ZIP 举报
易小侠
- 粉丝: 6474
- 资源: 9万+
最新资源
- python-leetcode面试题解之第186题反转字符串中的单词II-题解.zip
- 一个基于python的web后端高性能开发框架,下载可用
- python-leetcode面试题解之第179题最大数-题解.zip
- python-leetcode面试题解之第170题两数之和III数据结构设计-题解.zip
- python-leetcode面试题解之第168题Excel表列名称-题解.zip
- python-leetcode面试题解之第167题两数之和II输入有序数组-题解.zip
- python-leetcode面试题解之第166题分数到小数-题解.zip
- python-leetcode面试题解之第165比较版本号-题解.zip
- python-leetcode面试题解之第163题缺失的区间-题解.zip
- python-leetcode面试题解之第162题寻找峰值-题解.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈