【HTML + CSS + JS—— “粒子喷泉”—

height: 100%;

overflow: hidden;

}

index.js

var numpts = 300;

var speed = 0.03;

var spin = 3;

var space = 10;

var ctx, blurf=0.3,

blur=false,

gravity=9.8,

color=320,

ttl=10,

bounce=0.7,

pt, pt1, pt2,

z = 200,

dist = 1000, points = [], mouse=false, ry=0;

var xvel = 25, yvel = 50, zvel = 25, lastx, lasty;

var last = new Date().getTime();

var plane = new Quad(0,25,0,40,40);

function Quad(cx, cy, cz, l, w) {

this.cx = cx || 0;

this.cy = cy || 0;

this.cz = cz || 0;

this.length = l || 1;

this.width = w || 1;

this.color = “#fff”;

this.verts = [

new Point(cx+w/2, cy, cz+l/2),

new Point(cx-w/2, cy, cz+l/2),

new Point(cx-w/2, cy, cz-l/2),

new Point(cx+w/2, cy, cz-l/2),

];

}

Quad.prototype.draw = function() {

for(var i = 0; i < plane.verts.length-1;i++) {

pt1 = process( plane.verts[i] );

pt2 = process( plane.verts[i+1] );

drawLine(pt1.x, pt1.y, pt2.x, pt2.y, this.color);

}

pt1 = process( plane.verts[0] );

drawLine(pt2.x, pt2.y, pt1.x, pt1.y, this.color);

};

function Point(x,y,z,scale, color, alpha, vel) {

this.x = x || 1;

this.y = y || 0;

this.z = z || 1.001;

this.scale = scale || 1;

this.alpha = alpha || 1.0;

this.color = color || “#fff”;

this.vel = vel || [0,0,0];

this.ttl = Math.random()*ttl + 1;

this.sttl = this.ttl;

}

function render() {

if(!blur) {

ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);

} else {

ctx.fillStyle = ‘rgba(0,0,0,’+blurf+‘)’;

ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);

}

plane.draw();

for(var i = 0; i < points.length;i++) {

pt = process(points[i]);

drawCircle(pt.x, pt.y, points[i].scale*pt.scale, 1, points[i].color);

}

animate();

requestAnimFrame(render);

}

function animate() {

var time = new Date().getTime();

var t = (time - last) / 1000;

t = t > 0.3 ? 0.3 : t; // HACK - clamp time so it doesnt go haywire when last grows large cus render stops

for(var i = 0; i < points.length;i++) {

points[i].ttl -= t;

points[i].x += points[i].vel[0] * t;

points[i].y += points[i].vel[1] * t;

points[i].z += points[i].vel[2] * t;

points[i].vel[1] += gravity;

points[i].scale = (points[i].ttl/points[i].sttl);

points[i].color = “hsla(”+(color+(points[i].ttl/points[i].sttl)*30)+“,100%, “+(points[i].ttl/points[i].sttl)*100+”%,1.0)”;

if(points[i].ttl < 0) {

points.splice(i,1);

points.push( createpoint() );

}

if((points[i].y+points[i].scale/2) >= plane.cy) {

points[i].vel[1] = -points[i].vel[1] * bounce + gravity*1.25; // + grav, keeps them from bouncing forever

points[i].y = plane.cy-(points[i].scale/2);

}

}

last = time;

}

function drawCircle(x, y, r, w, color) {

ctx.fillStyle = color;

ctx.lineWidth = w;

ctx.beginPath();

ctx.arc(x, y, (r>0?r:0), 0, Math.PI*2);

ctx.fill();

}

function drawLine(sx,sy, x, y, color) {

ctx.strokeStyle = color;

ctx.beginPath();

ctx.moveTo(sx,sy);

ctx.lineTo(x, y);

ctx.stroke();

}

function process(pt) {

var p = rotate(pt);

return project§;

}

function rotate(pt) {

var p = sCopy(pt);

p.x = (pt.x)*Math.cos(ry)-(pt.z)*Math.sin(ry);

p.z = (pt.x)*Math.sin(ry)+(pt.z)*Math.cos(ry) + z;

p.scale = pt.scale;

return p;

}

function project(pt) {

var p = sCopy(pt);

p.x = ctx.canvas.width/2 + (pt.x * (dist/pt.z));

p.y = ctx.canvas.height/2 + (pt.y * (dist/pt.z));

p.scale = (dist/pt.z);

return p;

}

function init() {

points = [];

for(var i = 0; i < numpts;i++){

points.push( createpoint() );

points[i].ttl = 0;

}

}

function createpoint() {

return new Point(

Math.random()*2-1,

Math.random()*2-1,

Math.random()*2-1,

undefined, //Math.random()+0.1,

“#f0f”,

.5,

[Math.random()xvel-xvel/2, Math.random()-yvel, Math.random()*zvel-zvel/2]

);

}

function sCopy(obj) {

var o = {};

for(var a in obj) {

if(obj.hasOwnProperty(a)){ o[a] = obj[a]; }

}

return o;

}

window.addEventListener(‘load’, onLoad, false);

function onLoad(evt) {

var canvas = document.querySelector(‘canvas’);

ctx = canvas.getContext(“2d”);

window.onresize = function () {

ctx.canvas.height = document.body.offsetHeight;

最后

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长,自己不成体系的自学效果低效漫长且无助。

因此收集整理了一份《2024年Web前端开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。

img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点!不论你是刚入门Android开发的新手,还是希望在技术上不断提升的资深开发者,这些资料都将为你打开新的学习之门!

如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
mg-dSR5cDin-1715746052440)]

[外链图片转存中…(img-lsOcTlwE-1715746052440)]

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点!不论你是刚入门Android开发的新手,还是希望在技术上不断提升的资深开发者,这些资料都将为你打开新的学习之门!

如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值