Anonymous user
Boston Python workshop/Saturday/ColorWall: Difference between revisions
Boston Python workshop/Saturday/ColorWall (view source)
Revision as of 19:36, 8 July 2012
, 11 years agono edit summary
imported>Jesstess No edit summary |
imported>Jesstess No edit summary |
||
(7 intermediate revisions by the same user not shown) | |||
Line 8:
* Practice using functions and classes.
* Get experience with graphics programming using the Tkinter GUI toolkit.
* Practice reading other people's code.
== Project setup ==
Line 84 ⟶ 85:
=== 4. Implement a new effect called <code>RainbowTest</code> ===
==Suggested exercises==▼
It should run for 5 seconds, cycling through the colors in the rainbow, pausing for a moment at each color.
Remember to add your effect to the <code>Effect</code> list at the bottom of <code>effects.py</code>!
Test your new effect with
<pre>python run.py RainbowTest</pre>
=== 5. Play with the randomness in <code>Twinkle</code> ===
Walk through <code>Twinkle</code>. Find explanations of the <code>random.randint</code> and <code>random.uniform</code> functions in the online documentation at http://docs.python.org/library/random.html.▼
Experiment with these functions at a Python prompt:▼
<pre>▼
import random▼
random.randint(0, 1)▼
random.randint(0, 5)▼
random.uniform(-1, 1)▼
</pre>▼
Then experiment with the numbers that make up the hue and re-run the effect:▼
<pre>▼
python run.py Twinkle▼
</pre>▼
<b>Challenge</b>: make <code>Twinkle</code> twinkle with shades of red.
=== 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>.
===Checkerboard===
Find and change the colors used in the <code>Checkerboards</code> effect, and re-run the effect:
Line 107 ⟶ 145:
re-run the effect, and see what changed.
Find and change the color of the columns in the <code>Matrix</code> effect, and re-run the effect:▼
What other patterns can you create by tweaking the math for this effect?
▲<pre>
python run.py 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.▼
▲Walk through <code>Twinkle</code>. Find explanations of the <code>random.randint</code> and <code>random.uniform</code> functions in the online documentation at
=== Matrix ===
▲Find and change the color of the columns in the <code>Matrix</code> effect, and re-run the effect:
▲Experiment with these functions at a Python prompt:
<pre>
▲python run.py Matrix
▲import random
▲random.randint(0, 1)
▲random.randint(0, 5)
▲random.uniform(-1, 1)
</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.
▲Then experiment with the numbers that make up the hue and re-run the effect:
▲<pre>
▲python run.py Twinkle
▲</pre>
Write your own effects!▼
▲=== Write more of your own effects! ===
You have color, time, randomness, letters, and more at your disposal. Go nuts!
|