Skip to content

Commit 81ba273

Browse files
committed
First draft
1 parent 841a55b commit 81ba273

2 files changed

Lines changed: 16121 additions & 32 deletions

File tree

examples/curated/33_Geometries.js

Lines changed: 73 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,115 @@
11
/*
22
* @name Geometries
3-
* @arialabel Seven 3D shapes in neon gradient rotating on a white background. Shapes include cube, cylinder, ring, pyramid, sphere, plane, and ellipsoid.
4-
* @description There are seven 3D primitives in p5 now.
3+
* @description p5's
4+
* <a href="https://p5js.org/reference/#/p5/WEBGL" target="_blank">WEBGL</a>
5+
* mode includes 7 primitive shapes. Those shapes are plane, box,
6+
* cylinder, cone, torus, sphere, and ellipsoid. Additionally,
7+
* <a href="https://p5js.org/reference/#/p5/model" target="_blank">model()</a>
8+
* displays a custom geometry loaded via
9+
* <a href="https://p5js.org/reference/#/p5/loadModel" target="_blank">loadModel()</a>.
10+
* This example includes each of the primitive shapes. It also includes a model
11+
* from <a href="https://nasa3d.arc.nasa.gov/models" target="_blank">NASA's collection</a>.
512
*/
613

14+
// Variable to store NASA model
15+
let astronaut;
16+
17+
function preload() {
18+
astronaut = loadModel("assets/astronaut.obj");
19+
}
20+
721
function setup() {
822
createCanvas(710, 400, WEBGL);
923

24+
angleMode(DEGREES);
25+
26+
// Use a normal material, which uses color to illustrate
27+
// what direction each face of the geometry is pointing
28+
normalMaterial();
29+
1030
describe(
11-
'a 3d example containing seven primitive objects, a plane, box, cylinder, cone, torus, sphere, and ellipsoid.'
31+
"Eight 3D shapes: a plane, box, cylinder, cone, torus, sphere, " +
32+
"ellipsoid, and a model of an astronaut. Each shape is rotating in " +
33+
"all directions. The surface of the shapes are multicolored."
1234
);
1335
}
1436

1537
function draw() {
1638
background(250);
1739

18-
normalMaterial();
40+
// Plane
1941
push();
20-
translate(-240, -100, 0);
21-
rotateZ(frameCount * 0.01);
22-
rotateX(frameCount * 0.01);
23-
rotateY(frameCount * 0.01);
42+
translate(-250, -100, 0);
43+
rotateZ(frameCount);
44+
rotateX(frameCount);
45+
rotateY(frameCount);
2446
plane(70);
2547
pop();
2648

49+
// Box
2750
push();
28-
translate(0, -100, 0);
29-
rotateZ(frameCount * 0.01);
30-
rotateX(frameCount * 0.01);
31-
rotateY(frameCount * 0.01);
51+
translate(-75, -100, 0);
52+
rotateZ(frameCount);
53+
rotateX(frameCount);
54+
rotateY(frameCount);
3255
box(70, 70, 70);
3356
pop();
3457

58+
// Cylinder
3559
push();
36-
translate(240, -100, 0);
37-
rotateZ(frameCount * 0.01);
38-
rotateX(frameCount * 0.01);
39-
rotateY(frameCount * 0.01);
60+
translate(100, -100, 0);
61+
rotateZ(frameCount);
62+
rotateX(frameCount);
63+
rotateY(frameCount);
4064
cylinder(70, 70);
4165
pop();
4266

67+
// Cone
4368
push();
44-
translate(-250, 100, 0);
45-
rotateZ(frameCount * 0.01);
46-
rotateX(frameCount * 0.01);
47-
rotateY(frameCount * 0.01);
69+
translate(275, -100, 0);
70+
rotateZ(frameCount);
71+
rotateX(frameCount);
72+
rotateY(frameCount);
4873
cone(50, 70);
4974
pop();
5075

76+
// Torus
5177
push();
52-
translate(-75, 100, 0);
53-
rotateZ(frameCount * 0.01);
54-
rotateX(frameCount * 0.01);
55-
rotateY(frameCount * 0.01);
78+
translate(-250, 100, 0);
79+
rotateZ(frameCount);
80+
rotateX(frameCount);
81+
rotateY(frameCount);
5682
torus(50, 20);
5783
pop();
5884

85+
// Sphere
5986
push();
60-
translate(100, 100, 0);
61-
rotateZ(frameCount * 0.01);
62-
rotateX(frameCount * 0.01);
63-
rotateY(frameCount * 0.01);
87+
translate(-75, 100, 0);
88+
rotateZ(frameCount);
89+
rotateX(frameCount);
90+
rotateY(frameCount);
91+
92+
// Show black stroke to help visualize movement
93+
stroke(0);
6494
sphere(50);
6595
pop();
6696

97+
// Ellipsoid
98+
push();
99+
translate(100, 100, 0);
100+
rotateZ(frameCount);
101+
rotateX(frameCount);
102+
rotateY(frameCount);
103+
ellipsoid(20, 40, 40);
104+
pop();
105+
106+
// Astronaut
67107
push();
68108
translate(275, 100, 0);
69-
rotateZ(frameCount * 0.01);
70-
rotateX(frameCount * 0.01);
71-
rotateY(frameCount * 0.01);
72-
ellipsoid(30, 40, 40);
109+
rotateZ(180);
110+
rotateZ(frameCount);
111+
rotateX(frameCount);
112+
rotateY(frameCount);
113+
model(astronaut);
73114
pop();
74115
}

0 commit comments

Comments
 (0)