Skip to content

Commit 1bced92

Browse files
philiptrphiliptr
authored andcommitted
Image layout for rendering tutorial
1 parent 1d54868 commit 1bced92

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

content/static/tutorials/rendering/index.html

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ <h3>Another drawing surface</h3>
4040
To draw the same shape into a new surface, first create a new PGraphics object, then draw to it by typing the name of the object and dot operator before the name of the drawing functions. This new surface is placed in the display window with the image() function.
4141
</p>
4242
<img src="imgs/35_02.png" style= "width: 100px; height: 100px; float: left;">
43+
4344
<pre>
4445
PGraphics circle = createGraphics(100, 100);
4546
circle.beginDraw();
@@ -48,6 +49,8 @@ <h3>Another drawing surface</h3>
4849
circle.endDraw();
4950
image(circle, 0, 0);
5051
</pre>
52+
<br />
53+
<br />
5154
<p>
5255
The createGraphics() function generates the new drawing surface at the size in pixels defined by the parameters. This step only happens once to initialize it. The beginDraw() function is used to start working with a custom PGraphics object and the endDraw() method is used to stop. Both are needed each time a change is made. Finally, the surface may be drawn to the display window with the image() function. All of the parameters to image() to control the position and size may be used to change the way the surface is drawn.
5356
<br />
@@ -75,7 +78,11 @@ <h3>Another drawing surface</h3>
7578
Based on this example, the most obvious differences to working with PGraphics objects are the additional lines of code and the extra step of prepending each drawing function with the name of the object. This example is simplified to demonstrate the mechanics of the technique, but it doesn’t do anything to justify it. The following example reveals a typical issue that creating a new drawing surface can fix. The goal of the program is to use a crosshair to show the position of the cursor and to draw a new circle to the screen each time the mouse is clicked. For the circles to accumulate on screen, the background() function isn’t used. This has the unintended effect of also accumulating the crosshairs as seen in this code:
7679
</p>
7780
<img src="imgs/35_04_1.png" style= "width: 100px; height: 100px; float: left;">
81+
<br />
82+
<br />
7883
<img src="imgs/35_04_2.png" style= "width: 100px; height: 100px; float: left;">
84+
<br />
85+
<br />
7986
<img src="imgs/35_04_3.png" style= "width: 100px; height: 100px; float: left;">
8087
<pre>
8188
void setup() {
@@ -99,8 +106,14 @@ <h3>Another drawing surface</h3>
99106
To allow for the circles to accumulate in the display window, but to have a different effect for the crosshairs, a new drawing surface is created to render the circles, while the crosshairs are drawn in the main display window. The surface with the circles is redrawn each frame in draw(), followed by the lines so they are on top of the circles layer.
100107
</p>
101108
<img src="imgs/35_05_1.png" style= "width: 100px; height: 100px; float: left;">
109+
<br />
110+
<br />
102111
<img src="imgs/35_05_2.png" style= "width: 100px; height: 100px; float: left;">
112+
<br />
113+
<br />
103114
<img src="imgs/35_05_3.png" style= "width: 100px; height: 100px; float: left;">
115+
<br />
116+
<br />
104117
<img src="imgs/35_05_4.png" style= "width: 100px; height: 100px; float: left;">
105118
<pre>
106119
PGraphics circles;
@@ -137,6 +150,8 @@ <h3>Another drawing surface</h3>
137150
Another good reason to use a PGraphics object is to render geometry a single time, but to display it many times within the program as a texture unit. The following example draws an ellipse at a random location on an surface that’s only 50 × 50 pixels, then follows to draw that surface in a grid by placing the image() function inside a nested loop.
138151
</p>
139152
<img src="imgs/35_06_1.png" style= "width: 600px; height: 100px">
153+
<br />
154+
<br />
140155
<img src="imgs/35_06_2.png" style= "width: 600px; height: 100px">
141156
<pre>
142157
PGraphics tile;
@@ -178,8 +193,14 @@ <h3>OpenGL surfaces</h3>
178193
Just as the the size() function defines the main renderer for a program, each createGraphics() function defines the renderer for the PGraphics object with a third, optional parameter. When the third parameter isn’t used, as in the examples seen already in this chapter, the default renderer is set. The P2D and P3D renderers are the other options. For instance, to create a new drawing surface for 3D shapes, use P3D as the third parameter to size() and createGraphics():
179194
</p>
180195
<img src="imgs/35_07_1.png" style= "width: 100px; height: 100px; float: left;">
196+
<br />
197+
<br />
181198
<img src="imgs/35_07_2.png" style= "width: 100px; height: 100px; float: left;">
199+
<br />
200+
<br />
182201
<img src="imgs/35_07_3.png" style= "width: 100px; height: 100px; float: left;">
202+
<br />
203+
<br />
183204
<img src="imgs/35_07_4.png" style= "width: 100px; height: 100px; float: left;">
184205
<pre>
185206
PGraphics cube;
@@ -229,7 +250,11 @@ <h3>Combine surfaces</h3>
229250
The final section in this chapter demonstrates techniques for combining more than one drawing surface together within the display window. This builds on the code earlier in the chapter, but extends it further. The next example builds on code 35-07 with two changes. First, another drawing surface was added and second, the background() was removed from each layer and replaced with clear(). The clear() method is similar to defining the background because it erases everything in the drawing surface, but it makes each pixel transparent instead of filling each with a color. Here, clear() is used to make it easier to combine the two drawing surfaces together because the shapes drawn into each buffer are surrounded by transparent pixels. Transparent backgrounds aren’t possible for the display window, the default PGraphics object. They are one of the primary advantages of creating a new drawing surface.
230251
</p>
231252
<img src="imgs/35_09_1.png" style= "width: 100px; height: 100px; float: left;">
253+
<br />
254+
<br />
232255
<img src="imgs/35_09_2.png" style= "width: 100px; height: 100px; float: left;">
256+
<br />
257+
<br />
233258
<img src="imgs/35_09_3.png" style= "width: 100px; height: 100px; float: left;">
234259
<pre>
235260
PGraphics cubeA;
@@ -281,8 +306,14 @@ <h3>Combine surfaces</h3>
281306
Move the cursor around in the display window to modify the transparency of each layer. The visibility of each other is set by the tint() that precedes the image() function. A quick look at the drawCubeA() and drawCubeB() functions reveal there might be a better way to write the program. Both functions are nearly identical with three differences: the name of the surface to draw to, the rotation amount for the x-axis, the rotation amount for the y-axis. These values can be passed into a function as parameters so a single function can be used in place of two. The unknown syntax is how to pass in a PGraphics object as a parameter to a function. Fortunately, it follows the same pattern as all parameters, the name of the data type is followed by a variable name. The updated program follows.
282307
</p>
283308
<img src="imgs/35_10_1.png" style= "width: 100px; height: 100px; float: left;">
309+
<br />
310+
<br />
284311
<img src="imgs/35_10_2.png" style= "width: 100px; height: 100px; float: left;">
312+
<br />
313+
<br />
285314
<img src="imgs/35_10_3.png" style= "width: 100px; height: 100px; float: left;">
315+
<br />
316+
<br />
286317
<img src="imgs/35_10_4.png" style= "width: 100px; height: 100px; float: left;">
287318
<pre>
288319
PGraphics cubeA;
@@ -325,8 +356,14 @@ <h3>Combine surfaces</h3>
325356
The next example is similar to the previous example, but it blends the two drawing surfaces together with the blendMode() function. The blend mode is defined at the end of setup() and is then applied for the duration of the program.
326357
</p>
327358
<img src="imgs/35_11_1.png" style= "width: 100px; height: 100px; float: left;">
359+
<br />
360+
<br />
328361
<img src="imgs/35_11_2.png" style= "width: 100px; height: 100px; float: left;">
362+
<br />
363+
<br />
329364
<img src="imgs/35_11_3.png" style= "width: 100px; height: 100px; float: left;">
365+
<br />
366+
<br />
330367
<img src="imgs/35_11_4.png" style= "width: 100px; height: 100px; float: left;">
331368
<pre>
332369
PGraphics cubeA;

0 commit comments

Comments
 (0)