Vector2与perlin打造粒子流动效果

代码语言:html

所属分类:粒子

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

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

    <script src="http://repo.bfw.wiki/bfwrepo/js/Vector2.min.js"></script>
    <script src="http://repo.bfw.wiki/bfwrepo/js/perlin.js"></script>
    <style>
        body {
            background-color: black;
        }
        .canvas {
            position: absolute;
            top: 0;
            left: 0;
            width: 100vw;
            height: 100vh;
        }
        .codepen-link {
            position: absolute;
            bottom: 30px;
            right: 30px;
            height: 40px;
            width: 40px;
            z-index: 10;
            border-radius: 50%;
            box-sizing: border-box;
            background-position: center center;
            background-size: cover;
            opacity: 0.5;
            -webkit-transition: all 0.25s;
            transition: all 0.25s;
        }
        .codepen-link:hover {
            opacity: 0.8;
            box-shadow: 0 0 6px #efefef;
        }
        .instructions {
            position: absolute;
            bottom: 30px;
            left: 30px;
            color: #cfcfff;
            font-family: "Poppins", sans-serif;
            font-size: 1em;
            line-height: 1.25em;
            pointer-events: none;
        }
    </style>
</head>
<body>
    <canvas class="mycanvas" width="745" height="706"></canvas>

    <div class="instructions">
        <p>
            Hover to repel particles
        </p>
        <p>
            Mouse x / y position changes noise frequency
        </p>
        <p>
            Mouse down to attract particles
        </p>
        <p>
            Double-click to add an attractor
        </p>
        <p>
            Double-click attractors to remove
        </p>
    </div>



    <script>
        /* jshint esversion: 6 */

        ((main) => {

            main(this, document, {
                v2: Vector2,
                noise: noise
            });

        })((window, document, lib, undefined) => {

            'use strict';

            const PI = Math.PI,
            TAU = PI * 2,
            ABS = Math.abs,
            RAND = Math.random,
            ROUND = Math.round,
            SIN = Math.sin,
            COS = Math.cos;

            class Config {
                constructor(opts) {
                    for (let opt in opts) {
                        this.set(opt, opts[opt]);.........完整代码请登录后点击上方下载按钮下载查看

网友评论0