3 ##################################
4 A Saga of Fire and Water - Codelab
5 ##################################
10 .. include:: cpp_summary.inc
12 .. include:: ../nacldev/setup_app.inc
17 Rather than start from nothing, for this codelab we've provided
18 you with a zip file containing a starting point.
20 Download the codelab::
22 curl http://nacltools.storage.googleapis.com/cds2014/cds2014_cpp.zip -O
28 Go into the codelab directory::
32 Create a new local git repo::
42 git commit -am "initial"
44 While working, you can see what you've changed by running::
49 Fire is cool, let's burn some stuff...
50 --------------------------------------
52 Indulging your inner child, lets make some virtual fire!
53 Use the following shockingly intuitive incantation::
57 You should now see a small popup window, smoldering away.
58 If you click, you can make more fire!
59 I think that's pretty cool, but then I selected
60 the institution of higher learning I attended based
61 on the integral role fire played in its campus life.
66 Remarkably, not everyone enjoys the primal illusion of fire.
68 Your task in this codelab is to transform the rising fire
69 effect you see before you into a beautiful, tranquil waterfall.
70 This will require digging into some C++ code.
72 Before you begin, you'll want to copy our fire program to a new name,
73 since you might decide later that you like fire better, I know I do::
77 git commit -am "adding water"
79 For this codelab, you'll only need to change `water.cc`.
81 The task of turning fire into water involves two key challenges:
83 * Alter the red-yellow palette of fire into a blue-green one.
84 * Reverse upward rising flame into downward falling water.
85 * Seed the waterfall from the top instead of the bottom.
87 At this point you'll want to open up `water.cc` in the editor you
90 I see a red door and I want it painted... blue
91 ==============================================
93 While PPAPI's 2D graphics API uses multi-component RGB pixels,
94 our flame effect is actually monochrome. A single intensity
95 value is used in the flame simulation. This is then converted
96 to color based on a multi-color gradient.
97 To alter the color-scheme, locate this palette, and exchange
98 the red component (first) with the blue one (third).
100 Hint: Focus your energies on the CreatePalette function.
102 You can test you changes at any time with::
109 Now there's the small matter of gravity.
110 While smoke, and well flame, rises, we want our water to go down.
112 The simulation of fire loops over each pixel,
113 bottom row to top row,
114 diffusing "fire stuff" behind the sweep.
115 You'll want to reverse this.
117 Hint: You'll need to change the y loop direction in the UpdateFlames function.
122 While you can now use the mouse to inject a trickle of water.
123 The small line of blue at the bottom isn't much of a waterfall.
124 Move it to the top to complete the effect.
126 Hint: You'll want to change the area that the UpdateCoals function mutates.
132 In addition to learning a new appreciation for fire, you've also made water...
133 And while dusting off your C/C++ image manipulation skills,
134 you've discovered how easy it is to modify, build,
135 and run a NaCl application that uses PPAPI.
137 2D graphics is fun, but now you're ready to check out the wealth of
139 `PPAPI interfaces available
140 <https://src.chromium.org/viewvc/chrome/trunk/src/ppapi/cpp/>`_.
142 While our in-browser environment is rapidly evolving
143 to become a complete development solution,
144 for the broadest range of development options, check out the
146 <https://developer.chrome.com/native-client/cpp-api>`_.
148 Send us comments and feedback on the `native-client-discuss
149 <https://groups.google.com/forum/#!forum/native-client-discuss>`_ mailing list,
150 or ask questions using Stack Overflow's `google-nativeclient
151 <https://stackoverflow.com/questions/tagged/google-nativeclient>`_ tag.
154 I hope this codelab has lit a fire in you to go out there,
155 and bring an awesome C/C++ application to NaCl or PNaCl today!
158 .. include:: ../nacldev/cleanup_app.inc