gsap实现canvas彩色流体磁场粒子动画效果代码

代码语言:html

所属分类:粒子

代码描述:gsap实现canvas彩色流体磁场粒子动画效果代码

代码标签: gsap canvas 彩色 流体 磁场 粒子 动画

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

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

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

  
  
<style>
body {
 background-color: #000;
  display: flex;
  align-items: center;
  justify-content: center; 	
	overflow: hidden;
}

canvas {
	min-height: 100vh;
}
</style>


  
  
</head>

<body>
  <canvas id="canvas"></canvas>

<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/gsap.3.10.4.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/MotionPathPlugin.min.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/EasePack.3.51.js"></script>
      <script >
gsap.config({trialWarn: false});
console.clear()
let select = s => document.querySelector(s),
		q = gsap.utils.selector(document),
		toArray = s => gsap.utils.toArray(s),
		canvas = select('#canvas'),
		ctx = canvas.getContext('2d'),
		particles = [],
		sizeObj = {width: window.innerWidth,
							 height: window.innerHeight
							},
		particleArray = [],
		resolution = Math.min(window.devicePixelRatio || 1, 2),
		colorArray = ["d6140a","ffb301","082970","fa7204","e33189","ffb501","a49e3b","3d2c74","ce1918","1c9ba2"],
		//starColorArray = ["607466","201e1f","fcfffc","b370b0","ff4000","4b244a","25171a","276fbf","183059","0e131f"],
		//starColorArray = ["ebd4cb","da9f93","b6465f","890620","2c0703","2a2b2a","1c1c1c","242325","32213a","383b53"],
		num = 2600,
		facePath = MotionPathPlugin.getRawPath("m168.81.49c-14.96,3.43-30.05,6.69-43.67,14.08-40.15,21.77-68.13,53.78-81.44,97.93-6.84,22.69-8.91,45.63-3.16,68.87,2.26,9.14.49,17.34-4.77,24.96-7.47,10.83-14.98,21.62-22.37,32.51-3.69,5.44-7.74,10.67-10.67,16.58-3.89,7.84-2.68,14.5,3.81,20.35,3.97,3.58,8.38,6.46,13.81,7.62,6.33,1.36,8.89,5.96,7.06,12.24-.49,1.7-1.24,3.32-1.85,4.98-2.52,6.84-1.07,12.37,4.48,17.14,3.64,3.13,4.35,5.24,2.75,9.63-2.14,5.88-1.27,11.01,3.13,15.57,3.54,3.67,6.23,7.87,6.97,13.05.63,4.4-.46,8.73-.73,13.09-.86,14.22,6.03,26.39,19.36,31.5,6.07,2.32,12.43,2.64,18.77,2.97,14.89.77,29.8,1.21,44.67,2.53,14.55,1.3,23.93,8.3,28.21,22.48,4.76,15.79,9.62,31.55,13.78,47.5"),
		//starPath = d="m32.21,38.12l-12.31-8.01-12.41,7.85,3.81-14.18L0,14.4l14.66-.76L20.09,0l5.25,13.71,14.65.95-11.42,9.23,3.63,14.23Z",
		starArr = []

colorArray = colorArray.map(x => Array.from(x)[0] == '#' ? x : `#${x}`);
//starColorArray = starColorArray.map(x => Array.from(x)[0] == '#' ? x : `#${x}`);
MotionPathPlugin.cacheRawPathMeasurements(facePath);

let dotRadius = gsap.utils.mapRange(0, 180, 0.05, 12)
let dotOpacity = gsap.utils.mapRange(0, 180, 0.01, 1)
let dotDuration = gsap.utils.mapRange(0, 180, 3, 13)
let dotOscDuration = gsap.utils.mapRange(0, 180, 0.35, 1)
let dotOscPosY = gsap.utils.mapRange(0, 180, -20, 20)
let dotScale = gsap.utils.mapRange(0, 180, 0.6, 0.1)

function convertToRadians(degree) {
	return degree*(Math.PI/180);
}
class Particle {
  constructor(x, y, radius, color, scale, rotation, origin, duration, oscDuration, opacity, oscPosY) {		
   	this.x = x;
   	this.y = y;
   	this.radius = radius;
   	this.color = color;
   	this.scale = scale;
   	this.rotation = rotation;
   	this.origin = origin;
   	this.duration = duration;
   	this.oscDuration = oscDuration;
.........完整代码请登录后点击上方下载按钮下载查看

网友评论0