p5实现彩色泡泡粒子组成的文字动画效果代码

代码语言:html

所属分类:粒子

代码描述:p5实现彩色泡泡粒子组成的文字动画效果代码

代码标签: p5 彩色 泡泡 粒子 动画

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

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

<head>

    <meta charset="UTF-8">



    <style>
        body {
              margin: 0;
              overflow: hidden;
            }
    </style>

</head>

<body>


    <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/dat.gui-min.js"></script>
    <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/p5.js"></script>

    <script>
        // This script is dependant on p5.js
        var gui = new dat.GUI({name: 'GUI'});
    
        var system = {
          text: "Bfw",
          flow: 2,
          topSpeed: 500,
          lifeSpan: 1000,
          flowOffset: 0,
          gravity:{
            direction:90,
            force:0
          }
        };
    
        var f_b = gui.addFolder('Base');
        f_b.open();
        f_b.add(system, "text")
          .onChange(init)
          f_b.add(system, 'flow', 0, 100);
          f_b.add(system, 'topSpeed', 10, 1000);
          f_b.add(system, 'lifeSpan', 100, 2000);
          f_b.add(system, 'flowOffset', 0, Math.PI*2);
    
        var f_g = gui.addFolder('Gravity');
        f_g.open();
        f_g.add(system.gravity, "direction").min(0).max(360)
          .onChange(setGravity)
          f_g.add(system.gravity, "force").min(0).max(100)
            .onChange(setGravity)
    
    
    
    
        let colors = [
          '#f44336', '#e91e63', '#9c27b0', '#673ab7', '#3f51b5',
          '#2196f3', '#03a9f4', '#00bcd4', '#009688', '#4CAF50',
          '#8BC34A', '#CDDC39', '#FFEB3B', '#FFC107', '#FF9800',
          '#FF5722'
        ];
        class Particle {
          constructor(x, y, size, index) {
            this.base_size = size;
            this.index = index || 0;
            this.spawn = createVector(x, y);
            this.init();
          }
          init() {
            this.size = this.base_size * random(0.5, 1.5);
    
            this.start = millis();
            this.position = this.spawn.copy();
            this.velocity = createVector(0, 0);
            this.acceleration = createVector(0, 0);
            this.duration = system.lifeSpan * random(0.2,1.2);
            this.drag = random(0.9, 1);
            this.addForce(
              new p5.Vector.fromAngle(random(TWO_PI), random(10))
            );
            this.color = random(colors);
    
          }
          display() {
            let s = 1;
            if (millis() - this.start < this.duration * 0.1) {
              s = map(millis() - this.start, 0, this.duration * 0.1, 0, 1);
            } else if (millis() - this.start > this.duration * 0.5) {
              s = map(millis() - this.start, this.duration * 0.5, this.duration, 1, 0);
            }
            fill(this.color);
            circle(this.position.x, this.position.y, this.size * s * map(this.velocity.mag(),0,system.topSpeed,0.5,1.2).........完整代码请登录后点击上方下载按钮下载查看

网友评论0