Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 28 additions & 14 deletions effects.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
import ascii8x8

# A dictionary of hsv values for some common colors.
colors = {"black":(0, 0, 0), "white":(0, 0, 1), "gray":(0, 0, 0.5),
"red":(0, 1, 1), "blue":(0.66, 1, 1), "yellow":(0.16, 1, 1),
"purple":(0.85, 1, 0.5), "green":(0.33, 1, 0.5),
"orange":(0.083, 1, 1), "pink":(0.9, 1, 1), "lime":(0.33, 1, 1),
"baby blue":(0.66, 0.5, 1), "cyan":(0.5, 1, 1),
"brown":(0.07, 0.86, 0.54), "beige":(0.083, 0.32, 1),
"indigo":(0.75, 1, 0.5), "dark gray":(0, 0, 0.15),
"light gray":(0, 0, 0.75), "maroon":(0, 1, 0.5),
"navy":(0.66, 1, 0.25)}
colors = {"black": (0, 0, 0), "white": (0, 0, 1), "gray": (0, 0, 0.5),
"red": (0, 1, 1), "blue": (0.66, 1, 1), "yellow": (0.16, 1, 1),
"purple": (0.85, 1, 0.5), "green": (0.33, 1, 0.5),
"orange": (0.083, 1, 1), "pink": (0.9, 1, 1), "lime": (0.33, 1, 1),
"baby blue": (0.66, 0.5, 1), "cyan": (0.5, 1, 1),
"brown": (0.07, 0.86, 0.54), "beige": (0.083, 0.32, 1),
"indigo": (0.75, 1, 0.5), "dark gray": (0, 0, 0.15),
"light gray": (0, 0, 0.75), "maroon": (0, 1, 0.5),
"navy": (0.66, 1, 0.25)}


class Effect(object):
def __init__(self, wall):
Expand All @@ -21,6 +22,7 @@ def __init__(self, wall):
def run(self):
pass


class SolidColorTest(Effect):
def run(self):
hue = 1
Expand All @@ -35,6 +37,7 @@ def run(self):
self.wall.draw()
time.sleep(2)


class HueTest(Effect):
def run(self):
hue = random.random()
Expand All @@ -48,6 +51,7 @@ def run(self):
hue = (hue + .01) % 1
time.sleep(.05)


class SaturationTest(Effect):
def run(self):
hue = random.random()
Expand All @@ -62,6 +66,7 @@ def run(self):
saturation = (saturation + .05) % 1
time.sleep(.05)


class ValueTest(Effect):
def run(self):
hue = random.random()
Expand All @@ -76,15 +81,17 @@ def run(self):
value = (value + .05) % 1
time.sleep(.05)


class DictionaryTest(Effect):
def run(self):
for color in colors.keys():
for color in list(colors.keys()):
for x in range(self.wall.width):
for y in range(self.wall.height):
self.wall.set_pixel(x, y, colors[color])
self.wall.draw()
time.sleep(0.5)


class Checkerboards(Effect):
def run(self):
for i in range(10):
Expand All @@ -97,6 +104,7 @@ def run(self):
self.wall.draw()
time.sleep(0.5)


class Columns(Effect):
def run(self):
hue = random.random()
Expand All @@ -111,6 +119,7 @@ def run(self):
self.wall.clear()
hue = (hue + .05) % 1


class Rainbow(Effect):
def run(self):
hue = random.random()
Expand Down Expand Up @@ -168,6 +177,7 @@ def run(self):
self.wall.draw()
time.sleep(.01)


class KnightMoves(Effect):
def __init__(self, wall):
self.wall = wall
Expand Down Expand Up @@ -227,21 +237,22 @@ def getMoves(self):
if (self.knight_x + 2) < self.wall.width and (self.knight_y - 1) >= 0:
moves.append((self.knight_x + 2, self.knight_y - 1))
if (self.knight_x + 2) < self.wall.width and \
(self.knight_y + 1) < self.wall.height:
(self.knight_y + 1) < self.wall.height:
moves.append((self.knight_x + 2, self.knight_y + 1))
if (self.knight_x + 1) < self.wall.width and \
(self.knight_y + 2) < self.wall.height:
(self.knight_y + 2) < self.wall.height:
moves.append((self.knight_x + 1, self.knight_y + 2))
return moves


class Matrix(Effect):
class Column(object):
def __init__(self, wall):
self.wall = wall
self.cache = []
# Tail must be at least 1 pixel long
self.tail = max(1, random.randint(
self.wall.height / 2, self.wall.height * 2))
self.wall.height / 2, self.wall.height * 2))
# Get a position somewhere above the wall (so it can trickle down
# onto the wall)
self.pos = (random.randint(0, self.wall.width - 1),
Expand Down Expand Up @@ -317,6 +328,7 @@ def draw(self, cols):
timeout -= 1
drawing = 0


class LetterTest(Effect):
"""
Cycle through the letters of the alphabet.
Expand All @@ -338,7 +350,7 @@ def run(self):

# Display upper and lower case letters. The break between 90 and 97 is
# for non-letter keyboard characters.
for ord in range(65, 91) + range(97, 123):
for ord in list(range(65, 91)) + list(range(97, 123)):
self.wall.clear()

# Set every pixel to the background color, since ascii8x8 will only
Expand All @@ -353,6 +365,7 @@ def run(self):
self.wall.draw()
time.sleep(.1)


class Bouncer(Effect):
class Ball(object):
def __init__(self, wall):
Expand Down Expand Up @@ -410,6 +423,7 @@ def run(self):
self.wall.draw()
time.sleep(.1)


class Message(Effect):
message = [
' ',
Expand Down
8 changes: 4 additions & 4 deletions run.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

import argparse, sys
import argparse

from wall import Wall
import effects
Expand All @@ -24,13 +24,13 @@
wall = Wall(args.width, args.height)

if args.effects:
effects_to_run = [getattr(effects, a) for a in args.effects \
if hasattr(effects, a)]
effects_to_run = [getattr(effects, a) for a in args.effects
if hasattr(effects, a)]

else:
effects_to_run = effects.Effects

for effect in effects_to_run:
new_effect = effect(wall)
print new_effect.__class__.__name__
print(new_effect.__class__.__name__)
new_effect.run()
8 changes: 6 additions & 2 deletions wall.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/usr/bin/env python

from Tkinter import ALL, Canvas, Frame, SUNKEN, Tk
try:
from tkinter import ALL, Canvas, Frame, SUNKEN, Tk # for Python 3
except ImportError:
from Tkinter import ALL, Canvas, Frame, SUNKEN, Tk # for Python 2
import colorsys

"""
Expand All @@ -26,6 +29,7 @@
re-draw the pixels.
"""


class Wall(object):
MIN_RED = MIN_GREEN = MIN_BLUE = 0x0
MAX_RED = MAX_GREEN = MAX_BLUE = 0xFF
Expand Down Expand Up @@ -62,7 +66,7 @@ def draw(self):
self.canvas.delete(ALL)
for x in range(len(self.pixels)):
x_0 = (x % self.width) * self.PIXEL_WIDTH
y_0 = (x / self.width) * self.PIXEL_WIDTH
y_0 = (x // self.width) * self.PIXEL_WIDTH
x_1 = x_0 + self.PIXEL_WIDTH
y_1 = y_0 + self.PIXEL_WIDTH
hue = "#%02x%02x%02x" % self._get_rgb(self.pixels[x])
Expand Down