Skip to content

Commit ac4c1f1

Browse files
committed
adding size() and fixing up examples for #283
1 parent c85748d commit ac4c1f1

1 file changed

Lines changed: 67 additions & 38 deletions

File tree

content/static/tutorials/p3d/index.html

Lines changed: 67 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,19 @@ <h3>3D Transformations</h3>
6464
</p>
6565

6666
<pre>
67+
float x,y,z;
68+
69+
void setup() {
70+
size(200,200,P3D);
71+
x = width/2;
72+
y = height/2;
73+
z = 0;
74+
}
75+
6776
void draw() {
6877
translate(x,y,z);
69-
rect(0,0,w,h);
78+
rectMode(CENTER);
79+
rect(0,0,100,100);
7080

7181
z++; // The rectangle moves forward as z increments.
7282
}
@@ -78,33 +88,39 @@ <h3>3D Transformations</h3>
7888

7989
<p><img src="imgs/rotateZ.png"></p>
8090
<pre>
81-
translate(x,y,z);
82-
rotateZ(angle);
91+
size(200, 200, P3D);
92+
background(100);
8393
rectMode(CENTER);
84-
rect(0,0,w,h);
94+
fill(51);
95+
stroke(255);
96+
97+
translate(100, 100, 0);
98+
rotateZ(PI/8);
99+
rect(0, 0, 100, 100);
100+
85101
</pre><br/>
86102

87103
<p>We can also rotate around the x and y axes.</p>
88104

89105
<p><img src="imgs/rotateX.png"></p>
90106
<pre>
91-
rotateX(angle);
107+
rotateX(PI/8);
92108
</pre><br/>
93109

94110
<p><img src="imgs/rotateY.png"></p>
95111
<pre>
96-
rotateY(angle);
112+
rotateY(PI/8);
97113
</pre><br/>
98114

99115
<p>As well as multiple axes at a time.</p>
100116

101117
<p><img src="imgs/rotateXYZ.png"></p>
102118
<pre>
103-
translate(x,y,z);
104-
rotateX(angle1);
105-
rotateY(angle2);
106-
rotateZ(angle3);
107-
rect(0,0,w,h);
119+
translate(100, 100, 0);
120+
rotateX(PI/8);
121+
rotateY(PI/8);
122+
rotateZ(PI/8);
123+
rect(0, 0, 100, 100);
108124
</pre><br/>
109125

110126
<h3>3D Shapes</h3>
@@ -119,6 +135,10 @@ <h3>3D Shapes</h3>
119135

120136
<p><img src="imgs/primitives3D.png"></p>
121137
<pre>
138+
size(640,360,P3D);
139+
background(0);
140+
lights();
141+
122142
pushMatrix();
123143
translate(130, height/2, 0);
124144
rotateY(1.25);
@@ -146,27 +166,33 @@ <h3>3D Shapes</h3>
146166

147167
<p><img src="imgs/pyramid3D.png"></p>
148168
<pre>
149-
translate(width/2, height/2, 0);
150-
rotateX(angle1);
151-
rotateY(angle2);
152-
scale(100);
153-
beginShape();
154-
vertex(-1, -1, -1);
155-
vertex( 1, -1, -1);
156-
vertex( 0, 0, 1);
169+
size(640, 360, P3D);
170+
background(0);
157171

158-
vertex( 1, -1, -1);
159-
vertex( 1, 1, -1);
160-
vertex( 0, 0, 1);
172+
translate(width/2, height/2, 0);
173+
stroke(255);
174+
rotateX(PI/2);
175+
rotateZ(-PI/6);
176+
noFill();
161177

162-
vertex( 1, 1, -1);
163-
vertex(-1, 1, -1);
164-
vertex( 0, 0, 1);
178+
beginShape();
179+
vertex(-100, -100, -100);
180+
vertex( 100, -100, -100);
181+
vertex( 0, 0, 100);
182+
183+
vertex( 100, -100, -100);
184+
vertex( 100, 100, -100);
185+
vertex( 0, 0, 100);
186+
187+
vertex( 100, 100, -100);
188+
vertex(-100, 100, -100);
189+
vertex( 0, 0, 100);
190+
191+
vertex(-100, 100, -100);
192+
vertex(-100, -100, -100);
193+
vertex( 0, 0, 100);
194+
endShape();
165195

166-
vertex(-1, 1, -1);
167-
vertex(-1, -1, -1);
168-
vertex( 0, 0, 1);
169-
endShape();
170196
</pre><br/>
171197

172198
Note above how it's often simpler to specify vertex locations using a standardized unit of measure (i.e. 1 pixel) and relative to a point of origin (0,0,0). The size and position of the shape is then set using matrix transformations: translate(), rotate(), and scale(). For some examples of more sophisticated custom shapes built in 3D, take a look at these examples: <a href="http://processing.org/learning/topics/rgbcube.html">RGB Cube</a>, <a href="http://processing.org/learning/topics/vertices.html">Vertices</a>, <a href="http://processing.org/learning/topics/toroid.html">Toroid</a>, <a href="http://processing.org/learning/topics/icosahedra.html">Isocahedra</a>.
@@ -183,15 +209,18 @@ <h3>Textures</h3>
183209

184210
<p><img src="imgs/texture1.png"><br/>
185211
<pre>
186-
translate(width / 2, height / 2);
187-
stroke(255);
188-
fill(127);
189-
beginShape();
190-
vertex(-100, -100, 0);
191-
vertex(100, -100, 0);
192-
vertex(100, 100, 0);
193-
vertex(-100, 100, 0);
194-
endShape(CLOSE);
212+
size(640, 360,P3D);
213+
background(0);
214+
translate(width/2, height/2);
215+
stroke(255);
216+
fill(127);
217+
beginShape();
218+
vertex(-100, -100, 0);
219+
vertex( 100, -100, 0);
220+
vertex( 100, 100, 0);
221+
vertex(-100, 100, 0);
222+
endShape(CLOSE);
223+
195224
</pre><br/>
196225
</p>
197226

0 commit comments

Comments
 (0)