Get started with particle-api-js CDN
Apache-2.0 licensed
Particle-API-JS is a library for interacting with the Particle Cloud Platform.
Tags:- particle
- library
- spark
- api
Stable version
Copied!
How to start using particle-api-js CDN
<!DOCTYPE html>
<html>
<head>
<title>Get started with particle-api-js CDN - cdnhub.io</title>
<script src="https://cdn.cdnhub.io/particle-api-js/10.4.2/particle.min.js"></script>
</head>
<body>
<script>
// Initialize the Particle.js library with your Particle Access Token
const particle = new p5(p => {
p.setup = () => {
p.createCanvas(400, 400);
p.particles = [];
for (let i = 0; i < 50; i++) {
p.particles.push(new p5.Particle());
}
p.colorMode(p.HSL, 360, 100, 100, 100);
};
p.draw = () => {
p.background(p.mapValue(p.mouseX, 0, p.width, 0, 360));
for (let i = 0; i < p.particles.length; i++) {
p.particles[i].follow(p.mousePosition, 1);
p.particles[i].update();
p.particles[i].show();
}
};
p.Particle = class {
constructor() {
this.pos = p.createVector(p.random(p.width), p.random(p.height));
this.vel = p.createVector();
this.acc = p.createVector();
this.size = 4;
this.lifespan = 100;
}
follow(target, maxSpeed) {
this.acc.x = p.lerp(this.acc.x, p.sub(target, this.pos).x, 0.1);
this.acc.y = p.lerp(this.acc.y, p.sub(target, this.pos).y, 0.1);
this.vel.add(this.acc);
this.vel.limit(maxSpeed);
this.update();
}
update() {
this.pos.add(this.vel);
this.lifespan -= 1;
}
show() {
const hue = p.mapValue(this.lifespan, 0, 100, 0, 360);
p.stroke(hue, 100, 100, 100);
p.noFill();
p.ellipse(this.pos.x, this.pos.y, this.size, this.size);
}
};
});
</script>
</body>
</html>
Copied!
Copied!
All versions
10.0.0
10.1.0
10.2.0
10.3.0
10.3.1
10.4.0
10.4.1
10.4.2
10.4.3
10.5.0
10.5.1
10.6.0
11.0.0
11.1.0
*** 11.1.1
5.0.2
5.1.0
5.1.1
5.2.0
5.2.1
5.2.2
5.2.3
5.2.4
5.2.5
5.2.6
5.2.7
5.3.0
5.3.0-develop.1
5.3.1
6.0.0
6.0.1
6.0.2
6.0.3
6.0.4
6.0.5
6.0.6
6.0.7
6.0.8
6.1.0
6.2.0
6.3.0
6.3.1
6.4.0
6.4.1
6.4.2
6.4.3
6.5.0
6.6.0
6.6.1
6.6.2
7.0.0
7.0.0-rc.1
7.0.1
7.1.1
7.2.0
7.2.2
7.2.3
7.3.0
7.4.0
7.4.1
8.0.0
8.0.1
8.1.0
8.2.0
8.2.1
8.3.0
8.4.0
9.0.0
9.0.1
9.0.2
9.1.0
9.1.1
9.1.2
9.2.0
9.3.0
9.4.0
9.4.1