Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
画出星星
用鼠标画画。 右键单击要下载的图像。
css
body { margin:0; background-color:#000; color:#fff; font-family:arial; } div { position:absolute; z-index:2; margin:0 0 20px 20px; }
JavaScript
var w = window.innerWidth; var h = window.innerHeight; var canvas = document.createElement('canvas'); document.body.appendChild(canvas); canvas.width = w; canvas.height = h; var ctx = canvas.getContext('2d'); ctx.fillStyle = '#000000'; ctx.fillRect(0,0,w,h); ctx.globalCompositeOperation = 'lighter'; var randomNumbers = length => Array.from(new Array(length), () => Math.random()); var TAU = Math.PI*2; var createSmokeParticle = () => { var canvas = document.createElement('canvas'); var w = 100; var h = 100; var cx = w * 0.5; var cy = h * 0.5; canvas.width = w; canvas.height = h; var ctx = canvas.getContext('2d'); canvas.ctx = ctx; var xRand = -5 + (Math.random()*10); var yRand = -5 + (Math.random()*10); var xRand2 = 10 + (Math.random()*(cx/2)); var yRand2 = 10 + (Math.random()*(cy/2)); var color = { r: Math.round(150+(Math.random()*100)), g: Math.round(50+(Math.random()*100)), b: Math.round(50+(Math.random()*100)) } ctx.fillStyle = `rgba(${color.r},${color.g},${color.b},.15)`; Array .from(new Array(200), () => randomNumbers(3)) .forEach( (p,i,arr) => { var length = arr.length; var x = Math.cos( TAU/xRand/length*i ) * p[2]*xRand2 + cx; var y = Math.sin( TAU/yRand/length*i ) * p[2]*yRand2 + cy; ctx.beginPath(); ctx.moveTo(x, y); ctx.arc(x, y, p[2]*4, 0, TAU); ctx.fill(); }); return canvas; }; var Particle = function() { var p = this; p.osc1 = { osc: 0, val: 0, freq: Math.random() }; p.osc2 = { osc: 0, val: 0, freq: Math.random() }; p.counter = 0; p.x = mousePos.x; p.y = mousePos.y; p.size = Math.random()*100; p.growth = Math.random()/20; p.life = Math.random(); p.opacity = Math.random()/5; p.speed = { x: Math.random(), y: Math.random() }; p.texture = createSmokeParticle(); p.rotationOsc = Math.round(Math.random()) ? 'osc1' : 'osc2'; }; var particles = []; var update = () => { particles.forEach((p,i) => { p.x = mousePos.x; p.y = mousePos.y; p.size = (Math.sqrt(Math.pow(p.x-p.ox,2) + Math.pow(p.y-p.oy,2))) * 5; p.counter += 0.01; p.growth = Math.sin(p.life); p.life -= 0.001; p.osc1.osc = Math.sin(p.osc1.val += p.osc1.freq); p.osc2.osc = Math.cos(p.osc2.val += p.osc2.freq); p.ox = p.x; p.oy = p.y; }); }; var render = () => { particles.forEach(p => { ctx.save(); ctx.globalAlpha = p.opacity/(p.size/50); ctx.translate(p.x, p.y); ctx.rotate(Math.random()*TAU); ctx.drawImage(p.texture, 0-(p.size/2), 0-(p.size/2), p.size, p.size); ctx.globalAlpha = 1; ctx.beginPath(); ctx.fillStyle = `rgba(${ 155+Math.round(Math.random()*100) },${ 155+Math.round(Math.random()*100) },${ 155+Math.round(Math.random()*100) },${ Math.random() })`; ctx.arc(Math.random()*p.size, Math.random()*p.size, Math.random(), 0, TAU); ctx.fill(); ctx.restore(); }); }; var loop = () => { update(); render(); window.requestAnimationFrame(loop); }; var mousePos = { x: 0, y: 0 } var drawingMode = false; var activateDraw = e => { drawingMode = true; particles = Array.from(new Array(10), () => new Particle()); draw(e); }; var disableDraw = e => { drawingMode = false; particles = []; }; var draw = e => { console.log(drawingMode) if (!drawingMode) return; console.log(e) particles.forEach(p => { //p.size = Math.max(10,e.movementX + e.movementY); }); }; canvas.addEventListener('mousedown', activateDraw); canvas.addEventListener('mousemove', e => { mousePos.x = e.layerX; mousePos.y = e.layerY; draw(e); }); canvas.addEventListener('mouseup',disableDraw); //canvas.addEventListener('touchstart', e => activateDraw); //canvas.addEventListener('touchmove', e => draw); //canvas.addEventListener('touchend', e => disableDraw); loop();
粒子
时间
文字
hover
canvas
3d
游戏
音乐
火焰
水波
轮播图
鼠标跟随
动画
css
加载动画
导航
菜单
按钮
滑块
tab
弹出层
统计图
svg
×
Close
在线代码下载提示
开通在线代码永久免费下载,需支付20jQ币
开通后,在线代码模块中所有代码可终身免费下!
您已开通在线代码永久免费下载,关闭提示框后,点下载代码可直接下载!
您已经开通过在线代码永久免费下载
对不起,您的jQ币不足!可通过发布资源 或
直接充值获取jQ币
取消
开通下载
<!doctype html> <html> <head> <meta charset="utf-8"> <title>画出星空-jq22.com</title> <script src="https://www.jq22.com/jquery/jquery-1.10.2.js"></script> <style>
</style> </head> <body>
<script>
</script>
</body> </html>
2012-2021 jQuery插件库版权所有
jquery插件
|
jq22工具库
|
网页技术
|
广告合作
|
在线反馈
|
版权声明
沪ICP备13043785号-1
浙公网安备 33041102000314号