Hardware Reference
In-Depth Information
irst this might sound like it would produce the same results - and it does for a limited
amount of drawing - but the results of the two can look very diferent. his is because if you
draw on a small segment and your drawing extends outside the bounds of the segment, you
will not see any lines. However, if you are rotating the drawing points, then drawing outside
the segment will be seen in the other segments. his fundamentally changes how things look
with regard to relections. Rotation of a point is easy; you just have to apply the following
formula to the X and Y coordinates of the point to get the new point X' and Y':
X' = X Cos θ - Y Sin θ
Y' = X Sin θ + Y Cos θ
θ is the angle of rotation about the origin. So to get the origin in the centre of the screen, you
have to subtract half the width from the reading values. You can use a loop to repeatedly do
this for as much repeating as you want. I will leave that with you to do as an exercise. What I
will give you here is an example of the second, more interesting, relection kaleidoscope-style
of symmetry. his plots the picture into an of-screen bufer, and then makes up the screen
by repeating this bufer in a relected and inverted manner to give a four-fold symmetrical
pattern. his new variant is shown in Listing 15-5.
Listing 15-5 Kilido-Sketch
#!/usr/bin/env python
“””
Rotary Encoder Kilido-sketch
Four fold symmetry
encoder 1 wired to inputs 6 & 7
encoder 2 wired to inputs 4 & 5
Tilt switch wired to input 3
“””
import colorsys
from smbus import SMBus
import os, sys, pygame
from pygame.locals import *
import piface.pfio as pfio # piface library
import subprocess
pfio.init() # initialise piface
pygame.init() # initialise pygame
pygame.event.set_allowed(None)
pygame.event.set_allowed([pygame.KEYDOWN, pygame.QUIT, ;
pygame.MOUSEBUTTONDOWN])
Search WWH ::




Custom Search