├── .babelrc ├── .gitignore ├── README-CN.md ├── README.md ├── asset ├── bz-box.html ├── curvejs.ico ├── get-path.html ├── github.png ├── main.js ├── rope.html ├── smooth.html ├── smooth2.html ├── smooth2.js └── test.png ├── dist ├── curve.js └── curve.min.js ├── example ├── curves │ ├── index.html │ ├── index.js │ └── main.js ├── expand │ ├── index.html │ ├── index.js │ └── main.js ├── loading │ ├── index.html │ ├── loading.js │ └── qq.png ├── noise-motion │ ├── index.html │ ├── index.js │ └── main.js ├── noise │ ├── index.html │ ├── index.js │ └── main.js ├── points-to │ ├── index.html │ ├── index.js │ └── main.js ├── rope │ ├── index.html │ ├── index.js │ └── main.js ├── scale-to │ ├── index.html │ ├── index.js │ └── main.js ├── simple-es5 │ └── index.html ├── simple │ ├── index.html │ ├── index.js │ └── main.js ├── siri-wave │ ├── index.html │ ├── index.js │ ├── main.js │ └── siri-wava.js ├── smooth │ ├── index.html │ ├── index.js │ └── main.js ├── sprout │ ├── index.html │ ├── index.js │ └── main.js ├── tfc │ ├── index-sc.html │ ├── index.html │ ├── index.js │ ├── main-sc.js │ └── main.js ├── water │ ├── bg.png │ ├── index.html │ ├── index.js │ └── main.js └── word │ ├── index.html │ ├── index.js │ └── main.js ├── index.html ├── package.json ├── pg ├── index.html ├── preview.html └── rd.html ├── rollup.config.js ├── src ├── color.js ├── curve.js ├── group.js ├── index.js ├── motion │ ├── circle.js │ ├── dance.js │ ├── expand.js │ ├── index.js │ ├── line.js │ ├── move.js │ ├── noise.js │ ├── path.js │ ├── rotate.js │ └── to.js ├── noise.js ├── q-curve.js ├── raf.js ├── smooth-curve.js ├── sprout-curve.js ├── stage.js ├── util.js ├── vector2.js ├── word-data.js └── word.js └── tutorial ├── rope.md └── smooth-curve.md /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ "es2015" ] 3 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | coverage 3 | -------------------------------------------------------------------------------- /README-CN.md: -------------------------------------------------------------------------------- 1 | ## 腾讯AlloyTeam正式发布Web魔幻线条 - curvejs 2 | 3 |  4 | 5 | [curvejs](https://github.com/AlloyTeam/curvejs) 中文读["克js"],是腾讯AlloyTeam打造的一款魔幻线条框架,让线条成为一名优秀的舞者,让线条们成为优秀的舞团,HTML5 Canvas就是舞台。 6 | 7 | 官网:[https://alloyteam.github.io/curvejs/](https://alloyteam.github.io/curvejs/) 8 | 9 | 你还记得window经典的屏幕保护程序《变幻线》吗? 10 | 11 |  12 | 13 | 其原理就是使用 Perlin-Noise + Particle System + Bézier Curve + Color Transition 制作而成。 14 | 15 | 使用curvejs实现类似变幻线功能只需要几行代码: 16 | 17 | ```js 18 | const { Stage, Curve, motion } = curvejs 19 | 20 | let stage = new Stage(document.getElementById('myCanvas')) 21 | 22 | stage.add(new Curve({ 23 | color: '#00FF00', 24 | data: {value: 0, step: 0.008, width: 600, height: 400}, 25 | motion: motion.noise 26 | })) 27 | 28 | function tick(){ 29 | stage.update() 30 | requestAnimationFrame(tick) 31 | } 32 | 33 | tick() 34 | ``` 35 | 36 | [【体验地址】](https://alloyteam.github.io/curvejs/pg/rd.html?type=noise) 37 | 38 | 当然,curvejs的能力不仅仅是变换线,这完全取决于你的想象力。比如: 39 | 40 | * [Loading](https://alloyteam.github.io/curvejs/example/loading/) 41 | * [Rope](https://alloyteam.github.io/curvejs/example/rope/) 42 | * [Siri-Wave](https://alloyteam.github.io/curvejs/example/siri-wave/) 43 | * [Water](https://alloyteam.github.io/curvejs/example/water/) 44 | * [Sprout](https://alloyteam.github.io/curvejs/example/sprout/) 45 | * [Scale-To](https://alloyteam.github.io/curvejs/pg/rd.html?type=scale) 46 | * [Points-To](https://alloyteam.github.io/curvejs/pg/rd.html?type=points-to) 47 | * [Rotate](https://alloyteam.github.io/curvejs/pg/rd.html?type=rotate) 48 | * [Word](https://alloyteam.github.io/curvejs/pg/rd.html?type=word) 49 | * [Perlin-Noise](https://alloyteam.github.io/curvejs/pg/rd.html?type=noise) 50 | * [Simple](https://alloyteam.github.io/curvejs/pg/rd.html?type=simple) 51 | * [Simple-ES5](https://alloyteam.github.io/curvejs/pg/rd.html?type=simple-es5) 52 | * [Lerp Color](https://alloyteam.github.io/curvejs/pg/rd.html?type=color) 53 | * [Curves](https://alloyteam.github.io/curvejs/pg/rd.html?type=curves) 54 | * [Line](https://alloyteam.github.io/curvejs/pg/rd.html?type=line) 55 | * [Close](https://alloyteam.github.io/curvejs/pg/rd.html?type=close) 56 | 57 | ## 使用指南 58 | 59 | ```bash 60 | $ npm install curvejs 61 | ``` 62 | 63 | ```javascript 64 | import curvejs from 'curvejs' 65 | ``` 66 | 67 | 也可以直接插入script到你的HTML页面: 68 | 69 | ```html 70 | 71 | ``` 72 | 73 | 开始跳舞: 74 | 75 | ```js 76 | var Stage = curvejs.Stage, 77 | Curve = curvejs.Curve, 78 | canvas = document.getElementById('myCanvas'), 79 | stage = new Stage(canvas), 80 | rd = function() { 81 | return -2 + Math.random() * 2 82 | } 83 | 84 | var curve = new Curve({ 85 | color: '#00FF00', 86 | points: [277, 327, 230, 314, 236, 326, 257, 326], 87 | data: [rd(), rd(), rd(), rd(), rd(), rd(), rd(), rd()], 88 | motion: function motion(points, data) { 89 | points.forEach(function (item, index) { 90 | points[index] += data[index] 91 | }) 92 | } 93 | }) 94 | 95 | stage.add(curve) 96 | 97 | function tick(){ 98 | stage.update() 99 | requestAnimationFrame(tick) 100 | } 101 | 102 | tick() 103 | ``` 104 | 105 | 上面的points代表了三次贝塞尔曲线的4个点。motion代表运动方式,motion可以拿到points和data。motion里函数的this指向Curve是实例curve。 106 | 107 | 108 | ## 使用内置motion 109 | 110 | ```js 111 | var curve = new Curve({ 112 | points: [277, 327, 230, 314, 236, 326, 257, 326], 113 | data: {angle: 0, r:5 ,step:Math.PI / 50 }, 114 | motion: curvejs.motion.dance 115 | }) 116 | ``` 117 | 118 | ## 基本原理 119 |  120 | 121 | 122 | * 每次创建Curve 可以传入八个数字,其实就代表上面的4个点的坐标 123 | * motion里可以拿到 points 进行自定义变幻 124 | * 幻影不需要开发者考虑,curvejs会自动生成幻影 125 | 126 | 这里需要特别强调,curvejs的幻影不是利用canvas的黑色底,然后fillRect填充半透而产生,而是Particle System。所以curvejs制作出的效果不用一定是黑色背景,而且canvas也可以是透明,这就大大增加了适用场景。 127 | 128 | ## 提交你的motion 129 | 130 | 在 [ motion 目录](https://github.com/AlloyTeam/curvejs/tree/master/src/motion), 有许多内置的motion提供给开发者使用,但是你也可以提交你的motion到这个项目,我会第一时间review并合入主干。 131 | 132 | 基本motion格式规则: 133 | 134 | ```js 135 | /** 136 | * motion description. 137 | * 138 | * @param {points} 139 | * @param {data} 140 | * data rule example: 141 | * [1, 0.2, -3, 0.7, 0.5, 0.3, -1, 1] 142 | */ 143 | export default function (points, data) { 144 | //你的motion逻辑 145 | } 146 | ``` 147 | 148 | ## curvejs相关 149 | 150 | * 官网:[https://alloyteam.github.io/curvejs/](https://alloyteam.github.io/curvejs/) 151 | * Github: [https://github.com/AlloyTeam/curvejs](https://github.com/AlloyTeam/curvejs) 152 | * 更加方便的交流关于curvejs的一切可以加入QQ的curvejs交流群(179181560) 153 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
4 |5 | Made curve a dancer in HTML5 canvas. 6 |
7 | 8 | --- 9 | ## [中文README](https://github.com/AlloyTeam/curvejs/blob/master/README-CN.md) 10 | 11 | ## Demos 12 | 13 | * [Loading](https://alloyteam.github.io/curvejs/example/loading/) 14 | * [Rope](https://alloyteam.github.io/curvejs/example/rope/) 15 | * [Siri-Wave](https://alloyteam.github.io/curvejs/example/siri-wave/) 16 | * [Water](https://alloyteam.github.io/curvejs/example/water/) 17 | * [Sprout](https://alloyteam.github.io/curvejs/example/sprout/) 18 | * [Scale-To](https://alloyteam.github.io/curvejs/pg/rd.html?type=scale) 19 | * [Points-To](https://alloyteam.github.io/curvejs/pg/rd.html?type=points-to) 20 | * [Rotate](https://alloyteam.github.io/curvejs/pg/rd.html?type=rotate) 21 | * [Word](https://alloyteam.github.io/curvejs/pg/rd.html?type=word) 22 | * [Perlin-Noise](https://alloyteam.github.io/curvejs/pg/rd.html?type=noise) 23 | * [Simple](https://alloyteam.github.io/curvejs/pg/rd.html?type=simple) 24 | * [Simple-ES5](https://alloyteam.github.io/curvejs/pg/rd.html?type=simple-es5) 25 | * [Lerp Color](https://alloyteam.github.io/curvejs/pg/rd.html?type=color) 26 | * [Curves](https://alloyteam.github.io/curvejs/pg/rd.html?type=curves) 27 | * [Line](https://alloyteam.github.io/curvejs/pg/rd.html?type=line) 28 | * [Close](https://alloyteam.github.io/curvejs/pg/rd.html?type=close) 29 | 30 | ## Usage 31 | 32 | ```bash 33 | $ npm install curvejs 34 | ``` 35 | 36 | ```javascript 37 | import curvejs from 'curvejs' 38 | ``` 39 | 40 | Or get it by the cdn and link `curve.min.js` in your HTML: 41 | 42 | ```html 43 | 44 | ``` 45 | 46 | Then start to dance: 47 | 48 | ```js 49 | var Stage = curvejs.Stage, 50 | Curve = curvejs.Curve, 51 | canvas = document.getElementById('myCanvas'), 52 | stage = new Stage(canvas), 53 | rd = function() { 54 | return -2 + Math.random() * 2 55 | } 56 | 57 | var curve = new Curve({ 58 | color: '#00FF00', 59 | points: [277, 327, 230, 314, 236, 326, 257, 326], 60 | data: [rd(), rd(), rd(), rd(), rd(), rd(), rd(), rd()], 61 | motion: function motion(points, data) { 62 | points.forEach(function (item, index) { 63 | points[index] += data[index] 64 | }) 65 | } 66 | }) 67 | 68 | stage.add(curve) 69 | 70 | function tick(){ 71 | stage.update() 72 | requestAnimationFrame(tick) 73 | } 74 | 75 | tick() 76 | ``` 77 | 78 | ## Using built-in motion 79 | 80 | ```js 81 | var curve = new Curve({ 82 | points: [277, 327, 230, 314, 236, 326, 257, 326], 83 | data: {angle: 0, r:5 ,step:Math.PI / 50 }, 84 | motion: curvejs.motion.dance 85 | }) 86 | ``` 87 | 88 | ## Submit your motion 89 | 90 | In [this motion directory](https://github.com/AlloyTeam/curvejs/tree/master/src/motion), there are already some built-in motion. you can submit your motion and then create a pull request to the project. 91 | 92 | Format and specification of your motion: 93 | 94 | ```js 95 | /** 96 | * move motion. 97 | * 98 | * @param {points} 99 | * @param {data} 100 | * data rule example: 101 | * [1, 0.2, -3, 0.7, 0.5, 0.3, -1, 1] 102 | */ 103 | export default function (points, data) { 104 | points.forEach(function (item, index) { 105 | points[index] += data[index] 106 | }) 107 | } 108 | ``` 109 | 110 | ## QQ Group 111 | 112 | The group id is 179181560. Welcome to join the group. 113 | 114 | ## License 115 | 116 | [MIT](http://opensource.org/licenses/MIT) 117 | 118 | Copyright (c) 2017-present, dntzhang & AlloyTeam 119 | -------------------------------------------------------------------------------- /asset/bz-box.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |202 | Made curve a dancer in HTML5 canvas. 203 |
204 |225 | v0.1.0 © 2017 AlloyTeam.com 226 |
227 |var xoff = 0.0;
80 | *
81 | * function draw() {
82 | * background(204);
83 | * xoff = xoff + .01;
84 | * var n = noise(xoff) * width;
85 | * line(n, 0, n, height);
86 | * }
87 | *
88 | * var noiseScale=0.02;
91 | *
92 | * function draw() {
93 | * background(0);
94 | * for (var x=0; x < width; x++) {
95 | * var noiseVal = noise((mouseX+x)*noiseScale, mouseY*noiseScale);
96 | * stroke(noiseVal*255);
97 | * line(x, mouseY+noiseVal*80, x, height);
98 | * }
99 | * }
100 | *
101 | *
198 | *
199 | * var noiseVal;
200 | * var noiseScale=0.02;
201 | *
202 | * function setup() {
203 | * createCanvas(100,100);
204 | * }
205 | *
206 | * function draw() {
207 | * background(0);
208 | * for (var y = 0; y < height; y++) {
209 | * for (var x = 0; x < width/2; x++) {
210 | * noiseDetail(2,0.2);
211 | * noiseVal = noise((mouseX+x) * noiseScale,
212 | * (mouseY+y) * noiseScale);
213 | * stroke(noiseVal*255);
214 | * point(x,y);
215 | * noiseDetail(8,0.65);
216 | * noiseVal = noise((mouseX + x + width/2) * noiseScale,
217 | * (mouseY + y) * noiseScale);
218 | * stroke(noiseVal*255);
219 | * point(x + width/2, y);
220 | * }
221 | * }
222 | * }
223 | *
224 | * var xoff = 0.0;
246 | *
247 | * function setup() {
248 | * noiseSeed(99);
249 | * stroke(0, 10);
250 | * }
251 | *
252 | * function draw() {
253 | * xoff = xoff + .01;
254 | * var n = noise(xoff) * width;
255 | * line(n, 0, n, height);
256 | * }
257 | *
258 | *