Anonymous user
Boston Python workshop/Saturday/ColorWall: Difference between revisions
Boston Python workshop/Saturday/ColorWall (view source)
Revision as of 15:11, 5 July 2012
, 11 years agono edit summary
imported>Jesstess No edit summary |
imported>Jesstess No edit summary |
||
Line 94:
<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.
Line 129 ⟶ 151:
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.
</li>
▲Walk through <code>Twinkle</code>. Find explanations of the <code>random.randint</code> and <code>random.uniform</code> functions in the online documentation at
▲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>
Write your own effects!
</li>
|