gsap实现led灯矩阵旋转动画效果代码
代码语言:html
所属分类:动画
代码描述:gsap实现led灯矩阵旋转动画效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<style>
*,
*:after,
*:before {
box-sizing: border-box;
}
body {
display: grid;
place-items: center;
min-height: 100vh;
font-family: 'Google Sans', sans-serif, system-ui;
background: black;
}
canvas {
width: 48vmin;
aspect-ratio: 1;
background: black;
}
</style>
</head>
<body>
<canvas></canvas>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/gsap.3.11.0.js"></script>
<script type="module">
gsap.defaults({ ease: "none" });
const NUMBER_OF_CELLS = 24;
const CANVAS = document.querySelector("canvas");
const CONTEXT = CANVAS.getContext("2d");
const RATIO = window.devicePixelRatio || 1;
const HUE_ONE = 10;
const HUE_TWO = 50;
CANVAS.width = CANVAS.offsetWidth * RATIO;
CANVAS.height = CANVAS.offsetHeight * RATIO;
const CELL_SIZE = CANVAS.width / NUMBER_OF_CELLS;
const CELL_BORDER = CELL_SIZE * 0.1;
const CELL_MAP = [];
const CELLS = [];
const NUMBER_OF_TRAILS = NUMBER_OF_CELLS * 0.5;
// How do you model the two square growth?
// 1. Each cell is two rects
// 2. One red, one yellow
// 3. One scales before the other so you have two scales
// 4. Yellow changes to white
// 5. They both scale down...
for (let t = 0; t < NUMBER_OF_TRAILS; t++) {
// In here generate the trails starting at x which will be the half way point?
// Given the trail number, you can work out the length of a side, etc.
const side = NUMBER_OF_CELLS - t * 2;
const total = side * 4 - 4;
const TRAIL_CELLS = [];
const START = {
x: NUMBER_OF_CELLS * 0.5,
y: t
};
const LIMIT = {
x: [t, NUMBER_OF_CELLS - t],
y: [t, NUMBER_OF_CELLS - t]
};
// console.info({ t, side, START, total })
let x = NUMBER_OF_CELLS * 0.5;
let y = t;
for (let c = 0; c < total; c++) {
TRAIL_CELLS.push({
index: c,
x,
y,
lightness: 50,
scaleOne: 0,
scaleTwo: 0,
scale: 0,
trail: t
.........完整代码请登录后点击上方下载按钮下载查看
网友评论0