ColorWall: Difference between revisions

294 bytes removed ,  8 years ago
imported>Jesstess
No edit summary
 
(13 intermediate revisions by 7 users not shown)
Line 12:
* Practice reading other people's code.
 
== ProjectDownload setupsource code ==
<ul>
 
<li>[https://openhatch.org/wiki/PyCon_intro_to_open_source#Goal_.232:_install_git Install git] if you have not already done so. </li>
=== Download and un-archive the ColorWall project skeleton code ===
<li> Clone source </li>
 
<pre> git clone git@github.com:jesstess/ColorWall.git </pre>
* http://web.mit.edu/jesstess/www/IntermediatePythonWorkshop/ColorWall.zip
</ul>
 
Un-archiving will produce a <code>ColorWall</code> folder containing several Python files, including: run.py, effects.py, and advanced_effects.py.
 
=== Test your setup ===
 
From a command prompt, navigate to the <code>ColorWall</code> directory and run
 
<pre>python run.py</pre>
 
You should see a window pop up and start cycling through colorful effects. If you don't, let a staff member know so you can debug this together.
 
== Project steps ==
Line 51 ⟶ 42:
<ul>
<li>
PythonUsing tuples: http://www.tutorialspointafterhoursprogramming.com/pythontutorial/Python/Tuples/python_tuples.htm
</li>
<li>
Line 60 ⟶ 51:
</li>
</ul>
 
 
=== 2. Examine <code>Effect</code> and the interface its subclasses provide ===
Line 79 ⟶ 69:
</pre>
 
<code>effects.py</code> exports andan <code>Effects</code> list at the bottom of the file. <code>run.py</code> goes through every effect in that list, creates a new instance of the effect, and invokes its <code>run</code> method.
 
<b>Check your understanding</b>: what would happen if you added an effect to the <code>Effects</code> list that didn't implement a <code>run</code> method? (Try it!)
Line 94 ⟶ 84:
</li>
</ul>
 
 
=== 3. Examine the nested <code>for</code> loop in <code>SolidColorTest</code> ===
Line 106 ⟶ 95:
<b>Check your understanding</b>: what would happen if you moved the <code>self.wall.draw()</code> to inside the inner <code>for</code> loop, just under <code>self.wall.set_pixel(x, y, hsv)</code> in <code>SaturationTest</code>? (Try it!)
 
<b>Tip</b>: you can run individual tests by passing their names as command line arguments (argument -e or --effects) to <code>run.py</code>. For example, if you only wanted to run <code>SaturationTest</code>, you could:
 
<pre>python run.py SaturationTest</pre>
 
<pre>python run.py -e SaturationTest</pre>
 
=== 4. Implement a new effect called <code>RainbowTest</code> ===
Line 119 ⟶ 107:
Test your new effect with
 
<pre>python run.py -e RainbowTest</pre>
 
 
=== 5. Play with the randomness in <code>Twinkle</code> ===
Line 138 ⟶ 125:
 
<pre>
python run.py -e Twinkle
</pre>
 
<b>Challenge</b>: make <code>Twinkle</code> twinkle with shades of redblue.
 
 
=== 6. Implement a new effect that involves randomness! ===
 
Remember to add your effect to the <code>Effect</code> list at the bottom of <code>effects.py</code>.
 
 
==Bonus exercises==
Line 156 ⟶ 141:
 
<pre>
python run.py -e Checkerboards
</pre>
 
Line 174 ⟶ 159:
 
What other patterns can you create by tweaking the math for this effect?
 
 
===2. Matrix ===
Line 181 ⟶ 165:
 
<pre>
python run.py -e Matrix
</pre>
 
Each column that we see on the wall corresponds to a <code>Column</code> object. Add some randomness to the color used by each column (the variable whose value you changed above) using the <code>random.random</code> function, re-run the effect, and see what happens.
 
 
===3. Write more of your own effects! ===