Skip to content

Commit 50194ff

Browse files
committed
Merge branch 'master' of github.com:processing/p5.js-website into showcase
2 parents cf4fef3 + 763be7f commit 50194ff

File tree

8 files changed

+341
-1
lines changed

8 files changed

+341
-1
lines changed

src/assets/css/main.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@
306306
}
307307

308308
#reference-page ul {
309-
margin-top: 0.5em;
309+
margin-top: 0;
310310
}
311311

312312
div.reference-group {
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* @name Parametric Equations
3+
* @description A parametric equation is where x and y
4+
* coordinates are both written in terms of another letter. This is
5+
* called a parameter and is usually given in the letter t or θ.
6+
* The inspiration was taken from the YouTube channel of Alexander Miller.
7+
*/
8+
9+
function setup(){
10+
createCanvas(720,400);
11+
}
12+
13+
// the parameter at which x and y depends is usually taken as either t or symbol of theta
14+
let t = 0;
15+
function draw(){
16+
background('#fff');
17+
translate(width/2,height/2);
18+
stroke('#0f0f0f');
19+
strokeWeight(1.5);
20+
//loop for adding 100 lines
21+
for(let i = 0;i<100;i++){
22+
line(x1(t+i),y1(t+i),x2(t+i)+20,y2(t+i)+20);
23+
}
24+
t+=0.15;
25+
}
26+
// function to change initial x co-ordinate of the line
27+
function x1(t){
28+
return sin(t/10)*125+sin(t/20)*125+sin(t/30)*125;
29+
}
30+
31+
// function to change initial y co-ordinate of the line
32+
function y1(t){
33+
return cos(t/10)*125+cos(t/20)*125+cos(t/30)*125;
34+
}
35+
36+
// function to change final x co-ordinate of the line
37+
function x2(t){
38+
return sin(t/15)*125+sin(t/25)*125+sin(t/35)*125;
39+
}
40+
41+
// function to change final y co-ordinate of the line
42+
function y2(t){
43+
return cos(t/15)*125+cos(t/25)*125+cos(t/35)*125;
44+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* @name Particles
3+
* @description There is a light-weight JavaScript library named
4+
* particle.js which creates a very pleasing particle system.
5+
* This is an attempt to recreate that particle system using p5.js.
6+
* Inspired by Particle.js, contributed by Sagar Arora.
7+
*/
8+
9+
10+
// this class describes the properties of a single particle.
11+
class Particle {
12+
// setting the co-ordinates, radius and the
13+
// speed of a particle in both the co-ordinates axes.
14+
constructor(){
15+
this.x = random(0,width);
16+
this.y = random(0,height);
17+
this.r = random(1,8);
18+
this.xSpeed = random(-2,2);
19+
this.ySpeed = random(-1,1.5);
20+
}
21+
22+
// creation of a particle.
23+
createParticle() {
24+
noStroke();
25+
fill('rgba(200,169,169,0.5)');
26+
circle(this.x,this.y,this.r);
27+
}
28+
29+
// setting the particle in motion.
30+
moveParticle() {
31+
if(this.x < 0 || this.x > width)
32+
this.xSpeed*=-1;
33+
if(this.y < 0 || this.y > height)
34+
this.ySpeed*=-1;
35+
this.x+=this.xSpeed;
36+
this.y+=this.ySpeed;
37+
}
38+
39+
// this function creates the connections(lines)
40+
// between particles which are less than a certain distance apart
41+
joinParticles(paraticles) {
42+
particles.forEach(element =>{
43+
let dis = dist(this.x,this.y,element.x,element.y);
44+
if(dis<85) {
45+
stroke('rgba(255,255,255,0.04)');
46+
line(this.x,this.y,element.x,element.y);
47+
}
48+
});
49+
}
50+
}
51+
52+
// an array to add multiple particles
53+
let particles = [];
54+
55+
function setup() {
56+
createCanvas(720, 400);
57+
for(let i = 0;i<width/10;i++){
58+
particles.push(new Particle());
59+
}
60+
}
61+
62+
function draw() {
63+
background('#0f0f0f');
64+
for(let i = 0;i<particles.length;i++) {
65+
particles[i].createParticle();
66+
particles[i].moveParticle();
67+
particles[i].joinParticles(particles.slice(i));
68+
}
69+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* @name Parametric Equations
3+
* @description A parametric equation is where x and y
4+
* coordinates are both written in terms of another letter. This is
5+
* called a parameter and is usually given in the letter t or θ.
6+
* The inspiration was taken from the YouTube channel of Alexander Miller.
7+
*/
8+
9+
function setup(){
10+
createCanvas(720,400);
11+
}
12+
13+
// the parameter at which x and y depends is usually taken as either t or symbol of theta
14+
let t = 0;
15+
function draw(){
16+
background('#fff');
17+
translate(width/2,height/2);
18+
stroke('#0f0f0f');
19+
strokeWeight(1.5);
20+
//loop for adding 100 lines
21+
for(let i = 0;i<100;i++){
22+
line(x1(t+i),y1(t+i),x2(t+i)+20,y2(t+i)+20);
23+
}
24+
t+=0.15;
25+
}
26+
// function to change initial x co-ordinate of the line
27+
function x1(t){
28+
return sin(t/10)*125+sin(t/20)*125+sin(t/30)*125;
29+
}
30+
31+
// function to change initial y co-ordinate of the line
32+
function y1(t){
33+
return cos(t/10)*125+cos(t/20)*125+cos(t/30)*125;
34+
}
35+
36+
// function to change final x co-ordinate of the line
37+
function x2(t){
38+
return sin(t/15)*125+sin(t/25)*125+sin(t/35)*125;
39+
}
40+
41+
// function to change final y co-ordinate of the line
42+
function y2(t){
43+
return cos(t/15)*125+cos(t/25)*125+cos(t/35)*125;
44+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* @name Particles
3+
* @description There is a light-weight JavaScript library named
4+
* particle.js which creates a very pleasing particle system.
5+
* This is an attempt to recreate that particle system using p5.js.
6+
* Inspired by Particle.js, contributed by Sagar Arora.
7+
*/
8+
9+
10+
// this class describes the properties of a single particle.
11+
class Particle {
12+
// setting the co-ordinates, radius and the
13+
// speed of a particle in both the co-ordinates axes.
14+
constructor(){
15+
this.x = random(0,width);
16+
this.y = random(0,height);
17+
this.r = random(1,8);
18+
this.xSpeed = random(-2,2);
19+
this.ySpeed = random(-1,1.5);
20+
}
21+
22+
// creation of a particle.
23+
createParticle() {
24+
noStroke();
25+
fill('rgba(200,169,169,0.5)');
26+
circle(this.x,this.y,this.r);
27+
}
28+
29+
// setting the particle in motion.
30+
moveParticle() {
31+
if(this.x < 0 || this.x > width)
32+
this.xSpeed*=-1;
33+
if(this.y < 0 || this.y > height)
34+
this.ySpeed*=-1;
35+
this.x+=this.xSpeed;
36+
this.y+=this.ySpeed;
37+
}
38+
39+
// this function creates the connections(lines)
40+
// between particles which are less than a certain distance apart
41+
joinParticles(paraticles) {
42+
particles.forEach(element =>{
43+
let dis = dist(this.x,this.y,element.x,element.y);
44+
if(dis<85) {
45+
stroke('rgba(255,255,255,0.04)');
46+
line(this.x,this.y,element.x,element.y);
47+
}
48+
});
49+
}
50+
}
51+
52+
// an array to add multiple particles
53+
let particles = [];
54+
55+
function setup() {
56+
createCanvas(720, 400);
57+
for(let i = 0;i<width/10;i++){
58+
particles.push(new Particle());
59+
}
60+
}
61+
62+
function draw() {
63+
background('#0f0f0f');
64+
for(let i = 0;i<particles.length;i++) {
65+
particles[i].createParticle();
66+
particles[i].moveParticle();
67+
particles[i].joinParticles(particles.slice(i));
68+
}
69+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* @name Parametric Equations
3+
* @description A parametric equation is where x and y
4+
* coordinates are both written in terms of another letter. This is
5+
* called a parameter and is usually given in the letter t or θ.
6+
* The inspiration was taken from the YouTube channel of Alexander Miller.
7+
*/
8+
9+
function setup(){
10+
createCanvas(720,400);
11+
}
12+
13+
// the parameter at which x and y depends is usually taken as either t or symbol of theta
14+
let t = 0;
15+
function draw(){
16+
background('#fff');
17+
translate(width/2,height/2);
18+
stroke('#0f0f0f');
19+
strokeWeight(1.5);
20+
//loop for adding 100 lines
21+
for(let i = 0;i<100;i++){
22+
line(x1(t+i),y1(t+i),x2(t+i)+20,y2(t+i)+20);
23+
}
24+
t+=0.15;
25+
}
26+
// function to change initial x co-ordinate of the line
27+
function x1(t){
28+
return sin(t/10)*125+sin(t/20)*125+sin(t/30)*125;
29+
}
30+
31+
// function to change initial y co-ordinate of the line
32+
function y1(t){
33+
return cos(t/10)*125+cos(t/20)*125+cos(t/30)*125;
34+
}
35+
36+
// function to change final x co-ordinate of the line
37+
function x2(t){
38+
return sin(t/15)*125+sin(t/25)*125+sin(t/35)*125;
39+
}
40+
41+
// function to change final y co-ordinate of the line
42+
function y2(t){
43+
return cos(t/15)*125+cos(t/25)*125+cos(t/35)*125;
44+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* @name Particles
3+
* @description There is a light-weight JavaScript library named
4+
* particle.js which creates a very pleasing particle system.
5+
* This is an attempt to recreate that particle system using p5.js.
6+
* Inspired by Particle.js, contributed by Sagar Arora.
7+
*/
8+
9+
10+
// this class describes the properties of a single particle.
11+
class Particle {
12+
// setting the co-ordinates, radius and the
13+
// speed of a particle in both the co-ordinates axes.
14+
constructor(){
15+
this.x = random(0,width);
16+
this.y = random(0,height);
17+
this.r = random(1,8);
18+
this.xSpeed = random(-2,2);
19+
this.ySpeed = random(-1,1.5);
20+
}
21+
22+
// creation of a particle.
23+
createParticle() {
24+
noStroke();
25+
fill('rgba(200,169,169,0.5)');
26+
circle(this.x,this.y,this.r);
27+
}
28+
29+
// setting the particle in motion.
30+
moveParticle() {
31+
if(this.x < 0 || this.x > width)
32+
this.xSpeed*=-1;
33+
if(this.y < 0 || this.y > height)
34+
this.ySpeed*=-1;
35+
this.x+=this.xSpeed;
36+
this.y+=this.ySpeed;
37+
}
38+
39+
// this function creates the connections(lines)
40+
// between particles which are less than a certain distance apart
41+
joinParticles(paraticles) {
42+
particles.forEach(element =>{
43+
let dis = dist(this.x,this.y,element.x,element.y);
44+
if(dis<85) {
45+
stroke('rgba(255,255,255,0.04)');
46+
line(this.x,this.y,element.x,element.y);
47+
}
48+
});
49+
}
50+
}
51+
52+
// an array to add multiple particles
53+
let particles = [];
54+
55+
function setup() {
56+
createCanvas(720, 400);
57+
for(let i = 0;i<width/10;i++){
58+
particles.push(new Particle());
59+
}
60+
}
61+
62+
function draw() {
63+
background('#0f0f0f');
64+
for(let i = 0;i<particles.length;i++) {
65+
particles[i].createParticle();
66+
particles[i].moveParticle();
67+
particles[i].joinParticles(particles.slice(i));
68+
}
69+
}

src/templates/pages/reference/index.hbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ slug: reference/
44
---
55

66
<div id="reference-page">
7+
78
{{> sidebar}}
89

910
<div class="column-span">

0 commit comments

Comments
 (0)