Boston Python Workshop/Saturday/ColorWall: Difference between revisions

From OpenHatch wiki
Content added Content deleted
imported>Jesstess
No edit summary
imported>Jesstess
m (Protected "Boston Python Workshop/Saturday/ColorWall" ([edit=autoconfirmed] (indefinite) [move=autoconfirmed] (indefinite)))
 
(10 intermediate revisions by 4 users not shown)
Line 1: Line 1:
Program graphical effects for a ColorWall using the Tkinter GUI toolkit. See the ColorWall in action [http://vimeo.com/16522975 here].
<div style="font-size:80%">< Back to [[Boston Python workshop]]</div>
==Setup==


See the [http://openhatch.org/wiki/Boston_Python_Workshop_3/Friday Friday setup instructions].
The ColorWall is a framework for implementing and displaying effects for a wall of pixels. During the Saturday workshop, you will write your own effects for the ColorWall.


==Goals==
<gallery caption="Example effects" widths="200px" heights="200px" perrow="3">
File:Colorwall_rainbow.png
File:Colorwall_matrix.png
File:Colorwall_twinkle.png
</gallery>


* Have fun experiment with and creating graphical effects.
You can also see the [http://vimeo.com/16522975 ColorWall in action].
* Practice using functions and classes.
=== Layout ===
* Get experience with graphics programming using the Tkinter GUI toolkit.


==Suggested exercises==
The ColorWall code consists of 3 files:


<ul>
* <code>run.py</code>: take arguments from your environment (like a specified width and height for the wall), set up the wall and effects, and run it.
<li>
* <code>wall.py</code>: the logic behind the matrix of squares that make up the wall. This file has a comment block at the top that summarize the interface that you will use when programming your own effects.
Find and change the colors used in the <code>Checkerboards</code> effect, and re-run the effect:
* <code>effects.py</code>: where effects live. This is the main file that you'll be editing during the workshop.


<pre>
=== Resources ===
python run.py Checkerboards
</pre>


Then change the line
* [[Boston_Python_workshop/Friday_handout#Setting_up_the_ColorWall|Friday setup instructions for the ColorWall]]

* [https://github.com/jesstess/ColorWall ColorWall code on GitHub]
<pre>
* The ColorWall uses the HSV color space. Wikipedia has a [http://en.wikipedia.org/wiki/HSL_and_HSV complicated explanation] for what that means, but what it boils down to for the purposes of our project is this: each pixel gets 3 values: hue (e.g. am I red, green, or blue), saturation (am I pale or intense), and value (am I bright or dark). <code>effects.py</code> has example effects that exercise hue, saturation, and value independently.
if (x + y + i) % 2 == 0:
</pre>

to

<pre>
if (x + y + i) % 3 == 0:
</pre>

re-run the effect, and see what changed.
</li>
<li>
Find and change the color of the columns in the <code>Matrix</code> effect, and re-run the 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.
</li>
<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

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>
</li>
<li>
Write your own effects!
</li>
</ul>

==Some Useful Links==

If you choose to use HSV colors you define instead of the dictionary, you may find some of the following useful:
* [http://www.yafla.com/yaflaColor/ColorRGBHSL.aspx A graphical HSV color picking website]
* [http://en.wikipedia.org/wiki/HSL_and_HSV HSV on Wikipedia]
* [http://docs.python.org/library/random.html Python random library]
* [http://docs.python.org/library/time.html Python time library]

[[Boston Python workshop 2/Saturday projects|&laquo; Back to the Saturday project page]]

Latest revision as of 13:15, 24 September 2011

Program graphical effects for a ColorWall using the Tkinter GUI toolkit. See the ColorWall in action here.

Setup

See the Friday setup instructions.

Goals

  • Have fun experiment with and creating graphical effects.
  • Practice using functions and classes.
  • Get experience with graphics programming using the Tkinter GUI toolkit.

Suggested exercises

  • Find and change the colors used in the Checkerboards effect, and re-run the effect:
    python run.py Checkerboards
    

    Then change the line

        if (x + y + i) % 2 == 0:
    

    to

        if (x + y + i) % 3 == 0:
    

    re-run the effect, and see what changed.

  • Find and change the color of the columns in the Matrix effect, and re-run the effect:
    python run.py Matrix
    

    Each column that we see on the wall corresponds to a Column object. Add some randomness to the color used by each column (the variable whose value you changed above) using the random.random function, re-run the effect, and see what happens.

  • Walk through Twinkle. Find explanations of the random.randint and random.uniform functions in the online documentation at http://docs.python.org/library/random.html. Experiment with these functions at a Python prompt:
    import random
    random.randint(0, 1)
    random.randint(0, 5)
    random.uniform(-1, 1)
    

    Then experiment with the numbers that make up the hue and re-run the effect:

    python run.py Twinkle
    
  • Write your own effects!

Some Useful Links

If you choose to use HSV colors you define instead of the dictionary, you may find some of the following useful:

« Back to the Saturday project page