1 Star 0 Fork 1

Mark/Ejecta

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
index.js 1.98 KB
一键复制 编辑 原始数据 按行查看 历史
Dominic Szablewski 提交于 2015-12-18 23:28 +08:00 . Use retina res in example .js
/*
INSTRUCTIONS:
This file must be copied into ./App in order to work
*/
var w = window.innerWidth;
var h = window.innerHeight;
var scale = window.devicePixelRatio;
var w2 = w/2;
var h2 = h/2;
var canvas = document.getElementById('canvas');
canvas.width = w * scale;
canvas.height = h * scale;
canvas.style.width = w;
canvas.style.height = h;
var ctx = canvas.getContext('2d');
ctx.scale(scale, scale);
var curves = [];
for( var i = 0; i < 200; i++ ) {
curves.push({
current: Math.random() * 1000,
inc: Math.random() * 0.005 + 0.002,
color: '#'+(Math.random()*0xFFFFFF<<0).toString(16) // Random color
});
}
var p = [0,0, 0,0, 0,0, 0,0];
var animate = function() {
// Clear the screen - note that .globalAlpha is still honored,
// so this will only "darken" the sceen a bit
ctx.globalCompositeOperation = 'source-over';
ctx.fillRect(0,0,w,h);
// Use the additive blend mode to draw the bezier curves
ctx.globalCompositeOperation = 'lighter';
// Calculate curve positions and draw
for( var i = 0; i < maxCurves; i++ ) {
var curve = curves[i];
curve.current += curve.inc;
for( var j = 0; j < p.length; j+=2 ) {
var a = Math.sin( curve.current * (j+3) * 373 * 0.0001 );
var b = Math.sin( curve.current * (j+5) * 927 * 0.0002 );
var c = Math.sin( curve.current * (j+5) * 573 * 0.0001 );
p[j] = (a * a * b + c * a + b) * w * c + w2;
p[j+1] = (a * b * b + c - a * b *c) * h2 + h2;
}
ctx.beginPath();
ctx.moveTo( p[0], p[1] );
ctx.bezierCurveTo( p[2], p[3], p[4], p[5], p[6], p[7] );
ctx.strokeStyle = curve.color;
ctx.stroke();
}
};
// The vertical touch position controls the number of curves;
// horizontal controls the line width
var maxCurves = 70;
document.addEventListener( 'touchmove', function( ev ) {
ctx.lineWidth = (ev.touches[0].pageX/w) * 20;
maxCurves = Math.floor((ev.touches[0].pageY/h) * curves.length);
}, false );
ctx.fillStyle = '#000000';
ctx.fillRect( 0, 0, w, h );
ctx.globalAlpha = 0.05;
ctx.lineWidth = 2;
setInterval( animate, 16 );
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Objective-C
1
https://gitee.com/liu-jing-jing/Ejecta.git
git@gitee.com:liu-jing-jing/Ejecta.git
liu-jing-jing
Ejecta
Ejecta
master

搜索帮助