Anonymous user
ColorWall: Difference between revisions
→2. Matrix
imported>Jesstess No edit summary |
|||
(17 intermediate revisions by 8 users not shown) | |||
Line 1:
[[File:Colorwall_matrix.png|right|300px]]
== Project ==
Program graphical effects for a ColorWall
== Goals ==
* Have fun
* Practice using functions and classes.
* Get experience with graphics programming using the Tkinter GUI toolkit.
* Practice reading other people's 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>
<li> Clone source </li>
</ul>
<pre>python run.py -a</pre>▼
== Project steps ==
Line 32 ⟶ 25:
Run the ColorWall effects again with
<pre>python run.py
The names of the effects are printed to the terminal as they are run. Pay particular attention to the first 4 effects:
Line 46 ⟶ 39:
<b>Check your understanding</b>: what saturation and value would you guess firetruck red have?
<b>Step 1 resources</b>:
<ul>
<li>
Using tuples: http://www.afterhoursprogramming.com/tutorial/Python/Tuples/
</li>
<li>
Using the <code>range</code> function to produce a sequence of numbers: http://docs.python.org/tutorial/controlflow.html#the-range-function
</li>
<li>
Using the <code>time</code> module to sleep (do nothing for a bit) inside your program: http://docs.python.org/library/time.html
</li>
</ul>
=== 2. Examine <code>Effect</code> and the interface its subclasses provide ===
Line 64 ⟶ 69:
</pre>
<code>effects.py</code> exports
<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!)
<b>Step 2 resources</b>:
<ul>
<li>
Creating and using Python functions: http://www.sthurlow.com/python/lesson05/
</li>
<li>
Creating and using Python classes: http://www.sthurlow.com/python/lesson08/
<li>
A discussion on <code>__init__</code> and <code>self</code>: http://stackoverflow.com/questions/625083/python-init-and-self-what-do-they-do
</li>
</ul>
=== 3. Examine the nested <code>for</code> loop in <code>SolidColorTest</code> ===
Line 80 ⟶ 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:
=== 4. Implement a new effect called <code>RainbowTest</code> ===
Line 93 ⟶ 107:
Test your new effect with
<pre>python run.py -e RainbowTest</pre>
=== 5. Play with the randomness in <code>Twinkle</code> ===
Line 112 ⟶ 125:
<pre>
python run.py -e Twinkle
</pre>
<b>Challenge</b>: make <code>Twinkle</code> twinkle with shades of
=== 6. Implement a new effect that involves randomness! ===
Line 124 ⟶ 136:
==Bonus exercises==
===1. Checkerboard===
Find and change the colors used in the <code>Checkerboards</code> effect, and re-run the effect:
<pre>
python run.py -e Checkerboards
</pre>
Line 148 ⟶ 160:
What other patterns can you create by tweaking the math for this effect?
===2. Matrix ===▼
▲=== Matrix ===
Find and change the color of the columns in the <code>Matrix</code> effect, and re-run the effect:
<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! ===▼
▲=== Write more of your own effects! ===
You have color, time, randomness, letters, and more at your disposal. Go nuts!
===Congratulations!===
You've read, modified, and added code to a software project that makes art out of pixels. Keep practicing!
[[File:Fireworks.png|150px]]
[[File:Balloons.png|150px]]
|