Skip to content

Commit f35d744

Browse files
committed
Merge branch 'master' of github.com:processing/p5.js-website
2 parents be11ca5 + c6ce835 commit f35d744

20 files changed

+1080
-495
lines changed

.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"allowAfterThis": true,
4343
"allowAfterSuper": true
4444
}
45-
]
45+
],
4646
"no-unused-vars": ["error", { "args": "none" }],
4747
"no-empty": ["error", { "allowEmptyCatch": true }],
4848
"no-console": "off"

Gruntfile.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
// use this if you want to match all subfolders:
77
// '<%= config.src %>/templates/pages/**/*.hbs'
88

9+
const yaml = require('js-yaml');
10+
const fs = require('fs').promises;
911
const pkg = require('./package.json');
1012

1113
module.exports = function(grunt) {
@@ -317,6 +319,23 @@ module.exports = function(grunt) {
317319
}
318320
});
319321

322+
grunt.registerTask('update-version', function(){
323+
const done = this.async();
324+
325+
const version = require('./src/templates/pages/reference/data.json').project.version;
326+
327+
fs.readFile('./src/data/data.yml').then((str) => {
328+
const data = yaml.safeLoad(str);
329+
data.version = version;
330+
331+
const dump = yaml.safeDump(data);
332+
333+
return fs.writeFile('./src/data/data.yml', dump);
334+
}).then(() => {
335+
done();
336+
});
337+
});
338+
320339
grunt.loadNpmTasks('grunt-exec');
321340
grunt.loadNpmTasks('grunt-assemble');
322341
grunt.loadNpmTasks('grunt-file-append');
@@ -351,6 +370,7 @@ module.exports = function(grunt) {
351370

352371
// runs three tasks in order
353372
grunt.registerTask('build', [
373+
'update-version',
354374
'exec',
355375
'clean',
356376
'requirejs',

src/assets/js/p5.dom.min.js

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

src/assets/js/p5.min.js

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

src/data/data.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
title: p5.js
1+
title: p5.js
2+
version: 0.9.0
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
* @name Ray Casting
3+
* @description Original example by Jonathan Watson.
4+
* <br><br>Detecting the position of the mouse in 3D space with ray casting.
5+
*/
6+
const objects = [];
7+
let eyeZ;
8+
9+
function setup() {
10+
createCanvas(710, 400, WEBGL);
11+
12+
eyeZ = height / 2 / tan((30 * PI) / 180); // The default distance the camera is away from the origin.
13+
14+
objects.push(new IntersectPlane(1, 0, 0, -100, 0, 0)); // Left wall
15+
objects.push(new IntersectPlane(1, 0, 0, 100, 0, 0)); // Right wall
16+
objects.push(new IntersectPlane(0, 1, 0, 0, -100, 0)); // Bottom wall
17+
objects.push(new IntersectPlane(0, 1, 0, 0, 100, 0)); // Top wall
18+
objects.push(new IntersectPlane(0, 0, 1, 0, 0, 0)); // Back wall
19+
20+
noStroke();
21+
ambientMaterial(250);
22+
}
23+
24+
function draw() {
25+
background(0);
26+
27+
// Lights
28+
pointLight(255, 255, 255, 0, 0, 400);
29+
ambientLight(244, 122, 158);
30+
31+
// Left wall
32+
push();
33+
translate(-100, 0, 200);
34+
rotateY((90 * PI) / 180);
35+
plane(400, 200);
36+
pop();
37+
38+
// Right wall
39+
push();
40+
translate(100, 0, 200);
41+
rotateY((90 * PI) / 180);
42+
plane(400, 200);
43+
pop();
44+
45+
// Bottom wall
46+
push();
47+
translate(0, 100, 200);
48+
rotateX((90 * PI) / 180);
49+
plane(200, 400);
50+
pop();
51+
52+
// Top wall
53+
push();
54+
translate(0, -100, 200);
55+
rotateX((90 * PI) / 180);
56+
plane(200, 400);
57+
pop();
58+
59+
plane(200, 200); // Back wall
60+
61+
const x = mouseX - width / 2;
62+
const y = mouseY - height / 2;
63+
64+
const Q = createVector(0, 0, eyeZ); // A point on the ray and the default position of the camera.
65+
const v = createVector(x, y, -eyeZ); // The direction vector of the ray.
66+
67+
let intersect; // The point of intersection between the ray and a plane.
68+
let closestLambda = eyeZ * 10; // The draw distance.
69+
70+
for (let x = 0; x < objects.length; x += 1) {
71+
let object = objects[x];
72+
let lambda = object.getLambda(Q, v); // The value of lambda where the ray intersects the object
73+
74+
if (lambda < closestLambda && lambda > 0) {
75+
// Find the position of the intersection of the ray and the object.
76+
intersect = p5.Vector.add(Q, p5.Vector.mult(v, lambda));
77+
closestLambda = lambda;
78+
}
79+
}
80+
81+
// Cursor
82+
push();
83+
translate(intersect);
84+
fill(237, 34, 93);
85+
sphere(10);
86+
pop();
87+
}
88+
89+
// Class for a plane that extends to infinity.
90+
class IntersectPlane {
91+
constructor(n1, n2, n3, p1, p2, p3) {
92+
this.normal = createVector(n1, n2, n3); // The normal vector of the plane
93+
this.point = createVector(p1, p2, p3); // A point on the plane
94+
this.d = this.point.dot(this.normal);
95+
}
96+
97+
getLambda(Q, v) {
98+
return (-this.d - this.normal.dot(Q)) / this.normal.dot(v);
99+
}
100+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
* @name Ray Casting
3+
* @description Original example by Jonathan Watson.
4+
* <br><br>Detecting the position of the mouse in 3D space with ray casting.
5+
*/
6+
const objects = [];
7+
let eyeZ;
8+
9+
function setup() {
10+
createCanvas(710, 400, WEBGL);
11+
12+
eyeZ = height / 2 / tan((30 * PI) / 180); // The default distance the camera is away from the origin.
13+
14+
objects.push(new IntersectPlane(1, 0, 0, -100, 0, 0)); // Left wall
15+
objects.push(new IntersectPlane(1, 0, 0, 100, 0, 0)); // Right wall
16+
objects.push(new IntersectPlane(0, 1, 0, 0, -100, 0)); // Bottom wall
17+
objects.push(new IntersectPlane(0, 1, 0, 0, 100, 0)); // Top wall
18+
objects.push(new IntersectPlane(0, 0, 1, 0, 0, 0)); // Back wall
19+
20+
noStroke();
21+
ambientMaterial(250);
22+
}
23+
24+
function draw() {
25+
background(0);
26+
27+
// Lights
28+
pointLight(255, 255, 255, 0, 0, 400);
29+
ambientLight(244, 122, 158);
30+
31+
// Left wall
32+
push();
33+
translate(-100, 0, 200);
34+
rotateY((90 * PI) / 180);
35+
plane(400, 200);
36+
pop();
37+
38+
// Right wall
39+
push();
40+
translate(100, 0, 200);
41+
rotateY((90 * PI) / 180);
42+
plane(400, 200);
43+
pop();
44+
45+
// Bottom wall
46+
push();
47+
translate(0, 100, 200);
48+
rotateX((90 * PI) / 180);
49+
plane(200, 400);
50+
pop();
51+
52+
// Top wall
53+
push();
54+
translate(0, -100, 200);
55+
rotateX((90 * PI) / 180);
56+
plane(200, 400);
57+
pop();
58+
59+
plane(200, 200); // Back wall
60+
61+
const x = mouseX - width / 2;
62+
const y = mouseY - height / 2;
63+
64+
const Q = createVector(0, 0, eyeZ); // A point on the ray and the default position of the camera.
65+
const v = createVector(x, y, -eyeZ); // The direction vector of the ray.
66+
67+
let intersect; // The point of intersection between the ray and a plane.
68+
let closestLambda = eyeZ * 10; // The draw distance.
69+
70+
for (let x = 0; x < objects.length; x += 1) {
71+
let object = objects[x];
72+
let lambda = object.getLambda(Q, v); // The value of lambda where the ray intersects the object
73+
74+
if (lambda < closestLambda && lambda > 0) {
75+
// Find the position of the intersection of the ray and the object.
76+
intersect = p5.Vector.add(Q, p5.Vector.mult(v, lambda));
77+
closestLambda = lambda;
78+
}
79+
}
80+
81+
// Cursor
82+
push();
83+
translate(intersect);
84+
fill(237, 34, 93);
85+
sphere(10);
86+
pop();
87+
}
88+
89+
// Class for a plane that extends to infinity.
90+
class IntersectPlane {
91+
constructor(n1, n2, n3, p1, p2, p3) {
92+
this.normal = createVector(n1, n2, n3); // The normal vector of the plane
93+
this.point = createVector(p1, p2, p3); // A point on the plane
94+
this.d = this.point.dot(this.normal);
95+
}
96+
97+
getLambda(Q, v) {
98+
return (-this.d - this.normal.dot(Q)) / this.normal.dot(v);
99+
}
100+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
* @name Ray Casting
3+
* @description Original example by Jonathan Watson.
4+
* <br><br>Detecting the position of the mouse in 3D space with ray casting.
5+
*/
6+
const objects = [];
7+
let eyeZ;
8+
9+
function setup() {
10+
createCanvas(710, 400, WEBGL);
11+
12+
eyeZ = height / 2 / tan((30 * PI) / 180); // The default distance the camera is away from the origin.
13+
14+
objects.push(new IntersectPlane(1, 0, 0, -100, 0, 0)); // Left wall
15+
objects.push(new IntersectPlane(1, 0, 0, 100, 0, 0)); // Right wall
16+
objects.push(new IntersectPlane(0, 1, 0, 0, -100, 0)); // Bottom wall
17+
objects.push(new IntersectPlane(0, 1, 0, 0, 100, 0)); // Top wall
18+
objects.push(new IntersectPlane(0, 0, 1, 0, 0, 0)); // Back wall
19+
20+
noStroke();
21+
ambientMaterial(250);
22+
}
23+
24+
function draw() {
25+
background(0);
26+
27+
// Lights
28+
pointLight(255, 255, 255, 0, 0, 400);
29+
ambientLight(244, 122, 158);
30+
31+
// Left wall
32+
push();
33+
translate(-100, 0, 200);
34+
rotateY((90 * PI) / 180);
35+
plane(400, 200);
36+
pop();
37+
38+
// Right wall
39+
push();
40+
translate(100, 0, 200);
41+
rotateY((90 * PI) / 180);
42+
plane(400, 200);
43+
pop();
44+
45+
// Bottom wall
46+
push();
47+
translate(0, 100, 200);
48+
rotateX((90 * PI) / 180);
49+
plane(200, 400);
50+
pop();
51+
52+
// Top wall
53+
push();
54+
translate(0, -100, 200);
55+
rotateX((90 * PI) / 180);
56+
plane(200, 400);
57+
pop();
58+
59+
plane(200, 200); // Back wall
60+
61+
const x = mouseX - width / 2;
62+
const y = mouseY - height / 2;
63+
64+
const Q = createVector(0, 0, eyeZ); // A point on the ray and the default position of the camera.
65+
const v = createVector(x, y, -eyeZ); // The direction vector of the ray.
66+
67+
let intersect; // The point of intersection between the ray and a plane.
68+
let closestLambda = eyeZ * 10; // The draw distance.
69+
70+
for (let x = 0; x < objects.length; x += 1) {
71+
let object = objects[x];
72+
let lambda = object.getLambda(Q, v); // The value of lambda where the ray intersects the object
73+
74+
if (lambda < closestLambda && lambda > 0) {
75+
// Find the position of the intersection of the ray and the object.
76+
intersect = p5.Vector.add(Q, p5.Vector.mult(v, lambda));
77+
closestLambda = lambda;
78+
}
79+
}
80+
81+
// Cursor
82+
push();
83+
translate(intersect);
84+
fill(237, 34, 93);
85+
sphere(10);
86+
pop();
87+
}
88+
89+
// Class for a plane that extends to infinity.
90+
class IntersectPlane {
91+
constructor(n1, n2, n3, p1, p2, p3) {
92+
this.normal = createVector(n1, n2, n3); // The normal vector of the plane
93+
this.point = createVector(p1, p2, p3); // A point on the plane
94+
this.d = this.point.dot(this.normal);
95+
}
96+
97+
getLambda(Q, v) {
98+
return (-this.d - this.normal.dot(Q)) / this.normal.dot(v);
99+
}
100+
}

0 commit comments

Comments
 (0)