Skip to content

Commit 5eb545b

Browse files
set shape particles
1 parent 039b830 commit 5eb545b

File tree

3 files changed

+32
-10
lines changed

3 files changed

+32
-10
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Load particles.js and configure the particles:
2020
particlesJS('particles-js', {
2121
particles: {
2222
color_hex: '#fff',
23+
// 'circle', 'edge' or 'rectangle'
24+
shape: 'circle',
2325
opacity: 1,
2426
size: 2.5,
2527
size_random: true,

particles.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ function launchParticlesJS(tag_id, params){
1616
},
1717
particles: {
1818
color_hex: '#fff',
19+
shape: 'circle',
1920
opacity: 1,
2021
size: 2.5,
2122
size_random: true,
@@ -34,6 +35,7 @@ function launchParticlesJS(tag_id, params){
3435
if(params){
3536
if(params.particles){
3637
if(params.particles.color_hex) pJS.particles.color_hex = params.particles.color_hex;
38+
if(params.particles.shape) pJS.particles.shape = params.particles.shape;
3739
if(params.particles.opacity) pJS.particles.opacity = params.particles.opacity;
3840
if(params.particles.size) pJS.particles.size = params.particles.size;
3941
if(params.particles.size_random == false) pJS.particles.size_random = params.particles.size_random;
@@ -128,7 +130,24 @@ function launchParticlesJS(tag_id, params){
128130
this.draw = function(){
129131
pJS.canvas.ctx.fillStyle = 'rgba('+this.color.r+','+this.color.g+','+this.color.b+','+this.opacity+')';
130132
pJS.canvas.ctx.beginPath();
131-
pJS.canvas.ctx.arc(this.x, this.y, this.radius, 0, Math.PI * 2, false);
133+
134+
switch(pJS.particles.shape){
135+
case 'circle':
136+
pJS.canvas.ctx.arc(this.x, this.y, this.radius, 0, Math.PI * 2, false);
137+
break;
138+
139+
case 'edge':
140+
pJS.canvas.ctx.rect(this.x, this.y, this.radius*2, this.radius*2);
141+
break;
142+
143+
case 'triangle':
144+
pJS.canvas.ctx.moveTo(this.x,this.y);
145+
pJS.canvas.ctx.lineTo(this.x+this.radius,this.y+this.radius*2);
146+
pJS.canvas.ctx.lineTo(this.x-this.radius,this.y+this.radius*2);
147+
pJS.canvas.ctx.closePath();
148+
break;
149+
}
150+
132151
pJS.canvas.ctx.fill();
133152
}
134153

particles.min.js

Lines changed: 10 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)